Passed
Push — master ( 71cd79...3a5308 )
by Vincent
02:53 queued 20s
created

AbstractConstraint::setConstraint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace VGirol\JsonApiAssert\Constraint;
5
6
use PHPUnit\Framework\Constraint\Constraint;
7
8
/**
9
 * Abstract constraint class
10
 */
11
abstract class AbstractConstraint extends Constraint implements ConstraintContract
12
{
13
    /**
14
     * The JsonApi-Structure constraint used to make the tests
15
     *
16
     * @var \VGirol\JsonApiStructure\Constraint\Constraint
17
     */
18
    private $constraint;
19
20
    /**
21
     * Returns a string representation of the constraint.
22
     *
23
     * @return string
24
     */
25 30
    public function toString(): string
26
    {
27 30
        return $this->constraint->toString();
28
    }
29
30
    /**
31
     * Evaluates the constraint for parameter $other. Returns true if the constraint is met, false otherwise.
32
     *
33
     * @param mixed $other value or object to evaluate
34
     *
35
     * @return boolean
36
     */
37 51
    public function check($other): bool
38
    {
39 51
        return $this->matches($other);
40
    }
41
42
    /**
43
     * Evaluates the constraint for parameter $other. Returns true if the constraint is met, false otherwise.
44
     *
45
     * @param mixed $other value or object to evaluate
46
     *
47
     * @return bool
48
     */
49 48
    protected function matches($other): bool
50
    {
51 48
        return $this->constraint->handle($other);
52
    }
53
54
    /**
55
     * Undocumented function
56
     *
57
     * @param \VGirol\JsonApiStructure\Constraint\Constraint $constraint
58
     *
59
     * @return void
60
     */
61 51
    protected function setConstraint($constraint): void
62
    {
63 51
        $this->constraint = $constraint;
64 51
    }
65
}
66