From 2206b68da8ca3f0371935d27eb62ff7040ce01f4 Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Wed, 6 Dec 2023 14:19:22 +0100 Subject: [PATCH 01/11] Put all rules into PHPCS config - Add XML namespace for completeness - Remove non-existent `type="int"` - Add directory rules for improved test coverage and required exceptions - Fix the new upcoming violations --- composer.json | 4 ++-- .../annalyns-infiltration/.meta/exemplar.php | 1 - .../city-office/.meta/exemplar/Form.php | 8 +++---- exercises/concept/city-office/Form.php | 8 +++---- .../city-office/ReflectionAssertions.php | 3 ++- .../concept/lucky-numbers/.meta/exemplar.php | 6 +++-- .../concept/sweethearts/.meta/exemplar.php | 1 - .../windowing-system/.meta/exemplar.php | 10 ++++---- phpcs-php.xml | 24 +++++++++++++++---- 9 files changed, 40 insertions(+), 25 deletions(-) diff --git a/composer.json b/composer.json index 2dafd129..f742ac78 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "squizlabs/php_codesniffer": "^3.8" }, "scripts": { - "lint:check": "./vendor/bin/phpcs --ignore=*/hello-world/*,*/concept/* --standard=phpcs-php.xml ./exercises", - "lint:fix": "./vendor/bin/phpcbf --standard=phpcs-php.xml ./exercises" + "lint:check": "phpcs --standard=phpcs-php.xml", + "lint:fix": "phpcbf --standard=phpcs-php.xml" } } diff --git a/exercises/concept/annalyns-infiltration/.meta/exemplar.php b/exercises/concept/annalyns-infiltration/.meta/exemplar.php index 1595db77..99882ce5 100644 --- a/exercises/concept/annalyns-infiltration/.meta/exemplar.php +++ b/exercises/concept/annalyns-infiltration/.meta/exemplar.php @@ -34,4 +34,3 @@ public function canLiberate( ); } } - diff --git a/exercises/concept/city-office/.meta/exemplar/Form.php b/exercises/concept/city-office/.meta/exemplar/Form.php index e8f14f62..5c0dbedc 100644 --- a/exercises/concept/city-office/.meta/exemplar/Form.php +++ b/exercises/concept/city-office/.meta/exemplar/Form.php @@ -2,23 +2,23 @@ class Form { - function blanks(int $length): string + public function blanks(int $length): string { return str_repeat(" ", $length); } - function letters(string $word): array + public function letters(string $word): array { return mb_str_split($word); } - function checkLength(string $word, int $max_length): bool + public function checkLength(string $word, int $max_length): bool { $difference = mb_strlen($word) - $max_length; return $difference <= 0; } - function formatAddress(Address $address): string + public function formatAddress(Address $address): string { $formatted_street = mb_strtoupper($address->street); $formatted_postal_code = mb_strtoupper($address->postal_code); diff --git a/exercises/concept/city-office/Form.php b/exercises/concept/city-office/Form.php index 5fa879ff..38dab65d 100644 --- a/exercises/concept/city-office/Form.php +++ b/exercises/concept/city-office/Form.php @@ -2,23 +2,23 @@ class Form { - function blanks($length) + public function blanks($length) { return str_repeat(" ", $length); } - function letters($word) + public function letters($word) { return mb_str_split($word); } - function checkLength($word, $max_length) + public function checkLength($word, $max_length) { $difference = mb_strlen($word) - $max_length; return $difference <= 0; } - function formatAddress($address) + public function formatAddress($address) { $formatted_street = mb_strtoupper($address->street); $formatted_postal_code = mb_strtoupper($address->postal_code); diff --git a/exercises/concept/city-office/ReflectionAssertions.php b/exercises/concept/city-office/ReflectionAssertions.php index 39704b2b..15ba0448 100644 --- a/exercises/concept/city-office/ReflectionAssertions.php +++ b/exercises/concept/city-office/ReflectionAssertions.php @@ -45,7 +45,8 @@ private function assertMethodParameter( if (is_null($parameter)) { $this->fail( "Method '$parameter_name' missing parameter $parameter_index" - . " named '$parameter_name'"); + . " named '$parameter_name'" + ); } if ($parameter->getName() !== $parameter_name) { diff --git a/exercises/concept/lucky-numbers/.meta/exemplar.php b/exercises/concept/lucky-numbers/.meta/exemplar.php index 2b90d9c2..c3366d83 100644 --- a/exercises/concept/lucky-numbers/.meta/exemplar.php +++ b/exercises/concept/lucky-numbers/.meta/exemplar.php @@ -17,11 +17,13 @@ public function isPalindrome(int $number): bool public function validate(string $input): string { - if ($input === '') + if ($input === '') { return 'Required field'; + } - if ((int) $input <= 0) + if ((int) $input <= 0) { return 'Must be a whole number larger than 0'; + } return ''; } diff --git a/exercises/concept/sweethearts/.meta/exemplar.php b/exercises/concept/sweethearts/.meta/exemplar.php index bb87982a..f79a0935 100644 --- a/exercises/concept/sweethearts/.meta/exemplar.php +++ b/exercises/concept/sweethearts/.meta/exemplar.php @@ -46,4 +46,3 @@ public function pair( HEART; } } - diff --git a/exercises/concept/windowing-system/.meta/exemplar.php b/exercises/concept/windowing-system/.meta/exemplar.php index 80596c42..c49a7e98 100644 --- a/exercises/concept/windowing-system/.meta/exemplar.php +++ b/exercises/concept/windowing-system/.meta/exemplar.php @@ -7,7 +7,7 @@ class ProgramWindow public $height; public $width; - function __construct() + public function __construct() { $this->y = 0; $this->x = 0; @@ -15,13 +15,13 @@ function __construct() $this->width = 800; } - function move(Position $position) + public function move(Position $position) { $this->y = $position->y; $this->x = $position->x; } - function resize(Size $size) + public function resize(Size $size) { $this->height = $size->height; $this->width = $size->width; @@ -33,7 +33,7 @@ class Position public $y; public $x; - function __construct($y, $x) + public function __construct($y, $x) { $this->y = $y; $this->x = $x; @@ -45,7 +45,7 @@ class Size public $height; public $width; - function __construct($height, $width) + public function __construct($height, $width) { $this->height = $height; $this->width = $width; diff --git a/phpcs-php.xml b/phpcs-php.xml index 06d866c5..5c75ce02 100644 --- a/phpcs-php.xml +++ b/phpcs-php.xml @@ -1,6 +1,13 @@ - - Coding standard for xPHP + + Coding standard for Exercism PHP exercises + + exercises + src @@ -11,10 +18,17 @@ + */exemplar\.php + */concept/* + */hello-world/* - - + + - + + */*Test\.php + */exemplar\.php + src/* + From bf8501fc3a53d9611442c785aa5a17765ae21ab0 Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Wed, 6 Dec 2023 18:01:11 +0100 Subject: [PATCH 02/11] Revert visibility for certain concept exercises - Revert adding visibility - Exclude those exercises from PHPCS rule --- .../city-office/.meta/exemplar/Form.php | 8 ++++---- exercises/concept/city-office/Form.php | 8 ++++---- .../windowing-system/.meta/exemplar.php | 10 +++++----- phpcs-php.xml | 19 +++++++++++++++++++ 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/exercises/concept/city-office/.meta/exemplar/Form.php b/exercises/concept/city-office/.meta/exemplar/Form.php index 5c0dbedc..e8f14f62 100644 --- a/exercises/concept/city-office/.meta/exemplar/Form.php +++ b/exercises/concept/city-office/.meta/exemplar/Form.php @@ -2,23 +2,23 @@ class Form { - public function blanks(int $length): string + function blanks(int $length): string { return str_repeat(" ", $length); } - public function letters(string $word): array + function letters(string $word): array { return mb_str_split($word); } - public function checkLength(string $word, int $max_length): bool + function checkLength(string $word, int $max_length): bool { $difference = mb_strlen($word) - $max_length; return $difference <= 0; } - public function formatAddress(Address $address): string + function formatAddress(Address $address): string { $formatted_street = mb_strtoupper($address->street); $formatted_postal_code = mb_strtoupper($address->postal_code); diff --git a/exercises/concept/city-office/Form.php b/exercises/concept/city-office/Form.php index 38dab65d..5fa879ff 100644 --- a/exercises/concept/city-office/Form.php +++ b/exercises/concept/city-office/Form.php @@ -2,23 +2,23 @@ class Form { - public function blanks($length) + function blanks($length) { return str_repeat(" ", $length); } - public function letters($word) + function letters($word) { return mb_str_split($word); } - public function checkLength($word, $max_length) + function checkLength($word, $max_length) { $difference = mb_strlen($word) - $max_length; return $difference <= 0; } - public function formatAddress($address) + function formatAddress($address) { $formatted_street = mb_strtoupper($address->street); $formatted_postal_code = mb_strtoupper($address->postal_code); diff --git a/exercises/concept/windowing-system/.meta/exemplar.php b/exercises/concept/windowing-system/.meta/exemplar.php index c49a7e98..80596c42 100644 --- a/exercises/concept/windowing-system/.meta/exemplar.php +++ b/exercises/concept/windowing-system/.meta/exemplar.php @@ -7,7 +7,7 @@ class ProgramWindow public $height; public $width; - public function __construct() + function __construct() { $this->y = 0; $this->x = 0; @@ -15,13 +15,13 @@ public function __construct() $this->width = 800; } - public function move(Position $position) + function move(Position $position) { $this->y = $position->y; $this->x = $position->x; } - public function resize(Size $size) + function resize(Size $size) { $this->height = $size->height; $this->width = $size->width; @@ -33,7 +33,7 @@ class Position public $y; public $x; - public function __construct($y, $x) + function __construct($y, $x) { $this->y = $y; $this->x = $x; @@ -45,7 +45,7 @@ class Size public $height; public $width; - public function __construct($height, $width) + function __construct($height, $width) { $this->height = $height; $this->width = $width; diff --git a/phpcs-php.xml b/phpcs-php.xml index 5c75ce02..b2edb60c 100644 --- a/phpcs-php.xml +++ b/phpcs-php.xml @@ -6,6 +6,21 @@ > Coding standard for Exercism PHP exercises + + + + + + + + + + + + + + + exercises src @@ -17,6 +32,10 @@ + + */concept/city-office/* + */concept/windowing-system/* + */exemplar\.php */concept/* From 0aaabc475c5552666e39e8b4931b3c45ec152aa1 Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Wed, 6 Dec 2023 19:42:19 +0100 Subject: [PATCH 03/11] Use phpunit from composer in contribution workflow --- README.md | 49 +++++++++++++++----------- bin/install-phpcs.sh | 6 ---- bin/install-phpunit-9.sh | 6 ---- bin/install.sh | 6 ---- bin/lint.sh | 76 ---------------------------------------- composer.json | 4 ++- 6 files changed, 31 insertions(+), 116 deletions(-) delete mode 100755 bin/install-phpcs.sh delete mode 100755 bin/install-phpunit-9.sh delete mode 100755 bin/install.sh delete mode 100755 bin/lint.sh diff --git a/README.md b/README.md index e13b9097..2551573c 100644 --- a/README.md +++ b/README.md @@ -1,53 +1,60 @@ # Exercism PHP Track -![Configlet Status](https://github.com/exercism/php/workflows/Configlet%20CI/badge.svg) -[![Codacy Badge](https://api.codacy.com/project/badge/Grade/68242198cd124a3ebcbdc291d0e0eda4)](https://www.codacy.com/app/borgogelli/php?utm_source=github.com&utm_medium=referral&utm_content=borgogelli/php&utm_campaign=Badge_Grade) - Exercism exercises in PHP -## Install Dependencies +Follow these instructions, if you want to contribute to the track. +You must have a BASH shell to run the tooling locally. -### All dependencies +If you only want to solve the exercises, go to the [track docs][track-docs] and choose your installation option there. -```shell -> ./bin/install.sh -``` +## Install Dependencies -### Only tests dependencies +You must have installed `composer` as a global tool as recommended in the [PHP track installation docs][composer-installation-docs]. ```shell -> ./bin/install-phpunit-9.sh +bin/fetch-configlet +composer install ``` -### Only style-check dependencies +You now have all tools required to contribute. -```shell -> ./bin/install-phpcs.sh -``` +## Running Exercism resources management + +`bin/configlet` is a tool to manage exercism resources in this track. +See [Building Exercism docs][configlet-docs]. ## Running Unit Test Suite -### PHPUnit 9 +We use PHPUnit 9.6.x and a shell loop injecting `exemplar.php` as the solution for testing: ```shell -> PHPUNIT_BIN="./bin/phpunit-9.phar" ./bin/test.sh +composer test:run ``` ## Running Style Checker -### PSR-12 rules +We apply PSR-12 rules with minor tweaks and some exceptions: ```shell -> PHPCS_BIN="./bin/phpcs.phar" PHPCS_RULES="./phpcs-php.xml" ./bin/lint.sh +composer lint:check +``` + +To auto-fix the coding styles: + +```shell +composer lint:fix ``` ## Contributing - Read the documentation at [Exercism][docs]. -- Follow the [PSR-12] coding style (PHP uses a slightly [modified] version of [PSR-12]). +- Follow the [PSR-12] coding style (Exercisms PHP track uses a slightly [modified] version of [PSR-12]). - CI is run on all pull requests, it must pass the required checks for merge. +- CI is running all tests on PHP 8.0 to PHP 8.2 -[psr-12]: https://www.php-fig.org/psr/psr-12 +[composer-installation-docs]: https://exercism.org/docs/tracks/php/installation#h-install-composer +[configlet-docs]: https://exercism.org/docs/building/configlet [docs]: https://exercism.org/docs -[@group annotation]: https://phpunit.de/manual/4.1/en/appendixes.annotations.html#appendixes.annotations.group [modified]: phpcs-php.xml +[psr-12]: https://www.php-fig.org/psr/psr-12 +[track-docs]: https://exercism.org/docs/tracks/php/installation diff --git a/bin/install-phpcs.sh b/bin/install-phpcs.sh deleted file mode 100755 index 9ee6fbf3..00000000 --- a/bin/install-phpcs.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -curl -Lo bin/phpcs.phar https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar -chmod +x bin/phpcs.phar diff --git a/bin/install-phpunit-9.sh b/bin/install-phpunit-9.sh deleted file mode 100755 index 88452628..00000000 --- a/bin/install-phpunit-9.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -curl -Lo ./bin/phpunit-9.phar https://phar.phpunit.de/phpunit-9.phar -chmod +x bin/phpunit-9.phar diff --git a/bin/install.sh b/bin/install.sh deleted file mode 100755 index 1507bc58..00000000 --- a/bin/install.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -./bin/install-phpunit-9.sh -./bin/install-phpcs.sh diff --git a/bin/lint.sh b/bin/lint.sh deleted file mode 100755 index ca89e9fd..00000000 --- a/bin/lint.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env bash - -set -uo pipefail - -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[0;33m' -NC='\033[0m' # No Color - -function main { - has_failures=0 - - all_exercise_dirs=$(find ./exercises -maxdepth 2 -mindepth 2 -type d | sort) - for exercise_dir in $all_exercise_dirs; do - if [[ "${exercise_dir}" == *"hello-world"* ]]; then - continue - fi - - lint "${exercise_dir}" - if [[ $? -ne 0 ]]; then - has_failures=1 - fi - done - - return $has_failures -} - -function lint { - exercise_dir="${1}" - exercise=$(basename "${exercise_dir}") - echo -e "Checking ${YELLOW}${exercise}${NC} against PHP code standards" - - eval "${PHPCS_BIN}" \ - -sp \ - --standard="${PHPCS_RULES}" \ - "${exercise_dir}" -} - -function installed { - cmd=$(command -v "${1}") - - [[ -n "${cmd}" ]] && [[ -f "${cmd}" ]] - return ${?} -} - -function die { - >&2 echo "Fatal: ${@}" - exit 1 -} - -if [[ -z "${PHPCS_BIN:-}" ]]; then - die "Missing PHPCS_BIN environment variable"; -fi - -if [[ -z "${PHPCS_RULES:-}" ]]; then - die "Missing PHPCS_RULES environment variable"; -fi - -if [[ ! -f "${PHPCS_RULES}" ]]; then - die "PHPCS xml ruleset at '${PHPCS_RULES}' does not exist" -fi - -# Check for all required dependencies -deps=(curl "${PHPCS_BIN}") -for dep in "${deps[@]}"; do - installed "${dep}" || die "Missing '${dep}'" -done - -main "$@" - -if [[ $? -ne 0 ]]; then - echo -e "Some checks ${RED}failed${NC}. See log." - exit 1 -fi - -exit diff --git a/composer.json b/composer.json index f742ac78..1fc08919 100644 --- a/composer.json +++ b/composer.json @@ -11,11 +11,13 @@ }, "require-dev": { "php": "^7.4|^8.0", + "phpunit/phpunit": "^9.6", "slevomat/coding-standard": "^8.14.1", "squizlabs/php_codesniffer": "^3.8" }, "scripts": { "lint:check": "phpcs --standard=phpcs-php.xml", - "lint:fix": "phpcbf --standard=phpcs-php.xml" + "lint:fix": "phpcbf --standard=phpcs-php.xml", + "tests:run": "PHPUNIT_BIN='phpunit' bin/test.sh" } } From 4cdfbc5404260ae597a4fdcd0bff02ea3efa38f1 Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Wed, 6 Dec 2023 19:48:23 +0100 Subject: [PATCH 04/11] Improve style checker instructions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2551573c..e877a6d0 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ composer test:run ## Running Style Checker -We apply PSR-12 rules with minor tweaks and some exceptions: +We use a slightly [modified] version of [PSR-12] and some exceptions: ```shell composer lint:check From da44d36e3bfb744934c43adfd447361b3fa60cc8 Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Thu, 7 Dec 2023 16:53:57 +0100 Subject: [PATCH 05/11] Rename PHPCS rule to default name and omit it For testing CI test file coverage, print verbose output --- composer.json | 4 ++-- phpcs-php.xml => phpcs.xml | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename phpcs-php.xml => phpcs.xml (100%) diff --git a/composer.json b/composer.json index 1fc08919..41694f44 100644 --- a/composer.json +++ b/composer.json @@ -16,8 +16,8 @@ "squizlabs/php_codesniffer": "^3.8" }, "scripts": { - "lint:check": "phpcs --standard=phpcs-php.xml", - "lint:fix": "phpcbf --standard=phpcs-php.xml", + "lint:check": "phpcs -v", + "lint:fix": "phpcbf", "tests:run": "PHPUNIT_BIN='phpunit' bin/test.sh" } } diff --git a/phpcs-php.xml b/phpcs.xml similarity index 100% rename from phpcs-php.xml rename to phpcs.xml From 31efa6693db35af3fe809ebcb9d8289e51c59022 Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Thu, 7 Dec 2023 16:55:58 +0100 Subject: [PATCH 06/11] Run PHPCS quietly again --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 41694f44..8cc9c436 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "squizlabs/php_codesniffer": "^3.8" }, "scripts": { - "lint:check": "phpcs -v", + "lint:check": "phpcs", "lint:fix": "phpcbf", "tests:run": "PHPUNIT_BIN='phpunit' bin/test.sh" } From afaeda07c646dd73fdc313c70bffe2851818c4c7 Mon Sep 17 00:00:00 2001 From: mk-mxp Date: Wed, 27 Dec 2023 15:56:38 +0000 Subject: [PATCH 07/11] Require empty line after `declare(strict_types=1);` This is actually present everywhere in the code base, but not explicitly covered by the rules. --- phpcs.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/phpcs.xml b/phpcs.xml index b2edb60c..15c3efda 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -42,6 +42,7 @@ */hello-world/* + From 14e814a737b258763df54209dc083e7196d8f98a Mon Sep 17 00:00:00 2001 From: mk-mxp Date: Wed, 27 Dec 2023 16:33:43 +0000 Subject: [PATCH 08/11] Point links in README to phpcs.xml, not old name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e877a6d0..7087b16a 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,6 @@ composer lint:fix [composer-installation-docs]: https://exercism.org/docs/tracks/php/installation#h-install-composer [configlet-docs]: https://exercism.org/docs/building/configlet [docs]: https://exercism.org/docs -[modified]: phpcs-php.xml +[modified]: phpcs.xml [psr-12]: https://www.php-fig.org/psr/psr-12 [track-docs]: https://exercism.org/docs/tracks/php/installation From f8ee86db00d3de9e6458084ff6d95d09e94035c0 Mon Sep 17 00:00:00 2001 From: mk-mxp Date: Sat, 10 Feb 2024 10:01:25 +0000 Subject: [PATCH 09/11] Exclude all */.meta/*.php from strict typing The file names are set in `.meta/config.json`. And some exercises have more than one file as example solution. --- phpcs.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpcs.xml b/phpcs.xml index 15c3efda..230c30c4 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -37,7 +37,7 @@ */concept/windowing-system/* - */exemplar\.php + */.meta/*\.php */concept/* */hello-world/* @@ -48,7 +48,7 @@ */*Test\.php - */exemplar\.php + */.meta/*\.php src/* From 21f15df2fae0819c52a68f0aa87a56f3d84613ff Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Sun, 18 Feb 2024 19:06:46 +0100 Subject: [PATCH 10/11] Update PHPCodeSniffer to 3.9 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8cc9c436..38dd195f 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "php": "^7.4|^8.0", "phpunit/phpunit": "^9.6", "slevomat/coding-standard": "^8.14.1", - "squizlabs/php_codesniffer": "^3.8" + "squizlabs/php_codesniffer": "^3.9" }, "scripts": { "lint:check": "phpcs", From b3c1b94b7aa7e026beafa4870db21c18204a8757 Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Sun, 18 Feb 2024 19:23:07 +0100 Subject: [PATCH 11/11] Apply suggestion from review and improve markdown --- README.md | 53 +++++++++++++++++++++++++++-------------------------- phpcs.xml | 6 ++---- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 7087b16a..906b6caa 100644 --- a/README.md +++ b/README.md @@ -2,30 +2,33 @@ Exercism exercises in PHP -Follow these instructions, if you want to contribute to the track. -You must have a BASH shell to run the tooling locally. - -If you only want to solve the exercises, go to the [track docs][track-docs] and choose your installation option there. +Follow these instructions to contribute to the PHP track. +To solve the exercises, head to the [PHP track][exercism-track-home] and check the [documentation][exercism-track-installation]. ## Install Dependencies -You must have installed `composer` as a global tool as recommended in the [PHP track installation docs][composer-installation-docs]. +The following system dependencies are required: + +- `composer`, as recommended in the [PHP track installation docs][exercism-track-installation-composer]. +- [`bash` shell][gnu-bash] + +Run the following commands to get started with this project: ```shell -bin/fetch-configlet -composer install +bin/fetch-configlet # The official tool for managing Exercism language track repositories +composer install # Required dependencies to develop this track ``` -You now have all tools required to contribute. - ## Running Exercism resources management `bin/configlet` is a tool to manage exercism resources in this track. -See [Building Exercism docs][configlet-docs]. +See [Building Exercism docs][exercism-configlet]. ## Running Unit Test Suite -We use PHPUnit 9.6.x and a shell loop injecting `exemplar.php` as the solution for testing: +The tests are run with PHPUnit. A shell loop injecting `exemplar.php` is provided to ease testing. + +Execute the following command to run the tests: ```shell composer test:run @@ -33,28 +36,26 @@ composer test:run ## Running Style Checker -We use a slightly [modified] version of [PSR-12] and some exceptions: - -```shell -composer lint:check -``` - -To auto-fix the coding styles: +This project use a slightly [modified][local-file-phpcs-config] version of [PSR-12]. +Use the following commands to apply code style: ```shell -composer lint:fix +composer lint:check # Checks the files against the code style rules +composer lint:fix # Automatically fix codestyle issues ``` ## Contributing -- Read the documentation at [Exercism][docs]. -- Follow the [PSR-12] coding style (Exercisms PHP track uses a slightly [modified] version of [PSR-12]). +- Read the documentation at [Exercism][exercism-docs]. +- Follow the [PSR-12] coding style (Exercisms PHP track uses a slightly [modified][local-file-phpcs-config] version of [PSR-12]). - CI is run on all pull requests, it must pass the required checks for merge. - CI is running all tests on PHP 8.0 to PHP 8.2 -[composer-installation-docs]: https://exercism.org/docs/tracks/php/installation#h-install-composer -[configlet-docs]: https://exercism.org/docs/building/configlet -[docs]: https://exercism.org/docs -[modified]: phpcs.xml +[exercism-configlet]: https://exercism.org/docs/building/configlet +[exercism-docs]: https://exercism.org/docs +[exercism-track-home]: https://exercism.org/docs/tracks/php +[exercism-track-installation]: https://exercism.org/docs/tracks/php/installation +[exercism-track-installation-composer]: https://exercism.org/docs/tracks/php/installation#h-install-composer +[gnu-bash]: https://www.gnu.org/software/bash/ +[local-file-phpcs-config]: phpcs.xml [psr-12]: https://www.php-fig.org/psr/psr-12 -[track-docs]: https://exercism.org/docs/tracks/php/installation diff --git a/phpcs.xml b/phpcs.xml index 230c30c4..8c701492 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -18,14 +18,12 @@ - - + + exercises src - -