Completed
Pull Request — master (#15)
by
unknown
08:21
created

willBeSatisfiedByEverythingBelow()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of phpDocumentor.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @link      http://phpdoc.org
12
 */
13
14
namespace Flyfinder\Specification;
15
16
/**
17
 * Class CompositeSpecification
18
 * Base class for specifications, allows for combining specifications
19
 *
20
 * @psalm-immutable
21
 */
22
abstract class CompositeSpecification implements SpecificationInterface, PrunableInterface
23
{
24
    /**
25
     * Returns a specification that satisfies the original specification
26
     * as well as the other specification
27 1
     * @param SpecificationInterface $other
28
     * @return AndSpecification
29 1
     */
30
    public function andSpecification(SpecificationInterface $other) : AndSpecification
31
    {
32
        return new AndSpecification($this, $other);
33
    }
34
35
    /**
36 1
     * Returns a specification that satisfies the original specification
37
     * or the other specification
38 1
     * @param SpecificationInterface $other
39
     * @return OrSpecification
40
     */
41
    public function orSpecification(SpecificationInterface $other) : OrSpecification
42
    {
43
        return new OrSpecification($this, $other);
44
    }
45 1
46
    /**
47 1
     * Returns a specification that is the inverse of the original specification
48
     * i.e. does not meet the original criteria
49
     */
50
    public function notSpecification() : NotSpecification
51
    {
52
        return new NotSpecification($this);
53
    }
54
55
    /** {@inheritDoc} */
56
    public function canBeSatisfiedBySomethingBelow(array $value): bool
57
    {
58
        return true;
59
    }
60
61
    /** {@inheritDoc} */
62
    public function willBeSatisfiedByEverythingBelow(array $value): bool
63
    {
64
        return false;
65
    }
66
67
    /**
68
     * Provide default {@see canBeSatisfiedBySomethingBelow()} logic for specification classes
69
     * that don't implement PrunableInterface
70
     */
71
    public static function thatCanBeSatisfiedBySomethingBelow(SpecificationInterface $that, array $value): bool
72
    {
73
        return
74
            $that instanceof PrunableInterface
75
                ? $that->canBeSatisfiedBySomethingBelow($value)
76
                : true;
77
    }
78
79
    /**
80
     * Provide default {@see willBeSatisfiedByEverythingBelow()} logic for specification classes
81
     * that don't implement PrunableInterface
82
     */
83
    public static function thatWillBeSatisfiedByEverythingBelow(SpecificationInterface $that, array $value): bool
84
    {
85
        return
86
            $that instanceof PrunableInterface
87
            && $that->willBeSatisfiedByEverythingBelow($value);
88
    }
89
}
90