Specifying::orNot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Stratadox\Specification;
6
7
use Stratadox\Specification\Binary\AndSpecification;
8
use Stratadox\Specification\Binary\OrSpecification;
9
use Stratadox\Specification\Binary\XorSpecification;
10
use Stratadox\Specification\Contract\Satisfiable;
11
use Stratadox\Specification\Contract\Specifies;
12
use Stratadox\Specification\Unary\NotSpecification;
13
14
trait Specifying
15
{
16
    /** @see Specifies::not() */
17
    public function not() : Specifies
18
    {
19
        /** @var Specifying|Satisfiable $this */
20
        return $this->doesNotSatisfy($this);
0 ignored issues
show
Bug introduced by
The method doesNotSatisfy() does not exist on Stratadox\Specification\Contract\Satisfiable. It seems like you code against a sub-type of Stratadox\Specification\Contract\Satisfiable such as Stratadox\Specification\Specification or Stratadox\Specification\Binary\BinarySpecification or Stratadox\Specification\Unary\UnarySpecification. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
        return $this->/** @scrutinizer ignore-call */ doesNotSatisfy($this);
Loading history...
Bug introduced by
It seems like $this can also be of type Stratadox\Specification\Specifying; however, parameter $condition of Stratadox\Specification\...fying::doesNotSatisfy() does only seem to accept Stratadox\Specification\Contract\Satisfiable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

20
        return $this->doesNotSatisfy(/** @scrutinizer ignore-type */ $this);
Loading history...
21
    }
22
23
    /** @see Specifies::and() */
24
    public function and(Satisfiable $other) : Specifies
25
    {
26
        /** @var Specifying|Satisfiable $this */
27
        return $this->satisfiesBoth($this, $other);
0 ignored issues
show
Bug introduced by
The method satisfiesBoth() does not exist on Stratadox\Specification\Contract\Satisfiable. It seems like you code against a sub-type of Stratadox\Specification\Contract\Satisfiable such as Stratadox\Specification\Specification or Stratadox\Specification\Binary\BinarySpecification or Stratadox\Specification\Unary\UnarySpecification. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
        return $this->/** @scrutinizer ignore-call */ satisfiesBoth($this, $other);
Loading history...
Bug introduced by
It seems like $this can also be of type Stratadox\Specification\Specifying; however, parameter $firstCondition of Stratadox\Specification\...ifying::satisfiesBoth() does only seem to accept Stratadox\Specification\Contract\Satisfiable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
        return $this->satisfiesBoth(/** @scrutinizer ignore-type */ $this, $other);
Loading history...
28
    }
29
30
    /** @see Specifies::or() */
31
    public function or(Satisfiable $other) : Specifies
32
    {
33
        /** @var Specifying|Satisfiable $this */
34
        return $this->oneOfThese($this, $other);
0 ignored issues
show
Bug introduced by
The method oneOfThese() does not exist on Stratadox\Specification\Contract\Satisfiable. It seems like you code against a sub-type of Stratadox\Specification\Contract\Satisfiable such as Stratadox\Specification\Specification or Stratadox\Specification\Binary\BinarySpecification or Stratadox\Specification\Unary\UnarySpecification. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
        return $this->/** @scrutinizer ignore-call */ oneOfThese($this, $other);
Loading history...
Bug introduced by
It seems like $this can also be of type Stratadox\Specification\Specifying; however, parameter $firstCondition of Stratadox\Specification\Specifying::oneOfThese() does only seem to accept Stratadox\Specification\Contract\Satisfiable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
        return $this->oneOfThese(/** @scrutinizer ignore-type */ $this, $other);
Loading history...
35
    }
36
37
    /** @see Specifies::xor() */
38
    public function xor(Satisfiable $other) : Specifies
39
    {
40
        /** @var Specifying|Satisfiable $this */
41
        return new XorSpecification($this, $other);
0 ignored issues
show
Bug introduced by
It seems like $this can also be of type Stratadox\Specification\Specifying; however, parameter $leftHandCondition of Stratadox\Specification\...fication::__construct() does only seem to accept Stratadox\Specification\Contract\Satisfiable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

41
        return new XorSpecification(/** @scrutinizer ignore-type */ $this, $other);
Loading history...
42
    }
43
44
    /** @see Specifies::nor() */
45
    public function nor(Satisfiable $other) : Specifies
46
    {
47
        return $this->not()->andNot($other);
48
    }
49
50
    /** @see Specifies::andNot() */
51
    public function andNot(Satisfiable $other) : Specifies
52
    {
53
        return $this->and($this->doesNotSatisfy($other));
54
    }
55
56
    /** @see Specifies::butNot() */
57
    public function butNot(Satisfiable $other) : Specifies
58
    {
59
        return $this->andNot($other);
60
    }
61
62
    /** @see Specifies::orNot() */
63
    public function orNot(Satisfiable $other) : Specifies
64
    {
65
        return $this->or($this->doesNotSatisfy($other));
66
    }
67
68
69
    // Private
70
71
72
    private function doesNotSatisfy(Satisfiable $condition) : Specifies
73
    {
74
        return new NotSpecification($condition);
75
    }
76
77
    private function satisfiesBoth(Satisfiable $firstCondition, Satisfiable $secondCondition) : Specifies
78
    {
79
        return new AndSpecification($firstCondition, $secondCondition);
80
    }
81
82
    private function oneOfThese(Satisfiable $firstCondition, Satisfiable $secondCondition) : Specifies
83
    {
84
        return new OrSpecification($firstCondition, $secondCondition);
85
    }
86
}
87