Completed
Push — master ( d76c5e...03e4c2 )
by Tobias
03:46
created

WorkerTranslationBlock::work()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 13
cts 13
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 4
nop 3
crap 4
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Translation\Extractor\Visitor\Twig;
13
14
use Symfony\Bridge\Twig\Node\TransNode;
15
use Translation\Extractor\Model\SourceCollection;
16
use Translation\Extractor\Model\SourceLocation;
17
18
/**
19
 * @author Tobias Nyholm <[email protected]>
20
 */
21
final class WorkerTranslationBlock
22
{
23
    /**
24
     * @param \Twig_Node|\Twig_NodeInterface $node
25
     * @param SourceCollection               $collection
26
     * @param callable                       $getAbsoluteFilePath
27
     *
28
     * @return \Twig_Node|\Twig_NodeInterface
29
     */
30 3
    public function work($node, SourceCollection $collection, callable $getAbsoluteFilePath)
31
    {
32 3
        if ($node instanceof TransNode) {
33 3
            $id = $node->getNode('body')->getAttribute('data');
34 3
            $domain = 'messages';
35 3
            if ($node->hasNode('domain')) {
36 2
                if (null !== $domainNode = $node->getNode('domain')) {
37 2
                    $domain = $domainNode->getAttribute('value');
38 2
                }
39 2
            }
40
41 3
            $source = new SourceLocation($id, $getAbsoluteFilePath(), $node->getTemplateLine(), ['domain' => $domain]);
42 3
            $collection->addLocation($source);
43 3
        }
44
45 3
        return $node;
46
    }
47
}
48