Completed
Push — master ( 65f484...cb55bb )
by Asmir
07:37 queued 02:12
created

TwitalExtractor   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 41.51 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 26.32%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 22
loc 53
ccs 5
cts 19
cp 0.2632
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A visitPhpFile() 0 3 1
A visitTwigFile() 11 11 2
A visitFile() 11 11 2

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\Translation\Jms;
4
5
use Goetas\Twital\TwitalLoader;
6
use JMS\TranslationBundle\Model\MessageCatalogue;
7
use JMS\TranslationBundle\Translation\Extractor\File\TwigFileExtractor;
8
use JMS\TranslationBundle\Translation\Extractor\FileVisitorInterface;
9
use Twig\Source;
10
11
/**
12
 *
13
 * @author Asmir Mustafic <[email protected]>
14
 *
15
 */
16
class TwitalExtractor implements FileVisitorInterface
17
{
18
    /**
19
     *
20
     * @var TwigFileExtractor
21
     */
22
    private $twigFileExtractor;
23
    /**
24
     *
25
     * @var \Goetas\Twital\TwitalLoader
26
     */
27
    private $twitalLoader;
28
    /**
29
     *
30
     * @var \Twig_Environment
31
     */
32
    private $twig;
33
34 1
    public function __construct(\Twig_Environment $twig, TwitalLoader $twitalLoader, TwigFileExtractor $twigFileExtractor)
35
    {
36 1
        $this->twig = $twig;
37 1
        $this->twitalLoader = $twitalLoader;
38 1
        $this->twigFileExtractor = $twigFileExtractor;
39 1
    }
40
41
    public function visitPhpFile(\SplFileInfo $file, MessageCatalogue $catalogue, array $ast)
42
    {
43
    }
44
45 View Code Duplication
    public function visitTwigFile(\SplFileInfo $file, MessageCatalogue $catalogue, \Twig_Node $ast)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
46
    {
47
        if ($adapter = $this->twitalLoader->getSourceAdapter((string)$file)) {
48
49
            $source = $this->twitalLoader->getTwital()->compile($adapter, file_get_contents((string)$file));
50
51
            $ast = $this->twig->parse($this->twig->tokenize(new Source($source, (string)$file)));
52
        }
53
54
        $this->twigFileExtractor->visitTwigFile($file, $catalogue, $ast);
55
    }
56
57 View Code Duplication
    function visitFile(\SplFileInfo $file, MessageCatalogue $catalogue)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in 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...
58
    {
59
        if ($adapter = $this->twitalLoader->getSourceAdapter((string)$file)) {
60
61
            $source = $this->twitalLoader->getTwital()->compile($adapter, file_get_contents((string)$file));
62
63
            $ast = $this->twig->parse($this->twig->tokenize(new Source($source, (string)$file)));
64
65
            $this->twigFileExtractor->visitTwigFile($file, $catalogue, $ast);
66
        }
67
    }
68
}
69