AssignTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 36
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A assignTo() 0 7 1
A resolveAssignCallbacks() 0 4 2
1
<?php
2
3
namespace Vanderlee\Comprehend\Parser\Output;
4
5
/**
6
 * @author Martijn
7
 */
8
trait AssignTrait
9
{
10
    /**
11
     * List of result names to assign the matched text to.
12
     *
13
     * @var callable[]
14
     */
15
    private $assignCallbacks = [];
16
17
    /**
18
     * Resolve all callbacks registered to this trait.
19
     *
20
     * @param $text
21
     */
22 371
    private function resolveAssignCallbacks($text)
23
    {
24 371
        foreach ($this->assignCallbacks as $callback) {
25 2
            $callback($text);
26
        }
27 371
    }
28
29
    /**
30
     * After parsing, assign the matched input to the specified local variable.
31
     * Only assign if successfully matched entire parent up to root.
32
     *
33
     * @param mixed $variable
34
     *
35
     * @return $this
36
     */
37
    public function assignTo(&$variable)
38
    {
39 2
        $this->assignCallbacks[] = function ($text) use (&$variable) {
40 2
            $variable = $text;
41 2
        };
42
43 2
        return $this;
44
    }
45
}
46