Completed
Push — master ( 0148b2...8b8c0c )
by Pavel
03:00 queued 17s
created

CallbackCondition   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 62.5%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 27
ccs 5
cts 8
cp 0.625
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A attach() 0 4 1
A match() 0 4 2
1
<?php
2
3
namespace Bankiru\Seo\Integration\Local;
4
5
use Bankiru\Seo\ConditionInterface;
6
use Bankiru\Seo\TargetDefinitionInterface;
7
8
final class CallbackCondition implements ConditionInterface
9
{
10
    /** @var callable */
11
    private $callback;
12
13
    /**
14
     * CallbackCondition constructor.
15
     *
16
     * @param callable $callback
17
     */
18 1
    public function __construct(callable $callback)
19
    {
20 1
        $this->callback = $callback;
21 1
    }
22
23
    /** {@inheritdoc} */
24
    public function attach(TargetDefinitionInterface $target, $code)
25
    {
26
        $target->setCondition($code, $this);
27
    }
28
29
    /** {@inheritdoc} */
30 1
    public function match($object)
31
    {
32 1
        return call_user_func($this->callback, $object) ? 1 : null;
33
    }
34
}
35