From 73fc5059cb4900cfaf1e0c2ce60730f6de70f13a Mon Sep 17 00:00:00 2001 From: Nicholas Ruunu Date: Wed, 19 Jun 2024 01:13:54 +0200 Subject: [PATCH] Update to PHP 8.2, namespace and add author --- .coveralls.yml | 1 - .travis.yml | 28 ------------------- README.md | 10 +++---- composer.json | 18 ++++++------ phpspec.yml.dist | 15 ++-------- rector.php | 24 ++++++++++++++++ spec/AndXSpec.php | 10 +++---- spec/CompositeSpecificationSpec.php | 37 +++++++++++++------------ spec/NotSpec.php | 18 ++++++------ spec/OrXSpec.php | 10 +++---- src/AndX.php | 27 ++++-------------- src/CompositeSpecification.php | 24 ++++++---------- src/CompositeSpecificationInterface.php | 25 +++-------------- src/Not.php | 20 ++++--------- src/OrX.php | 13 +++++---- src/SpecificationInterface.php | 12 ++------ 16 files changed, 112 insertions(+), 180 deletions(-) delete mode 100644 .coveralls.yml delete mode 100644 .travis.yml create mode 100644 rector.php diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index 7a18ce2..0000000 --- a/.coveralls.yml +++ /dev/null @@ -1 +0,0 @@ -src_dir: src diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 067b32c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,28 +0,0 @@ -language: php - -php: - - 5.3 - - 5.4 - - 5.5 - - 5.6 - -sudo: false - -cache: - directories: - - $HOME/.composer/cache - -before_install: - - travis_retry composer self-update - -install: - - travis_retry composer install --no-interaction - -before_script: - - mkdir -p build/logs - -script: - - composer test - -after_success: - - php vendor/bin/coveralls -v diff --git a/README.md b/README.md index 3d50125..53a4421 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Specification +# Specification [![Build Status](https://travis-ci.org/rikbruil/specification.svg)](https://travis-ci.org/rikbruil/specification) [![Coverage Status](https://coveralls.io/repos/rikbruil/specification/badge.svg?branch=master)](https://coveralls.io/r/rikbruil/specification?branch=master) [![Latest Stable Version](https://poser.pugx.org/rikbruil/specification/v/stable.svg)](https://packagist.org/packages/rikbruil/specification) @@ -13,23 +13,23 @@ PHP implementation of the [Specification pattern][specification_pattern] $overDue = new OverDueSpecification(); $noticeSent = new NoticeSentSpecification(); $inCollection = new InCollectionSpecification(); - + // example of specification pattern logic chaining $sendToCollection = $overDue->andX($noticeSent) ->not($inCollection); - + foreach ($service->getInvoices() as $currentInvoice) { if (! $sendToCollection->isSatisfiedBy($currentInvoice)) { continue; } - + $currentInvoice->sendToCollection(); } ``` ## Requirements -- PHP 5.3+ +- PHP 8.2+ ## License diff --git a/composer.json b/composer.json index 9c45241..9935328 100644 --- a/composer.json +++ b/composer.json @@ -1,10 +1,14 @@ { - "name": "rikbruil/specification", + "name": "purist/specification", "description": "A PHP implementation of the Specification-pattern", "type": "library", "keywords": ["specification", "pattern"], "license": "MIT", "authors": [ + { + "name": "Nicholas Ruunu", + "email": "nicholas@ruu.nu" + }, { "name": "Rik Bruil", "email": "rik.bruil@gmail.com" @@ -12,19 +16,17 @@ ], "minimum-stability": "stable", "autoload": { - "psr-4": {"Rb\\Specification\\": "src/"} + "psr-4": {"Purist\\Specification\\": "src/"} }, "autoload-dev": { - "psr-4": {"spec\\Rb\\Specification\\": "spec/"} + "psr-4": {"spec\\Purist\\Specification\\": "spec/"} }, "require": { - "php": ">=5.3.3" + "php": "^8.2" }, "require-dev": { - "phpspec/phpspec": "~2.1@dev", - "henrikbjorn/phpspec-code-coverage": "~1.0", - "satooshi/php-coveralls": "~0.6", - "fabpot/php-cs-fixer": "~1.5" + "phpspec/phpspec": "^7.5", + "rector/rector": "^1.1" }, "extra": { "branch-alias": { diff --git a/phpspec.yml.dist b/phpspec.yml.dist index a37ba91..c5da2ab 100644 --- a/phpspec.yml.dist +++ b/phpspec.yml.dist @@ -1,15 +1,4 @@ -extensions: - - PhpSpec\Extension\CodeCoverageExtension - -code_coverage: - format: - - clover - - html - output: - html: build/logs/html - clover: build/logs/clover.xml - suites: main: - namespace: Rb\Specification - psr4_prefix: Rb\Specification + namespace: Purist\Specification + psr4_prefix: Purist\Specification diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..3f0d7e7 --- /dev/null +++ b/rector.php @@ -0,0 +1,24 @@ +withPaths([ + __DIR__ . '/src', + __DIR__ . '/spec', + ])->withPhpSets(php83: true)->withAttributesSets( + symfony: true, + doctrine: true, + ) + // here we can define, what prepared sets of rules will be applied + ->withPreparedSets( + deadCode: true, + codeQuality: true, + codingStyle: true, + typeDeclarations: true, + privatization: true, + instanceOf: true, + earlyReturn: true, + strictBooleans: true, + ); diff --git a/spec/AndXSpec.php b/spec/AndXSpec.php index 9fec288..678d97d 100644 --- a/spec/AndXSpec.php +++ b/spec/AndXSpec.php @@ -1,13 +1,13 @@ beConstructedWith($specificationA, $specificationB); @@ -18,7 +18,7 @@ public function it_should_fail_if_one_child_fails(SpecificationInterface $specif $this->isSatisfiedBy($className)->shouldReturn(false); } - public function it_should_pass_if_both_children_pass(SpecificationInterface $specificationA, SpecificationInterface $specificationB) + public function it_should_pass_if_both_children_pass(SpecificationInterface $specificationA, SpecificationInterface $specificationB): void { $className = 'foo'; $this->beConstructedWith($specificationA, $specificationB); @@ -29,7 +29,7 @@ public function it_should_pass_if_both_children_pass(SpecificationInterface $spe $this->isSatisfiedBy($className)->shouldReturn(true); } - public function it_should_fail_if_both_children_fail(SpecificationInterface $specificationA, SpecificationInterface $specificationB) + public function it_should_fail_if_both_children_fail(SpecificationInterface $specificationA, SpecificationInterface $specificationB): void { $className = 'foo'; $this->beConstructedWith($specificationA, $specificationB); diff --git a/spec/CompositeSpecificationSpec.php b/spec/CompositeSpecificationSpec.php index 295ab61..af67be9 100644 --- a/spec/CompositeSpecificationSpec.php +++ b/spec/CompositeSpecificationSpec.php @@ -1,60 +1,61 @@ beAnInstanceOf('spec\Rb\Specification\DummySpec'); + $this->beAnInstanceOf('spec\Purist\Specification\DummySpec'); } - public function it_is_initializable() + public function it_is_initializable(): void { - $this->shouldHaveType('Rb\Specification\CompositeSpecification'); + $this->shouldHaveType(\Purist\Specification\CompositeSpecification::class); } - public function it_should_return_and_specification(SpecificationInterface $specification) + public function it_should_return_and_specification(SpecificationInterface $specification): void { $specification->isSatisfiedBy('foo')->willReturn(true); $and = $this->andX($specification); - $and->shouldHaveType('Rb\Specification\AndX'); + $and->shouldHaveType(\Purist\Specification\AndX::class); $and->isSatisfiedBy('foo')->shouldReturn(true); } - public function it_should_return_or_specification(SpecificationInterface $specification) + public function it_should_return_or_specification(SpecificationInterface $specification): void { $specification->isSatisfiedBy('foo')->willReturn(false); $or = $this->orX($specification); - $or->shouldHaveType('Rb\Specification\OrX'); + $or->shouldHaveType(\Purist\Specification\OrX::class); $or->isSatisfiedBy('foo')->shouldReturn(true); } - public function it_should_return_not_specification(SpecificationInterface $specification) + public function it_should_return_not_specification(SpecificationInterface $specification): void { $specification->isSatisfiedBy('foo')->willReturn(true); $not = $this->not($specification); - $not->shouldHaveType('Rb\Specification\Not'); + $not->shouldHaveType(\Purist\Specification\Not::class); $not->isSatisfiedBy('foo')->shouldReturn(false); } } -class DummySpec extends CompositeSpecification +readonly class DummySpec extends CompositeSpecification { /** * {@inheritDoc} */ - public function isSatisfiedBy($value) + #[\Override] + public function isSatisfiedBy($value): bool { return $value === 'foo'; } diff --git a/spec/NotSpec.php b/spec/NotSpec.php index b3f385f..4cc34d3 100644 --- a/spec/NotSpec.php +++ b/spec/NotSpec.php @@ -1,24 +1,24 @@ beConstructedWith($specification); - $this->shouldHaveType('Rb\Specification\Not'); - $this->shouldHaveType('Rb\Specification\SpecificationInterface'); - $this->shouldHaveType('Rb\Specification\CompositeSpecification'); + $this->shouldHaveType(\Purist\Specification\Not::class); + $this->shouldHaveType(\Purist\Specification\SpecificationInterface::class); + $this->shouldHaveType(\Purist\Specification\CompositeSpecification::class); } - public function it_should_pass_if_child_fails(SpecificationInterface $specification) + public function it_should_pass_if_child_fails(SpecificationInterface $specification): void { $className = 'foo'; $this->beConstructedWith($specification); diff --git a/spec/OrXSpec.php b/spec/OrXSpec.php index 98fd4a0..429ad1b 100644 --- a/spec/OrXSpec.php +++ b/spec/OrXSpec.php @@ -1,13 +1,13 @@ beConstructedWith($specificationA, $specificationB); @@ -18,7 +18,7 @@ public function it_should_pass_if_one_child_fails(SpecificationInterface $specif $this->isSatisfiedBy($className)->shouldReturn(true); } - public function it_should_pass_if_both_children_pass(SpecificationInterface $specificationA, SpecificationInterface $specificationB) + public function it_should_pass_if_both_children_pass(SpecificationInterface $specificationA, SpecificationInterface $specificationB): void { $className = 'foo'; $this->beConstructedWith($specificationA, $specificationB); @@ -29,7 +29,7 @@ public function it_should_pass_if_both_children_pass(SpecificationInterface $spe $this->isSatisfiedBy($className)->shouldReturn(true); } - public function it_should_fail_if_both_children_fail(SpecificationInterface $specificationA, SpecificationInterface $specificationB) + public function it_should_fail_if_both_children_fail(SpecificationInterface $specificationA, SpecificationInterface $specificationB): void { $className = 'foo'; $this->beConstructedWith($specificationA, $specificationB); diff --git a/src/AndX.php b/src/AndX.php index 33f07a3..ebd09fa 100644 --- a/src/AndX.php +++ b/src/AndX.php @@ -1,35 +1,18 @@ x = $x; - $this->y = $y; } /** * {@inheritDoc} */ - public function isSatisfiedBy($value) + #[\Override] + public function isSatisfiedBy(mixed $value): bool { return $this->x->isSatisfiedBy($value) && $this->y->isSatisfiedBy($value); } diff --git a/src/CompositeSpecification.php b/src/CompositeSpecification.php index e8da66e..d8b3292 100644 --- a/src/CompositeSpecification.php +++ b/src/CompositeSpecification.php @@ -1,31 +1,23 @@ wrapped = $x; } /** * {@inheritDoc} */ - public function isSatisfiedBy($value) + #[\Override] + public function isSatisfiedBy(mixed $value): bool { return !$this->wrapped->isSatisfiedBy($value); } diff --git a/src/OrX.php b/src/OrX.php index 936c3b9..b289b3c 100644 --- a/src/OrX.php +++ b/src/OrX.php @@ -1,15 +1,18 @@ x->isSatisfiedBy($value) || $this->y->isSatisfiedBy($value); } diff --git a/src/SpecificationInterface.php b/src/SpecificationInterface.php index 054664f..315cc1f 100644 --- a/src/SpecificationInterface.php +++ b/src/SpecificationInterface.php @@ -1,17 +1,11 @@