Completed
Pull Request — master (#13)
by Asmir
02:23
created

TwitalExtractor::visitTwigFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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