AbstractCondition::getTarget()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Bankiru\Seo\Entity;
4
5
use Bankiru\Seo\ConditionInterface;
6
use Bankiru\Seo\Exception\ConditionException;
7
use Bankiru\Seo\TargetDefinitionInterface;
8
9
abstract class AbstractCondition implements ConditionInterface
10
{
11
    /**
12
     * @var string
13
     */
14
    private $code;
15
16
    /**
17
     * @var TargetDefinitionInterface
18
     */
19
    protected $target;
20
21
    /**
22
     * AbstractCondition constructor.
23
     *
24
     * @param string                    $code
25
     * @param TargetDefinitionInterface $target
26
     */
27 2
    public function __construct($code, TargetDefinitionInterface $target)
28
    {
29 2
        $this->code   = $code;
30 2
        $this->target = $target;
31 2
    }
32
33
    /** {@inheritdoc} */
34
    public function attach(TargetDefinitionInterface $target, $code)
35
    {
36
        $this->code   = $code;
37
        $this->target = $target;
38
        $this->target->setCondition($this->code, $this);
39
    }
40
41
    /** {@inheritdoc} */
42 3
    public function match($object)
43
    {
44 3
        if (!$this->supports($object)) {
45 1
            throw ConditionException::unsupportedArgumentToMatch($this, $object);
46
        }
47
48 2
        return $this->doMatch($object);
49
    }
50
51
    /**
52
     * @return string
53
     */
54
    public function getCode()
55
    {
56
        return $this->code;
57
    }
58
59
    /**
60
     * @return TargetDefinitionInterface
61
     */
62
    public function getTarget()
63
    {
64
        return $this->target;
65
    }
66
67
    /**
68
     * Checks whether the object is valid argument to perform matching
69
     *
70
     * @param mixed $object
71
     *
72
     * @return bool
73
     */
74
    abstract protected function supports($object);
75
76
    /**
77
     * Verify that object matches according to condition configuration
78
     *
79
     * @param $object
80
     *
81
     * @return int|null
82
     */
83
    abstract protected function doMatch($object);
84
}
85