Skip to content

Commit

Permalink
Overhaul tool usage in CI and for contribution (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-mxp committed Feb 18, 2024
1 parent b80fc00 commit d3a686c
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 145 deletions.
54 changes: 31 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,61 @@
# 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

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

### All dependencies
The following system dependencies are required:

```shell
> ./bin/install.sh
```
- `composer`, as recommended in the [PHP track installation docs][exercism-track-installation-composer].
- [`bash` shell][gnu-bash]

### Only tests dependencies
Run the following commands to get started with this project:

```shell
> ./bin/install-phpunit-9.sh
bin/fetch-configlet # The official tool for managing Exercism language track repositories
composer install # Required dependencies to develop this track
```

### Only style-check dependencies
## Running Exercism resources management

```shell
> ./bin/install-phpcs.sh
```
`bin/configlet` is a tool to manage exercism resources in this track.
See [Building Exercism docs][exercism-configlet].

## Running Unit Test Suite

### PHPUnit 9
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
> PHPUNIT_BIN="./bin/phpunit-9.phar" ./bin/test.sh
composer test:run
```

## Running Style Checker

### PSR-12 rules
This project use a slightly [modified][local-file-phpcs-config] version of [PSR-12].
Use the following commands to apply code style:

```shell
> PHPCS_BIN="./bin/phpcs.phar" PHPCS_RULES="./phpcs-php.xml" ./bin/lint.sh
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 (PHP 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

[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
[docs]: https://exercism.org/docs
[@group annotation]: https://phpunit.de/manual/4.1/en/appendixes.annotations.html#appendixes.annotations.group
[modified]: phpcs-php.xml
6 changes: 0 additions & 6 deletions bin/install-phpcs.sh

This file was deleted.

6 changes: 0 additions & 6 deletions bin/install-phpunit-9.sh

This file was deleted.

6 changes: 0 additions & 6 deletions bin/install.sh

This file was deleted.

76 changes: 0 additions & 76 deletions bin/lint.sh

This file was deleted.

8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
"squizlabs/php_codesniffer": "^3.9"
},
"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",
"lint:fix": "phpcbf",
"tests:run": "PHPUNIT_BIN='phpunit' bin/test.sh"
}
}
1 change: 0 additions & 1 deletion exercises/concept/annalyns-infiltration/.meta/exemplar.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@ public function canLiberate(
);
}
}

3 changes: 2 additions & 1 deletion exercises/concept/city-office/ReflectionAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions exercises/concept/lucky-numbers/.meta/exemplar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
}
Expand Down
1 change: 0 additions & 1 deletion exercises/concept/sweethearts/.meta/exemplar.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,3 @@ public function pair(
HEART;
}
}

20 changes: 0 additions & 20 deletions phpcs-php.xml

This file was deleted.

52 changes: 52 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0"?>
<ruleset
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd"
name="Exercism PHP Coding Standard"
>
<description>Coding standard for Exercism PHP exercises</description>

<!-- Expect all files are UTF-8 -->
<arg name="encoding" value="utf-8" />

<!-- No warnings (ignore them) -->
<arg value="n" />

<!-- Show sniffs (it's easy to find solutions knowing the code) -->
<arg value="s" />

<!-- A TAB is 4 chars wide (does not replace them, for calculation only!) -->
<arg name="tab-width" value="4" />

<!-- Run on 60 files in parallel -->
<arg name="parallel" value="60" />

<file>exercises</file>
<file>src</file>

<!-- Include all sniffs in the PSR12 standard except... -->
<rule ref="PSR12">
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
<exclude name="PSR1.Classes.ClassDeclaration.MultipleClasses" />
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
</rule>
<rule ref="Squiz.Scope.MethodScope.Missing">
<exclude-pattern>*/concept/city-office/*</exclude-pattern>
<exclude-pattern>*/concept/windowing-system/*</exclude-pattern>
</rule>
<rule ref="vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/TypeHints/DeclareStrictTypesSniff.php">
<exclude-pattern>*/.meta/*\.php</exclude-pattern>
<exclude-pattern>*/concept/*</exclude-pattern>
<exclude-pattern>*/hello-world/*</exclude-pattern>
<properties>
<property name="linesCountBeforeDeclare" value="1" />
<property name="linesCountAfterDeclare" value="1" />
<property name="spacesCountAroundEqualsSign" value="0" />
</properties>
</rule>
<rule ref="src/Sniffs/ExplainStrictTypesSniff.php">
<exclude-pattern>*/*Test\.php</exclude-pattern>
<exclude-pattern>*/.meta/*\.php</exclude-pattern>
<exclude-pattern>src/*</exclude-pattern>
</rule>
</ruleset>

0 comments on commit d3a686c

Please sign in to comment.