PathTranslationParserFactory::make()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
crap 2
1
<?php
2
3
namespace MagentoHackathon\Composer\Magento\Factory;
4
5
use Composer\Package\PackageInterface;
6
use MagentoHackathon\Composer\Magento\Parser\Parser;
7
use MagentoHackathon\Composer\Magento\Parser\PathTranslationParser;
8
use MagentoHackathon\Composer\Magento\ProjectConfig;
9
10
/**
11
 * Class PathTranslationParserFactory
12
 * @package MagentoHackathon\Composer\Magento\Parser
13
 * @author  Aydin Hassan <[email protected]>
14
 */
15
class PathTranslationParserFactory implements ParserFactoryInterface
16
{
17
    /**
18
     * @var ParserFactoryInterface
19
     */
20
    protected $parserFactory;
21
22
    /**
23
     * @var ProjectConfig
24
     */
25
    protected $config;
26
27
    /**
28
     * @param ParserFactoryInterface $parserFactory
29
     */
30 8
    public function __construct(ParserFactoryInterface $parserFactory, ProjectConfig $config)
31
    {
32 8
        $this->parserFactory = $parserFactory;
33 8
        $this->config = $config;
34 8
    }
35
36
    /**
37
     * @param PackageInterface $package
38
     * @param string $sourceDir
39
     * @return Parser
40
     * @throws \ErrorException
41
     */
42 2
    public function make(PackageInterface $package, $sourceDir)
43
    {
44 2
        $parser = $this->parserFactory->make($package, $sourceDir);
45
46 2
        if ($this->config->hasPathMappingTranslations()) {
47 1
            $translations = $this->config->getPathMappingTranslations();
48 1
            return new PathTranslationParser($parser, $translations);
49
        }
50
51 1
        return $parser;
52
    }
53
}
54