Completed
Push — master ( ed931d...d2bebe )
by Pavel
02:45
created

AbstractCondition::match()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Bankiru\Seo\Entity;
4
5
use Bankiru\Seo\Exception\ConditionException;
6
use Bankiru\Seo\ConditionInterface;
7
use Bankiru\Seo\TargetDefinitionInterface;
8
9
abstract class AbstractCondition implements ConditionInterface
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $code;
15
16
    /**
17
     * @var TargetDefinitionInterface
18
     */
19
    protected $targetDefinition;
20
21 1
    public function attach(TargetDefinitionInterface $target, $code)
22
    {
23
        $this->code             = $code;
24
        $this->targetDefinition = $target;
25 1
        $this->targetDefinition->setCondition($this->code, $this);
26
    }
27
28 2
    public function match($object)
29
    {
30 2
        if (!$this->supports($object)) {
31 1
            throw ConditionException::unsupportedArgumentToMatch($this, $object);
32
        }
33
34 1
        return $this->doMatch($object);
35
    }
36
37
    /**
38
     * Checks whether the object is valid argument to perform matching
39
     *
40
     * @param mixed $object
41
     *
42
     * @return bool
43
     */
44
    abstract protected function supports($object);
45
46
    /**
47
     * Verify that object matches according to condition configuration
48
     *
49
     * @param $object
50
     *
51
     * @return int|null
52
     */
53
    abstract protected function doMatch($object);
54
}
55