Skip to content

Commit e629d17

Browse files
authored
Merge pull request #3 from Bocmah/master
Remove unused dependency on doctrine/common
2 parents 42793ec + 9da6584 commit e629d17

9 files changed

Lines changed: 73 additions & 75 deletions

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
}
1313
],
1414
"require": {
15-
"php": ">=7.0",
16-
"doctrine/common": "^2.8"
15+
"php": ">=7.0"
1716
},
1817
"require-dev": {
1918
"phpunit/phpunit": "^6.4",

src/AndSpecification.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@
22

33
namespace Tanigami\Specification;
44

5+
/**
6+
* @template T
7+
* @extends Specification<T>
8+
*/
59
class AndSpecification extends Specification
610
{
711
/**
8-
* @var Specification
12+
* @var Specification<T>
913
*/
1014
private $one;
1115

1216
/**
13-
* @var Specification
17+
* @var Specification<T>
1418
*/
1519
private $other;
1620

1721
/**
18-
* @param Specification $one
19-
* @param Specification $other
22+
* @param Specification<T> $one
23+
* @param Specification<T> $other
2024
*/
2125
public function __construct(Specification $one, Specification $other)
2226
{
@@ -25,37 +29,32 @@ public function __construct(Specification $one, Specification $other)
2529
}
2630

2731
/**
28-
* {@inheritdoc}
32+
* @param T $object
2933
*/
3034
public function isSatisfiedBy($object): bool
3135
{
3236
return $this->one->isSatisfiedBy($object) && $this->other->isSatisfiedBy($object);
3337
}
3438

35-
/**
36-
* {@inheritdoc}
37-
*/
3839
public function whereExpression(string $alias): string
3940
{
4041
return sprintf(
41-
sprintf(
42-
'(%s) AND (%s)',
43-
$this->one()->whereExpression($alias),
44-
$this->other()->whereExpression($alias)
45-
)
42+
'(%s) AND (%s)',
43+
$this->one()->whereExpression($alias),
44+
$this->other()->whereExpression($alias)
4645
);
4746
}
4847

4948
/**
50-
* @return Specification
49+
* @return Specification<T>
5150
*/
5251
public function one(): Specification
5352
{
5453
return $this->one;
5554
}
5655

5756
/**
58-
* @return Specification
57+
* @return Specification<T>
5958
*/
6059
public function other(): Specification
6160
{

src/AnyOfSpecification.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@
22

33
namespace Tanigami\Specification;
44

5+
/**
6+
* @template T
7+
* @extends Specification<T>
8+
*/
59
class AnyOfSpecification extends Specification
610
{
711
/**
8-
* @var Specification[]
12+
* @var Specification<T>[]
913
*/
1014
private $specifications;
1115

1216
/**
13-
* @param Specification[] ...$specifications
17+
* @param Specification<T> ...$specifications
1418
*/
1519
public function __construct(Specification ...$specifications)
1620
{
1721
$this->specifications = $specifications;
1822
}
1923

2024
/**
21-
* {@inheritdoc}
25+
* @param T $object
2226
*/
2327
public function isSatisfiedBy($object): bool
2428
{
@@ -31,21 +35,18 @@ public function isSatisfiedBy($object): bool
3135
return true;
3236
}
3337

34-
/**
35-
* {@inheritdoc}
36-
*/
3738
public function whereExpression(string $alias): string
3839
{
3940
return implode(' AND ', array_map(
40-
function (Specification $specification) use ($alias) {
41+
static function (Specification $specification) use ($alias) {
4142
return '(' . $specification->whereExpression($alias) . ')';
4243
},
4344
$this->specifications
4445
));
4546
}
4647

4748
/**
48-
* @return Specification[]
49+
* @return Specification<T>[]
4950
*/
5051
public function specifications(): array
5152
{

src/NoneOfSpecification.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@
22

33
namespace Tanigami\Specification;
44

5+
/**
6+
* @template T
7+
* @extends Specification<T>
8+
*/
59
class NoneOfSpecification extends Specification
610
{
711
/**
8-
* @var Specification[]
12+
* @var Specification<T>[]
913
*/
1014
private $specifications;
1115

1216
/**
13-
* @param Specification[] ...$specifications
17+
* @param Specification<T> ...$specifications
1418
*/
1519
public function __construct(Specification ...$specifications)
1620
{
1721
$this->specifications = $specifications;
1822
}
1923

2024
/**
21-
* {@inheritdoc}
25+
* @param T $object
2226
*/
2327
public function isSatisfiedBy($object): bool
2428
{
@@ -32,10 +36,10 @@ public function isSatisfiedBy($object): bool
3236
}
3337

3438
/**
35-
* @return Specification[]
39+
* @return Specification<T>[]
3640
*/
3741
public function specifications(): array
3842
{
39-
return $this->specifications();
43+
return $this->specifications;
4044
}
4145
}

src/NotSpecification.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,35 @@
22

33
namespace Tanigami\Specification;
44

5+
/**
6+
* @template T
7+
* @extends Specification<T>
8+
*/
59
class NotSpecification extends Specification
610
{
711
/**
8-
* @var Specification
12+
* @var Specification<T>
913
*/
1014
private $specification;
1115

1216
/**
13-
* @param Specification $specification
17+
* @param Specification<T> $specification
1418
*/
1519
public function __construct(Specification $specification)
1620
{
1721
$this->specification = $specification;
1822
}
1923

2024
/**
21-
* @param mixed $object
22-
* @return bool
25+
* @param T $object
2326
*/
2427
public function isSatisfiedBy($object): bool
2528
{
2629
return !$this->specification->isSatisfiedBy($object);
2730
}
2831

2932
/**
30-
* @return Specification
33+
* @return Specification<T>
3134
*/
3235
public function specification(): Specification
3336
{

src/OneOfSpecification.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@
22

33
namespace Tanigami\Specification;
44

5+
/**
6+
* @template T
7+
* @extends Specification<T>
8+
*/
59
class OneOfSpecification extends Specification
610
{
711
/**
8-
* @var Specification[]
12+
* @var Specification<T>[]
913
*/
1014
private $specifications;
1115

1216
/**
13-
* @param Specification[] ...$specifications
17+
* @param Specification<T> ...$specifications
1418
*/
1519
public function __construct(Specification ...$specifications)
1620
{
1721
$this->specifications = $specifications;
1822
}
1923

2024
/**
21-
* {@inheritdoc}
25+
* @param T $object
2226
*/
2327
public function isSatisfiedBy($object): bool
2428
{
@@ -31,21 +35,18 @@ public function isSatisfiedBy($object): bool
3135
return false;
3236
}
3337

34-
/**
35-
* {@inheritdoc}
36-
*/
3738
public function whereExpression(string $alias): string
3839
{
3940
return implode(' OR ', array_map(
40-
function (Specification $specification) use ($alias) {
41+
static function (Specification $specification) use ($alias) {
4142
return '(' . $specification->whereExpression($alias) . ')';
4243
},
4344
$this->specifications
4445
));
4546
}
4647

4748
/**
48-
* @return Specification[]
49+
* @return Specification<T>[]
4950
*/
5051
public function specifications(): array
5152
{

src/OrSpecification.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@
22

33
namespace Tanigami\Specification;
44

5+
/**
6+
* @template T
7+
* @extends Specification<T>
8+
*/
59
class OrSpecification extends Specification
610
{
711
/**
8-
* @var Specification
12+
* @var Specification<T>
913
*/
1014
private $one;
1115

1216
/**
13-
* @var Specification
17+
* @var Specification<T>
1418
*/
1519
private $other;
1620

1721
/**
18-
* @param Specification $one
19-
* @param Specification $other
22+
* @param Specification<T> $one
23+
* @param Specification<T> $other
2024
*/
2125
public function __construct(Specification $one, Specification $other)
2226
{
@@ -25,37 +29,32 @@ public function __construct(Specification $one, Specification $other)
2529
}
2630

2731
/**
28-
* {@inheritdoc}
32+
* @param T $object
2933
*/
3034
public function isSatisfiedBy($object): bool
3135
{
3236
return $this->one->isSatisfiedBy($object) || $this->other->isSatisfiedBy($object);
3337
}
3438

35-
/**
36-
* {@inheritdoc}
37-
*/
3839
public function whereExpression(string $alias): string
3940
{
4041
return sprintf(
41-
sprintf(
42-
'(%s) OR (%s)',
43-
$this->one()->whereExpression($alias),
44-
$this->other()->whereExpression($alias)
45-
)
42+
'(%s) OR (%s)',
43+
$this->one()->whereExpression($alias),
44+
$this->other()->whereExpression($alias)
4645
);
4746
}
4847

4948
/**
50-
* @return Specification
49+
* @return Specification<T>
5150
*/
5251
public function one(): Specification
5352
{
5453
return $this->one;
5554
}
5655

5756
/**
58-
* @return Specification
57+
* @return Specification<T>
5958
*/
6059
public function other(): Specification
6160
{

0 commit comments

Comments
 (0)