Skip to content

Commit

Permalink
Update to PHP 8.2, namespace and add author
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasruunu committed Jun 18, 2024
1 parent ba6dcfd commit 73fc505
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 180 deletions.
1 change: 0 additions & 1 deletion .coveralls.yml

This file was deleted.

28 changes: 0 additions & 28 deletions .travis.yml

This file was deleted.

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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

Expand Down
18 changes: 10 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
{
"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"
}
],
"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": {
Expand Down
15 changes: 2 additions & 13 deletions phpspec.yml.dist
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use Rector\Config\RectorConfig;
use Rector\Doctrine\Set\DoctrineSetList;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector;

return RectorConfig::configure()->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,
);
10 changes: 5 additions & 5 deletions spec/AndXSpec.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace spec\Rb\Specification;
namespace spec\Purist\Specification;

use PhpSpec\ObjectBehavior;
use Rb\Specification\SpecificationInterface;
use Purist\Specification\SpecificationInterface;

class AndXSpec extends ObjectBehavior
{
public function it_should_fail_if_one_child_fails(SpecificationInterface $specificationA, SpecificationInterface $specificationB)
public function it_should_fail_if_one_child_fails(SpecificationInterface $specificationA, SpecificationInterface $specificationB): void
{
$className = 'foo';
$this->beConstructedWith($specificationA, $specificationB);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
37 changes: 19 additions & 18 deletions spec/CompositeSpecificationSpec.php
Original file line number Diff line number Diff line change
@@ -1,60 +1,61 @@
<?php

namespace spec\Rb\Specification;
namespace spec\Purist\Specification;

use PhpSpec\ObjectBehavior;
use Rb\Specification\AndX;
use Rb\Specification\CompositeSpecification;
use Rb\Specification\Not;
use Rb\Specification\OrX;
use Rb\Specification\SpecificationInterface;
use Purist\Specification\AndX;
use Purist\Specification\CompositeSpecification;
use Purist\Specification\Not;
use Purist\Specification\OrX;
use Purist\Specification\SpecificationInterface;

class CompositeSpecificationSpec extends ObjectBehavior
{
public function let()
public function let(): void
{
$this->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';
}
Expand Down
18 changes: 9 additions & 9 deletions spec/NotSpec.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?php

namespace spec\Rb\Specification;
namespace spec\Purist\Specification;

use PhpSpec\ObjectBehavior;
use Rb\Specification\CompositeSpecification;
use Rb\Specification\Not;
use Rb\Specification\SpecificationInterface;
use Purist\Specification\CompositeSpecification;
use Purist\Specification\Not;
use Purist\Specification\SpecificationInterface;

class NotSpec extends ObjectBehavior
{
public function it_should_have_correct_types(SpecificationInterface $specification)
public function it_should_have_correct_types(SpecificationInterface $specification): void
{
$this->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);
Expand Down
10 changes: 5 additions & 5 deletions spec/OrXSpec.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace spec\Rb\Specification;
namespace spec\Purist\Specification;

use PhpSpec\ObjectBehavior;
use Rb\Specification\SpecificationInterface;
use Purist\Specification\SpecificationInterface;

class OrXSpec extends ObjectBehavior
{
public function it_should_pass_if_one_child_fails(SpecificationInterface $specificationA, SpecificationInterface $specificationB)
public function it_should_pass_if_one_child_fails(SpecificationInterface $specificationA, SpecificationInterface $specificationB): void
{
$className = 'foo';
$this->beConstructedWith($specificationA, $specificationB);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
27 changes: 5 additions & 22 deletions src/AndX.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
<?php

namespace Rb\Specification;
namespace Purist\Specification;

/**
*/
class AndX extends CompositeSpecification
readonly final class AndX extends CompositeSpecification
{
/**
* @var SpecificationInterface
*/
protected $x;

/**
* @var SpecificationInterface
*/
protected $y;

/**
* @param SpecificationInterface $x
* @param SpecificationInterface $y
*/
public function __construct(SpecificationInterface $x, SpecificationInterface $y)
public function __construct(private SpecificationInterface $x, private SpecificationInterface $y)
{
$this->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);
}
Expand Down
Loading

0 comments on commit 73fc505

Please sign in to comment.