TwitalExtractor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A extract() 0 12 3
1
<?php
2
3
namespace Goetas\TwitalBundle\Translation;
4
5
use Goetas\Twital\TwitalLoader;
6
use Symfony\Bridge\Twig\Translation\TwigExtractor;
7
use Symfony\Component\Finder\Finder;
8
use Symfony\Component\Translation\MessageCatalogue;
9
use Twig\Environment;
10
11
/**
12
 *
13
 * @author Asmir Mustafic <[email protected]>
14
 *
15
 */
16
class TwitalExtractor extends TwigExtractor
17
{
18
19
    protected $twital;
20
21
    public function __construct(Environment $twig, TwitalLoader $twital)
22
    {
23
        parent::__construct($twig);
24
        $this->twital = $twital;
25
    }
26
27
    /**
28
     * {@inheritDoc}
29
     */
30
    public function extract($directory, MessageCatalogue $catalogue)
31
    {
32
        // load any existing translation files
33
        $finder = new Finder();
34
        $files = $finder->files()->in($directory);
0 ignored issues
show
Bug introduced by
It seems like $directory defined by parameter $directory on line 30 can also be of type array; however, Symfony\Component\Finder\Finder::in() does only seem to accept string|array<integer,string>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
35
        foreach ($files as $file) {
36
            if ($adapter = $this->twital->getSourceAdapter($file->getPathname())) {
37
                $source = $this->twital->getTwital()->compile($adapter, file_get_contents($file->getPathname()));
38
                $this->extractTemplate($source, $catalogue);
39
            }
40
        }
41
    }
42
}
43