Skip to content

Commit bd4d9de

Browse files
committed
Initial commit
0 parents  commit bd4d9de

File tree

17 files changed

+3103
-0
lines changed

17 files changed

+3103
-0
lines changed

.github/scripts/code_coverage.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/php
2+
<?php
3+
4+
defined('ROOT_PATH') or
5+
define('ROOT_PATH', realpath(__DIR__ . '/../..'));
6+
7+
echo implode(' ', getData($argv[1] ?? null));
8+
9+
/**
10+
* Return coverage data [highLowerBound, actualCoverage]
11+
*
12+
* @author Dzianis Kotau <[email protected]>
13+
* @return array|false False if XML could not be parsed
14+
*/
15+
function getData(string $attribute = null): array|false
16+
{
17+
if (($file = findConfig()) === false) {
18+
return false;
19+
}
20+
21+
$xml = simplexml_load_file($file);
22+
if ($xml === false) {
23+
return false;
24+
}
25+
26+
$report = $xml->coverage->report;
27+
if ($attribute === 'highLowerBound') {
28+
return [(int)$report->html['highLowerBound']];
29+
}
30+
31+
$actualCoverage = findActualCoverage(realpath(ROOT_PATH . '/' . $report->text['outputFile']));
32+
if ($attribute === 'actualCoverage') {
33+
return [$actualCoverage];
34+
}
35+
36+
return [(int)$report->html['highLowerBound'], $actualCoverage];
37+
}
38+
39+
/**
40+
* Finds phpunit config file
41+
*
42+
* @author Dzianis Kotau <[email protected]>
43+
* @return string|false False if file does not exist. Otherwise, path to the file
44+
*/
45+
function findConfig(): string|false
46+
{
47+
if (file_exists(ROOT_PATH . '/phpunit.xml')) {
48+
return ROOT_PATH . '/phpunit.xml';
49+
}
50+
51+
if (file_exists(ROOT_PATH . '/phpunit.xml.dist')) {
52+
return ROOT_PATH . '/phpunit.xml.dist';
53+
}
54+
55+
return false;
56+
}
57+
58+
/**
59+
* Get actual code coverage in percentage
60+
*
61+
* @author Dzianis Kotau <[email protected]>
62+
* @param string $filePath
63+
* @return int
64+
*/
65+
function findActualCoverage(string $filePath): int
66+
{
67+
$lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
68+
$lines = array_filter($lines, fn($line) => str_starts_with(trim($line), 'Lines'));
69+
$lines = array_values(array_map('trim', $lines));
70+
preg_match('/Lines:\s+(.*?)%/', $lines[0], $matches);
71+
72+
return (int)$matches[1] ?? 0;
73+
}

.github/workflows/course_build.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Course Workflow
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths-ignore:
8+
- '**.md'
9+
- 'tasks/**'
10+
pull_request:
11+
branches:
12+
- master
13+
paths-ignore:
14+
- '**.md'
15+
- 'tasks/**'
16+
workflow_dispatch:
17+
18+
concurrency:
19+
group: ci-course-${{ github.ref }}-1
20+
cancel-in-progress: true
21+
22+
permissions:
23+
contents: read
24+
25+
env:
26+
extensions: opcache, simplexml, mbstring, intl
27+
tools: composer, cs2pr, phpstan, phpunit/phpunit, roave/security-advisories:dev-latest, squizlabs/php_codesniffer
28+
ini_values: post_max_size=256M, max_execution_time=180, date.timezone=Asia/Tbilisi
29+
cache_key: php-cache-v2
30+
style_report: ./build/code-style/phpcs-report.xml
31+
32+
jobs:
33+
env-setup:
34+
name: Set variables
35+
runs-on: ubuntu-latest
36+
outputs:
37+
cache-key: ${{ steps.set-variables.outputs.cache-key }}
38+
extensions: ${{ steps.set-variables.outputs.extensions }}
39+
tools: ${{ steps.set-variables.outputs.tools }}
40+
style-report: ${{ steps.set-variables.outputs.style-report }}
41+
steps:
42+
- name: Set variables
43+
id: set-variables
44+
run: |
45+
echo "::set-output name=cache-key::${{ env.cache_key }}"
46+
echo "::set-output name=extensions::${{ env.extensions }}"
47+
echo "::set-output name=tools::${{ env.tools }}"
48+
echo "::set-output name=style-report::${{ env.style_report }}"
49+
50+
security-advisory:
51+
needs: [ env-setup ]
52+
uses: edu-cat/.github/.github/workflows/_security_advisory.yml@master
53+
with:
54+
cache_key: ${{ needs.env-setup.outputs.cache-key }}
55+
extensions: ${{ needs.env-setup.outputs.extensions }}
56+
tools: ${{ needs.env-setup.outputs.tools }}
57+
58+
code-style:
59+
needs: [ env-setup ]
60+
uses: edu-cat/.github/.github/workflows/_code_style.yml@master
61+
with:
62+
cache_key: ${{ needs.env-setup.outputs.cache-key }}
63+
style_report: ${{ needs.env-setup.outputs.style-report }}
64+
extensions: ${{ needs.env-setup.outputs.extensions }}
65+
tools: ${{ needs.env-setup.outputs.tools }}
66+
67+
code-analyse:
68+
needs: [ env-setup ]
69+
uses: edu-cat/.github/.github/workflows/_code_analyse.yml@master
70+
with:
71+
cache_key: ${{ needs.env-setup.outputs.cache-key }}
72+
extensions: ${{ needs.env-setup.outputs.extensions }}
73+
tools: ${{ needs.env-setup.outputs.tools }}
74+
75+
tests:
76+
needs: [ env-setup ]
77+
uses: edu-cat/.github/.github/workflows/_tests.yml@master
78+
with:
79+
cache_key: ${{ needs.env-setup.outputs.cache-key }}
80+
extensions: ${{ needs.env-setup.outputs.extensions }}
81+
tools: ${{ needs.env-setup.outputs.tools }}

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/node_modules
2+
/vendor
3+
.env
4+
.phpunit.result.cache
5+
Homestead.json
6+
Homestead.yaml
7+
npm-debug.log
8+
yarn-error.log
9+
.phplint-cache
10+
/.idea
11+
/.vscode
12+
phpunit.xml
13+
phpstan.neon

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Dzianis Kotau
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
[![Course Build](https://github.com/edu-cat/php-trainee-template/actions/workflows/course_build.yml/badge.svg?branch=master)](https://github.com/edu-cat/php-trainee-template/actions/workflows/course_build.yml)
2+
3+
# php-trainings
4+
PHP Education program
5+
6+
# Table of Contents
7+
1. [Pre-requirements](#pre-requirements)
8+
2. [Workflow](#workflow)
9+
3. [Special Notes](#special-notes)
10+
4. [See also](#see-also)
11+
12+
## Pre-requirements
13+
1. It's highly recommended to use Ubuntu latest stable edition.
14+
2. Install `php 8.1` following instructions for your OS.
15+
3. Install and enable at least `php-xml` extension.
16+
4. Install [Composer tool](https://getcomposer.org/download/).
17+
- If you are using GNU/Linux, run as the last Composer installation step:
18+
```shell
19+
mv composer.phar /usr/local/bin/composer
20+
chmod a+x /usr/local/bin/composer
21+
```
22+
5. Optional steps if you don't yet have public/private keys for your GitHub account:
23+
- Generate public/private keys for Github. You can use `ssh-keygen` command with parameters on GNU/Linux
24+
(press `Enter` for any prompt):
25+
```shell
26+
ssh-keygen -t ecdsa -b 521 -C "course_key" -f ~/.ssh/github_php_course
27+
```
28+
- Create `~/.ssh/config` file with following instructions:
29+
```
30+
# GitHub.com
31+
Host github.com
32+
UpdateHostKeys no
33+
PreferredAuthentications publickey
34+
IdentityFile ~/.ssh/github_php_course
35+
```
36+
- [Copy](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account)
37+
ssh public key to your GitHub profile.
38+
6. Identify yourself for GitHub:
39+
```shell
40+
git config --global user.name "Your Name"
41+
git config --global user.email "your_email"
42+
```
43+
44+
## Workflow
45+
1. You will be granted access to the repository with tasks.
46+
2. Clone the repository to your machine.
47+
3. Subscribe to the repository to be able to receive any notification on it.
48+
4. Create separate branch and folder in src/ and tests/ for each task.
49+
5. When you are ready to show your solution (task and tests), create Pull Request (PR).
50+
6. If you have errors reported by GitHub Actions, check their details and fix issues.
51+
52+
## Special Notes
53+
1. See Task1 [source](src/Task1/myTernary.php) and [test](tests/Task1/MyTernaryTest.php)
54+
files as example.
55+
2. Use [PSR-12](https://www.php-fig.org/psr/psr-12/) and [PSR-4](https://www.php-fig.org/psr/psr-4/)
56+
for code styling, autoload, etc.
57+
3. Use English for comments, class, properties, methods, functions, etc.
58+
4. If you use files without class declaration, add your src file to
59+
[includes.php](lib/includes.php) file to be able to run tests.
60+
5. Before creating PR run in your machine following commands
61+
62+
- `composer phpcs` to check code style
63+
- `composer phplint` to perform static analyze
64+
- `composer phpunit` to run tests
65+
66+
6. Create PR only after all above commands run with green (success) return status.
67+
68+
## See also
69+
1. [PHP Documentation](https://www.php.net/docs.php)
70+
2. [PHP: The Right Way](https://phptherightway.com/)
71+
3. [Laracasts](https://laracasts.com/)
72+
4. [SymfonyCasts](https://symfonycasts.com/)
73+
5. [Laravel Daily](https://laraveldaily.com/)
74+
6. [PHP Point](https://www.youtube.com/c/PHPPoint/videos)
75+
7. [Composer](https://getcomposer.org/)
76+
8. [Git Book](https://git-scm.com/book/en/v2)
77+

build/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

composer.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"name": "edu-cat/php-trainee-template",
3+
"type": "project",
4+
"description": "PHP Training Course for beginners",
5+
"keywords": ["php", "training", "course", "beginner", "trainee", "junior"],
6+
"homepage": "https://github.com/edu-cat/php-trainee-template",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Dzianis Kotau",
11+
"email": "[email protected]",
12+
"homepage": "https://dzianiskotau.com/",
13+
"role": "Owner"
14+
}
15+
],
16+
"support": {
17+
"issues": "https://github.com/edu-cat/php-trainee-template/issues"
18+
},
19+
"require": {
20+
"php": "^8.1"
21+
},
22+
"require-dev": {
23+
"phpstan/phpstan": "^1.8",
24+
"phpunit/phpunit": "^9.5",
25+
"roave/security-advisories": "dev-latest",
26+
"squizlabs/php_codesniffer": "^3.6"
27+
},
28+
"autoload": {
29+
"psr-4": {
30+
"App\\": "src/"
31+
},
32+
"files": ["lib/includes.php"]
33+
},
34+
"autoload-dev": {
35+
"psr-4": {
36+
"Tests\\": "tests/"
37+
}
38+
},
39+
"scripts": {
40+
"phpcs": "phpcs --standard=PSR12 src/ tests/",
41+
"phpcbf": "phpcbf --standard=PSR12 src/ tests/",
42+
"phpunit": "XDEBUG_MODE=coverage vendor/bin/phpunit",
43+
"phpstan": "vendor/bin/phpstan analyze",
44+
"sec-advisory": "composer update --dry-run roave/security-advisories"
45+
},
46+
"config": {
47+
"optimize-autoloader": true,
48+
"preferred-install": "dist",
49+
"sort-packages": true
50+
},
51+
"minimum-stability": "dev",
52+
"prefer-stable": true
53+
}

0 commit comments

Comments
 (0)