Specification::or()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Anfischer\Specification;
5
6
abstract class Specification
7
{
8
    /**
9
     * Abstract implementation of isSatisfiedBy.
10
     * Subclasses will use this method to implement their
11
     * own contract for validation logic.
12
     *
13
     * @param mixed $object
14
     * @return bool
15
     */
16
    abstract public function isSatisfiedBy($object): bool;
17
18
    /**
19
     * Method to allow for chaining specifications which must all satisfy
20
     *
21
     * @param Specification $specification
22
     * @return AndSpecification
23
     */
24 2
    public function and(Specification $specification): AndSpecification
25
    {
26 2
        return new AndSpecification($this, $specification);
27
    }
28
29
    /**
30
     * Method to allow for chaining specifications where at least one must satisfy
31
     *
32
     * @param Specification $specification
33
     * @return OrSpecification
34
     */
35 2
    public function or(Specification $specification): OrSpecification
36
    {
37 2
        return new OrSpecification($this, $specification);
38
    }
39
40
    /**
41
     * Method to allow for negation of a specification by forcing it to not satisfy
42
     *
43
     * @return NotSpecification
44
     */
45 4
    public function not(): NotSpecification
46
    {
47 4
        return new NotSpecification($this);
48
    }
49
}
50