AssignTrait::resolveAssignCallbacks()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 2
rs 10
c 0
b 0
f 0
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