Specification   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 42
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A not() 0 3 1
A or() 0 3 1
A and() 0 3 1
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