From 690db2fd3b47541bec43e5574b34f8de42201f0b Mon Sep 17 00:00:00 2001 From: Florent Blaison Date: Thu, 9 Jun 2022 17:43:58 +0200 Subject: [PATCH 1/2] update to php 8.1 --- .gitignore | 1 + composer.json | 4 ++-- phpunit.xml.dist | 9 ++++----- src/AndSpecification.php | 2 +- src/NotSpecification.php | 5 +---- src/OrSpecification.php | 2 +- src/SpecificationInterface.php | 2 +- tests/AndSpecificationTest.php | 9 +++++---- tests/Fixtures/NotSatisfiedSpecification.php | 2 +- tests/Fixtures/SatisfiedSpecification.php | 2 +- tests/NotSpecificationTest.php | 7 ++++--- tests/OrSpecificationTest.php | 9 +++++---- 12 files changed, 27 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index 3a51b32..934f210 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /composer.phar /composer.lock php-cs-fixer +.phpunit.result.cache diff --git a/composer.json b/composer.json index a619068..a342f1c 100644 --- a/composer.json +++ b/composer.json @@ -3,10 +3,10 @@ "description": "Implementation of the specification pattern in PHP", "homepage": "https://github.com/RiskioFr/Specification", "require": { - "php": "^7.0" + "php": "^8.1" }, "require-dev": { - "phpunit/phpunit": "~5.3" + "phpunit/phpunit": "^9.5" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 27c75b0..099dce8 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,7 +8,6 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" bootstrap="./vendor/autoload.php"> @@ -16,9 +15,9 @@ - - + + src - - + + diff --git a/src/AndSpecification.php b/src/AndSpecification.php index 716be9d..0584d2a 100644 --- a/src/AndSpecification.php +++ b/src/AndSpecification.php @@ -3,7 +3,7 @@ class AndSpecification extends CompositeSpecification { - protected $specifications; + private array $specifications; public function __construct(SpecificationInterface ...$specifications) { diff --git a/src/NotSpecification.php b/src/NotSpecification.php index 06e9490..1725812 100644 --- a/src/NotSpecification.php +++ b/src/NotSpecification.php @@ -3,11 +3,8 @@ class NotSpecification implements SpecificationInterface { - protected $specification; - - public function __construct(SpecificationInterface $specification) + public function __construct(private readonly SpecificationInterface $specification) { - $this->specification = $specification; } public function isSatisfiedBy($object) : bool diff --git a/src/OrSpecification.php b/src/OrSpecification.php index d0376cb..a469833 100644 --- a/src/OrSpecification.php +++ b/src/OrSpecification.php @@ -3,7 +3,7 @@ class OrSpecification extends CompositeSpecification { - protected $specifications; + private array $specifications; public function __construct(SpecificationInterface ...$specifications) { diff --git a/src/SpecificationInterface.php b/src/SpecificationInterface.php index b5e9613..ec11cd1 100644 --- a/src/SpecificationInterface.php +++ b/src/SpecificationInterface.php @@ -3,5 +3,5 @@ interface SpecificationInterface { - public function isSatisfiedBy($object) : bool; + public function isSatisfiedBy(mixed $object) : bool; } diff --git a/tests/AndSpecificationTest.php b/tests/AndSpecificationTest.php index b0356ce..87f5dee 100644 --- a/tests/AndSpecificationTest.php +++ b/tests/AndSpecificationTest.php @@ -1,16 +1,17 @@ Date: Thu, 9 Jun 2022 17:58:34 +0200 Subject: [PATCH 2/2] add psalm, phpcs and github workflow --- .github/workflow/pr_open.yml | 54 ++++++++++++++++++++ .gitignore | 1 + .php-cs-fixer.dist.php | 29 +++++++++++ Makefile | 2 + composer.json | 3 +- psalm.xml | 15 ++++++ src/AndSpecification.php | 9 ++-- src/CompositeSpecification.php | 5 +- src/LeafSpecification.php | 5 +- src/NotSpecification.php | 7 ++- src/OrSpecification.php | 7 ++- src/SpecificationInterface.php | 5 +- tests/Fixtures/NotSatisfiedSpecification.php | 2 +- tests/Fixtures/SatisfiedSpecification.php | 2 +- 14 files changed, 133 insertions(+), 13 deletions(-) create mode 100644 .github/workflow/pr_open.yml create mode 100644 .php-cs-fixer.dist.php create mode 100644 Makefile create mode 100644 psalm.xml diff --git a/.github/workflow/pr_open.yml b/.github/workflow/pr_open.yml new file mode 100644 index 0000000..f9954e3 --- /dev/null +++ b/.github/workflow/pr_open.yml @@ -0,0 +1,54 @@ +name: Pull Request - Open + +on: + pull_request: + types: [opened, reopened, synchronize] + +jobs: + phpcs: + name: Specification style formatting + runs-on: 'ubuntu-latest' + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Run php cs fixer + run: 'make test-phpcs' + phpunit: + name: (PHP ${{ matrix.php-versions }} on ${{ matrix.command-to-launch.name }}) + runs-on: 'ubuntu-latest' + strategy: + matrix: + command-to-launch: [ + { + name: 'psalm', + command: 'psalm', + }, + { + name: 'Unit tests', + command: 'vendor/bin/phpunit --coverage-text', + } + ] + php-versions: [ '8.1' ] + phpunit-versions: [ 'latest' ] + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + tools: vimeo/psalm, phpunit + coverage: xdebug + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - name: Cache composer dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + - name: Install Composer dependencies + run: composer install --no-progress --prefer-dist --optimize-autoloader + - name: Run test + run: ${{matrix.command-to-launch.command}} diff --git a/.gitignore b/.gitignore index 934f210..943815b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /composer.lock php-cs-fixer .phpunit.result.cache +.php-cs-fixer.cache diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..706775e --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,29 @@ +in(__DIR__) + ->exclude('config') + ->exclude('var') + ->notPath('bin/console') + ->notPath('public/index.php'); + +return (new PhpCsFixer\Config()) + ->setRiskyAllowed(true) + ->setRules([ + '@Symfony' => true, + '@Symfony:risky' => true, + 'date_time_immutable' => true, + 'linebreak_after_opening_tag' => true, + 'mb_str_functions' => true, + 'no_php4_constructor' => true, + 'no_unreachable_default_argument_value' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'php_unit_strict' => false, + 'phpdoc_order' => true, + 'strict_comparison' => true, + 'strict_param' => true, + 'concat_space' => ['spacing' => 'one'], + 'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'], + ]) + ->setFinder($finder); diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..409e92e --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +test-phpcs: + docker run --rm --platform linux/amd64 -v $(PWD):/data cytopia/php-cs-fixer fix --dry-run --diff src diff --git a/composer.json b/composer.json index a342f1c..0cd2cef 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,8 @@ "php": "^8.1" }, "require-dev": { - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "^9.5", + "vimeo/psalm": "^4.22" }, "autoload": { "psr-4": { diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..365ac90 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/src/AndSpecification.php b/src/AndSpecification.php index 0584d2a..fdc199d 100644 --- a/src/AndSpecification.php +++ b/src/AndSpecification.php @@ -1,19 +1,22 @@ specifications = $specifications; } - public function isSatisfiedBy($object) : bool + public function isSatisfiedBy(mixed $object): bool { foreach ($this->specifications as $specification) { - if (! $specification->isSatisfiedBy($object)) { + if (!$specification->isSatisfiedBy($object)) { return false; } } diff --git a/src/CompositeSpecification.php b/src/CompositeSpecification.php index c959638..325fbc8 100644 --- a/src/CompositeSpecification.php +++ b/src/CompositeSpecification.php @@ -1,7 +1,10 @@ specification->isSatisfiedBy($object); } diff --git a/src/OrSpecification.php b/src/OrSpecification.php index a469833..5a577a3 100644 --- a/src/OrSpecification.php +++ b/src/OrSpecification.php @@ -1,16 +1,19 @@ specifications = $specifications; } - public function isSatisfiedBy($object) : bool + public function isSatisfiedBy(mixed $object): bool { foreach ($this->specifications as $specification) { if ($specification->isSatisfiedBy($object)) { diff --git a/src/SpecificationInterface.php b/src/SpecificationInterface.php index ec11cd1..5279167 100644 --- a/src/SpecificationInterface.php +++ b/src/SpecificationInterface.php @@ -1,7 +1,10 @@