Completed
Pull Request — master (#11)
by Asmir
06:37 queued 05:22
created

TranslateNAttribute::visit()   C

Complexity

Conditions 7
Paths 5

Size

Total Lines 30
Code Lines 16

Duplication

Lines 6
Ratio 20 %

Code Coverage

Tests 16
CRAP Score 7.0099

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 6
loc 30
ccs 16
cts 17
cp 0.9412
rs 6.7272
cc 7
eloc 16
nc 5
nop 2
crap 7.0099
1
<?php
2
namespace Goetas\TwitalBundle\Attribute;
3
4
use Goetas\Twital\Attribute;
5
use Goetas\Twital\Compiler;
6
use DOMAttr;
7
use Goetas\Twital\Twital;
8
use Goetas\Twital\Helper\ParserHelper;
9
10
/**
11
 *
12
 * @author Asmir Mustafic <[email protected]>
13
 *
14
 */
15
class TranslateNAttribute implements Attribute
16
{
17
18 3
    public function visit(DOMAttr $att, Compiler $context)
19
    {
20 3
        $node = $att->ownerElement;
21
22 3
        $expessions = ParserHelper::staticSplitExpression($att->value, ",");
23
24 3
        if (!isset($expessions[0]) || !strlen($expessions[0])) {
25
            throw new \Exception("The count for trans-n is required");
26
        }
27
28 3
        $with = '{\'%count%\':' . $expessions[0] . '}';
29
30 3 View Code Duplication
        if (isset($expessions[1]) && strlen($expessions[1])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31 2
            $with = "$with|merge(" . $expessions[1] . ')';
32
        }
33
34 3
        $from = '';
35 3 View Code Duplication
        if (isset($expessions[2]) && strlen($expessions[2])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36 1
            $from = " from $expessions[2]";
37
        }
38
39 3
        $start = $context->createControlNode("transchoice " . $expessions[0] . " with $with" . $from);
40 3
        $end = $context->createControlNode("endtranschoice");
41
42 3
        $node->insertBefore($start, $node->firstChild);
43
44 3
        $node->appendChild($end);
45
46 3
        $node->removeAttributeNode($att);
47 3
    }
48
}
49