Completed
Push — master ( 5163d9...817b84 )
by Mike
07:06 queued 11s
created

canBeSatisfiedBySomethingBelow()   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
     */
28
    public function andSpecification(SpecificationInterface $other) : AndSpecification
29 1
    {
30
        return new AndSpecification($this, $other);
31
    }
32
33
    /**
34
     * Returns a specification that satisfies the original specification
35
     * or the other specification
36 1
     */
37
    public function orSpecification(SpecificationInterface $other) : OrSpecification
38 1
    {
39
        return new OrSpecification($this, $other);
40
    }
41
42
    /**
43
     * Returns a specification that is the inverse of the original specification
44
     * i.e. does not meet the original criteria
45 1
     */
46
    public function notSpecification() : NotSpecification
47 1
    {
48
        return new NotSpecification($this);
49
    }
50
51
    /** {@inheritDoc} */
52
    public function canBeSatisfiedBySomethingBelow(array $value) : bool
53
    {
54
        return true;
55
    }
56
57
    /** {@inheritDoc} */
58
    public function willBeSatisfiedByEverythingBelow(array $value) : bool
59
    {
60
        return false;
61
    }
62
63
    /**
64
     * Provide default {@see canBeSatisfiedBySomethingBelow()} logic for specification classes
65
     * that don't implement PrunableInterface
66
     *
67
     * @param mixed[] $value
68
     *
69
     * @psalm-param array{basename: string, path: string, stream: resource, dirname: string, type: string, extension: string} $value
70
     * @psalm-mutation-free
71
     */
72
    public static function thatCanBeSatisfiedBySomethingBelow(SpecificationInterface $that, array $value) : bool
73
    {
74
        return $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
     * @param mixed[] $value
84
     *
85
     * @psalm-param array{basename: string, path: string, stream: resource, dirname: string, type: string, extension: string} $value
86
     * @psalm-mutation-free
87
     */
88
    public static function thatWillBeSatisfiedByEverythingBelow(SpecificationInterface $that, array $value) : bool
89
    {
90
        return $that instanceof PrunableInterface
91
            && $that->willBeSatisfiedByEverythingBelow($value);
92
    }
93
}
94