-
Notifications
You must be signed in to change notification settings - Fork 0
/
Specifying.php
86 lines (69 loc) · 2.28 KB
/
Specifying.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
declare(strict_types = 1);
namespace Stratadox\Specification;
use Stratadox\Specification\Binary\AndSpecification;
use Stratadox\Specification\Binary\OrSpecification;
use Stratadox\Specification\Binary\XorSpecification;
use Stratadox\Specification\Contract\Satisfiable;
use Stratadox\Specification\Contract\Specifies;
use Stratadox\Specification\Unary\NotSpecification;
trait Specifying
{
/** @see Specifies::not() */
public function not() : Specifies
{
/** @var Specifying|Satisfiable $this */
return $this->doesNotSatisfy($this);
}
/** @see Specifies::and() */
public function and(Satisfiable $other) : Specifies
{
/** @var Specifying|Satisfiable $this */
return $this->satisfiesBoth($this, $other);
}
/** @see Specifies::or() */
public function or(Satisfiable $other) : Specifies
{
/** @var Specifying|Satisfiable $this */
return $this->oneOfThese($this, $other);
}
/** @see Specifies::xor() */
public function xor(Satisfiable $other) : Specifies
{
/** @var Specifying|Satisfiable $this */
return new XorSpecification($this, $other);
}
/** @see Specifies::nor() */
public function nor(Satisfiable $other) : Specifies
{
return $this->not()->andNot($other);
}
/** @see Specifies::andNot() */
public function andNot(Satisfiable $other) : Specifies
{
return $this->and($this->doesNotSatisfy($other));
}
/** @see Specifies::butNot() */
public function butNot(Satisfiable $other) : Specifies
{
return $this->andNot($other);
}
/** @see Specifies::orNot() */
public function orNot(Satisfiable $other) : Specifies
{
return $this->or($this->doesNotSatisfy($other));
}
// Private
private function doesNotSatisfy(Satisfiable $condition) : Specifies
{
return new NotSpecification($condition);
}
private function satisfiesBoth(Satisfiable $firstCondition, Satisfiable $secondCondition) : Specifies
{
return new AndSpecification($firstCondition, $secondCondition);
}
private function oneOfThese(Satisfiable $firstCondition, Satisfiable $secondCondition) : Specifies
{
return new OrSpecification($firstCondition, $secondCondition);
}
}