TranslateNAttribute   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 17.65 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 0
cbo 2
dl 6
loc 34
ccs 16
cts 17
cp 0.9412
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B visit() 6 30 7

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Goetas\TwitalBundle\Attribute;
4
5
use DOMAttr;
6
use Goetas\Twital\Attribute;
7
use Goetas\Twital\Compiler;
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