Skip to content

Commit b0d519c

Browse files
authored
Merge pull request #8 from maartenpaauw/develop
2 parents 6886fb7 + ccf8d28 commit b0d519c

22 files changed

+177
-64
lines changed

.github/dependabot.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
1-
# Please see the documentation for all configuration options:
2-
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
3-
41
version: 2
2+
53
updates:
4+
- package-ecosystem: "composer"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"
8+
day: "monday"
9+
time: "07:00"
10+
timezone: "Europe/Amsterdam"
11+
labels:
12+
- "dependencies"
13+
- "composer"
14+
assignees:
15+
- "maartenpaauw"
16+
reviewers:
17+
- "maartenpaauw"
618

719
- package-ecosystem: "github-actions"
820
directory: "/"
921
schedule:
1022
interval: "weekly"
23+
day: "monday"
24+
time: "07:00"
25+
timezone: "Europe/Amsterdam"
1126
labels:
12-
- "dependencies"
27+
- "dependencies"
28+
- "github-actions"
29+
assignees:
30+
- "maartenpaauw"
31+
reviewers:
32+
- "maarten"

.github/workflows/code-coverage.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: code-coverage
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
- main
8+
pull_request:
9+
branches:
10+
- develop
11+
- main
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
name: Code coverage
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v3
21+
22+
- name: Setup PHP
23+
uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: 8.1
26+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
27+
coverage: xdebug
28+
29+
- name: Setup problem matchers
30+
run: |
31+
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
32+
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
33+
34+
- name: Install dependencies
35+
run: composer install --prefer-dist --no-interaction
36+
37+
- name: Execute tests
38+
run: vendor/bin/pest --coverage --coverage-clover coverage.xml
39+
40+
- name: Upload coverage report
41+
uses: codecov/codecov-action@v3
42+
with:
43+
files: coverage.xml
44+
fail_ci_if_error: true

.github/workflows/php-cs-fixer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88

99
steps:
1010
- name: Checkout code
11-
uses: actions/checkout@v2
11+
uses: actions/checkout@v3
1212
with:
1313
ref: ${{ github.head_ref }}
1414

.github/workflows/phpstan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
name: phpstan
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v3
1515

1616
- name: Setup PHP
1717
uses: shivammathur/setup-php@v2

.github/workflows/run-tests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ jobs:
1313
fail-fast: true
1414
matrix:
1515
os: [ubuntu-latest, windows-latest]
16-
php: [8.0, 8.1]
17-
laravel: [8.*, 9.*]
16+
php: [8.1, 8.2]
17+
laravel: [9.*, 10.*]
1818
stability: [prefer-lowest, prefer-stable]
1919
include:
20-
- laravel: 8.*
21-
testbench: ^6.23
2220
- laravel: 9.*
2321
testbench: ^7.1
22+
- laravel: 10.*
23+
testbench: ^8.0.10
2424

2525
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
2626

2727
steps:
2828
- name: Checkout code
29-
uses: actions/checkout@v2
29+
uses: actions/checkout@v3
3030

3131
- name: Setup PHP
3232
uses: shivammathur/setup-php@v2

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ testbench.yaml
1212
vendor
1313
node_modules
1414
.php-cs-fixer.cache
15+
coverage.xml

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22

33
All notable changes to `laravel-specification-pattern` will be documented in this file.
44

5+
## [v2.0.0] - 2023-03-21
6+
7+
### Added
8+
9+
- Support from Laravel 10.
10+
11+
### Changed
12+
13+
- Renamed `SpecificationException` to `DissatisfiedSpecification` and extend from `DomainException`.
14+
- Marked the following classes as final:
15+
- `AndSpecification`.
16+
- `NotSpecification`.
17+
- `OrSpecification`.
18+
- `VerboseSpecification`.
19+
20+
### Removed
21+
22+
- Support for PHP 8.
23+
- Support for Laravel 8.
24+
525
## [v1.1.0] - 2022-03-07
626

727
### Added
@@ -12,5 +32,6 @@ All notable changes to `laravel-specification-pattern` will be documented in thi
1232

1333
- initial release
1434

35+
[v2.0.0]: https://github.com/maartenpaauw/laravel-specification-pattern/compare/v1.1.0...v2.0.0
1536
[v1.1.0]: https://github.com/maartenpaauw/laravel-specification-pattern/compare/v1.0.0...v1.1.0
1637
[v1.0.0]: https://github.com/maartenpaauw/laravel-specification-pattern/releases/tag/v1.0.0

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Laravel specification pattern
22

33
[![Latest Version on Packagist](https://img.shields.io/packagist/v/maartenpaauw/laravel-specification-pattern.svg?style=flat-square)](https://packagist.org/packages/maartenpaauw/laravel-specification-pattern)
4-
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/maartenpaauw/laravel-specification-pattern/run-tests?label=tests)](https://github.com/maartenpaauw/laravel-specification-pattern/actions?query=workflow%3Arun-tests+branch%3Amain)
5-
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/maartenpaauw/laravel-specification-pattern/Check%20&%20fix%20styling?label=code%20style)](https://github.com/maartenpaauw/laravel-specification-pattern/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
4+
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/maartenpaauw/laravel-specification-pattern/run-tests.yml?label=tests)](https://github.com/maartenpaauw/laravel-specification-pattern/actions?query=workflow%3Arun-tests+branch%3Amain)
5+
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/maartenpaauw/laravel-specification-pattern/php-cs-fixer.yml?label=code%20style)](https://github.com/maartenpaauw/laravel-specification-pattern/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
6+
[![Codecov](https://codecov.io/gh/maartenpaauw/laravel-specification-pattern/branch/develop/graph/badge.svg?token=YM9A0DUA4R)](https://codecov.io/gh/maartenpaauw/laravel-specification-pattern)
67
[![Total Downloads](https://img.shields.io/packagist/dt/maartenpaauw/laravel-specification-pattern.svg?style=flat-square)](https://packagist.org/packages/maartenpaauw/laravel-specification-pattern)
78

89
Filter an Illuminate collection with specifications.

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
"require": {
1919
"php": "^8.0",
2020
"spatie/laravel-package-tools": "^1.9.2",
21-
"illuminate/contracts": "^8.83|^9.2"
21+
"illuminate/contracts": "^9.33|^10.4"
2222
},
2323
"require-dev": {
2424
"nunomaduro/collision": "^5.11|^6.1",
25-
"nunomaduro/larastan": "^1.0",
26-
"orchestra/testbench": "^6.22",
25+
"nunomaduro/larastan": "^1.0|^2.1",
26+
"orchestra/testbench": "^6.22|^7.0",
2727
"pestphp/pest": "^1.21",
2828
"pestphp/pest-plugin-laravel": "^1.1",
2929
"phpstan/extension-installer": "^1.1",
@@ -46,7 +46,7 @@
4646
"scripts": {
4747
"analyse": "vendor/bin/phpstan analyse",
4848
"test": "vendor/bin/pest",
49-
"test-coverage": "vendor/bin/pest coverage"
49+
"test-coverage": "vendor/bin/pest --coverage"
5050
},
5151
"config": {
5252
"sort-packages": true,

config/specification-pattern.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
return [
46
'collection-method' => 'matching',
57
];

src/AndSpecification.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,19 @@
66

77
/**
88
* @template TCandidate
9+
*
910
* @extends CompositeSpecification<TCandidate>
1011
*/
11-
class AndSpecification extends CompositeSpecification
12+
final class AndSpecification extends CompositeSpecification
1213
{
1314
/**
14-
* @param array<Specification<TCandidate>> $specifications
15+
* @param array<array-key, Specification<TCandidate>> $specifications
1516
*/
1617
public function __construct(
1718
private array $specifications,
1819
) {
1920
}
2021

21-
/**
22-
* @inheritDoc
23-
*/
2422
public function isSatisfiedBy(mixed $candidate): bool
2523
{
2624
foreach ($this->specifications as $specification) {

src/Commands/MakeSpecificationCommand.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,47 @@
77
use Illuminate\Console\GeneratorCommand;
88
use Symfony\Component\Console\Input\InputOption;
99

10-
class MakeSpecificationCommand extends GeneratorCommand
10+
final class MakeSpecificationCommand extends GeneratorCommand
1111
{
12-
public $name = 'make:specification';
13-
14-
public $description = 'Create a new specification class';
15-
12+
/**
13+
* @var string
14+
*/
15+
protected $name = 'make:specification';
16+
17+
/**
18+
* @var string
19+
*/
20+
protected $description = 'Create a new specification class';
21+
22+
/**
23+
* @var string
24+
*/
1625
protected $type = 'Specification';
1726

1827
protected function getStub(): string
1928
{
2029
if ($this->option('composite')) {
21-
return $this->resolveStubPath('/stubs/specification-composite.stub');
30+
return $this->resolveStubPath(
31+
'/stubs/specification-composite.stub',
32+
);
2233
}
2334

24-
return $this->resolveStubPath('/stubs/specification.stub');
35+
return $this->resolveStubPath(
36+
'/stubs/specification.stub',
37+
);
2538
}
2639

40+
/**
41+
* @inheritDoc
42+
*/
2743
protected function getDefaultNamespace($rootNamespace): string
2844
{
2945
return sprintf('%s\Specifications', $rootNamespace);
3046
}
3147

48+
/**
49+
* @inheritDoc
50+
*/
3251
protected function buildClass($name): string
3352
{
3453
$replacements = [
@@ -42,6 +61,9 @@ protected function buildClass($name): string
4261
);
4362
}
4463

64+
/**
65+
* @return array<int, InputOption>
66+
*/
4567
protected function getOptions(): array
4668
{
4769
$composite = new InputOption(

src/CompositeSpecification.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
/**
88
* @template TCandidate
9+
*
910
* @implements Specification<TCandidate>
1011
*/
1112
abstract class CompositeSpecification implements Specification

src/DissatisfiedSpecification.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Maartenpaauw\Specifications;
6+
7+
use DomainException;
8+
9+
final class DissatisfiedSpecification extends DomainException
10+
{
11+
}

src/Laravel/CollectionMatchingMacro.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@
99
use Maartenpaauw\Specifications\Specification;
1010

1111
/**
12-
* @mixin Collection
12+
* @template TKey of array-key
13+
* @template TValue
14+
*
15+
* @mixin Collection<TKey, TValue>
1316
*/
14-
class CollectionMatchingMacro
17+
final class CollectionMatchingMacro
1518
{
1619
public function __invoke(): Closure
1720
{
1821
return function (Specification $specification) {
19-
return $this->filter(static function ($candidate) use ($specification): bool {
20-
return $specification->isSatisfiedBy($candidate);
21-
});
22+
return $this->filter(
23+
static function ($candidate) use ($specification): bool {
24+
return $specification->isSatisfiedBy($candidate);
25+
},
26+
);
2227
};
2328
}
2429
}

src/NotSpecification.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
/**
88
* @template TCandidate
9+
*
910
* @extends CompositeSpecification<TCandidate>
1011
*/
11-
class NotSpecification extends CompositeSpecification
12+
final class NotSpecification extends CompositeSpecification
1213
{
1314
/**
1415
* @param Specification<TCandidate> $specification
@@ -18,9 +19,6 @@ public function __construct(
1819
) {
1920
}
2021

21-
/**
22-
* @inheritDoc
23-
*/
2422
public function isSatisfiedBy(mixed $candidate): bool
2523
{
2624
return ! $this->specification->isSatisfiedBy($candidate);

src/OrSpecification.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,19 @@
66

77
/**
88
* @template TCandidate
9+
*
910
* @extends CompositeSpecification<TCandidate>
1011
*/
11-
class OrSpecification extends CompositeSpecification
12+
final class OrSpecification extends CompositeSpecification
1213
{
1314
/**
14-
* @param array<Specification<TCandidate>> $specifications
15+
* @param array<array-key, Specification<TCandidate>> $specifications
1516
*/
1617
public function __construct(
1718
private array $specifications,
1819
) {
1920
}
2021

21-
/**
22-
* @inheritDoc
23-
*/
2422
public function isSatisfiedBy(mixed $candidate): bool
2523
{
2624
foreach ($this->specifications as $specification) {

0 commit comments

Comments
 (0)