ModifyTag::process()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jasny\PhpdocParser\Tag;
6
7
use Jasny\PhpdocParser\TagInterface;
8
9
/**
10
 * Modify the behavior of a tag
11
 */
12
class ModifyTag implements TagInterface, ProxyTagInterface
13
{
14
    /**
15
     * @var TagInterface
16
     */
17
    protected $tag;
18
19
    /**
20
     * @var callable
21
     */
22
    protected $logic;
23
24
25
    /**
26
     * Class constructor.
27
     *
28
     * @param TagInterface $tag
29
     * @param callable     $logic
30
     */
31 3
    public function __construct(TagInterface $tag, callable $logic)
32
    {
33 3
        $this->tag = $tag;
34 3
        $this->logic = $logic;
35
    }
36
37
    /**
38
     * Get the tag name
39
     *
40
     * @return string
41
     */
42 1
    public function getName(): string
43
    {
44 1
        return $this->tag->getName();
45
    }
46
47
    /**
48
     * Get the wrapped tag.
49
     *
50
     * @return TagInterface
51
     */
52 1
    public function getTag(): TagInterface
53
    {
54 1
        return $this->tag;
55
    }
56
57
    /**
58
     * Process an notation.
59
     *
60
     * @param array  $notations
61
     * @param string $value
62
     * @return array
63
     */
64 1
    public function process(array $notations, string $value): array
65
    {
66 1
        $tagNotations = $this->tag->process([], $value);
67 1
        $notations = call_user_func($this->logic, $notations, $tagNotations, $value);
68
69 1
        return $notations;
70
    }
71
}
72