Completed
Pull Request — master (#15)
by
unknown
03:57
created

thatCanBeSatisfiedByAnythingBelow()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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