ExactCondition::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Bankiru\Seo\Integration\Local;
4
5
use Bankiru\Seo\ConditionInterface;
6
use Bankiru\Seo\TargetDefinitionInterface;
7
8
final class ExactCondition implements ConditionInterface
9
{
10
    /** @var mixed */
11
    private $value;
12
    /** @var bool */
13
    private $strict = true;
14
15
    /**
16
     * ExactCondition constructor.
17
     *
18
     * @param mixed $value
19
     * @param bool  $strict
20
     */
21 1
    public function __construct($value, $strict = true)
22
    {
23 1
        $this->value  = $value;
24 1
        $this->strict = $strict;
25 1
    }
26
27
    /** {@inheritdoc} */
28
    public function attach(TargetDefinitionInterface $target, $code)
29
    {
30
        $target->setCondition($code, $this);
31
    }
32
33
    /** {@inheritdoc} */
34 5
    public function match($object)
35
    {
36
        /** @noinspection TypeUnsafeComparisonInspection */
37 5
        return $this->doMatch($object) ? 1 : null;
38
    }
39
40
    /**
41
     * @param $object
42
     *
43
     * @return bool
44
     */
45 5
    private function doMatch($object)
46
    {
47 5
        return $this->strict ? $object === $this->value : $object == $this->value;
48
    }
49
}
50