Completed
Push — 3.0 ( fb09f5...9f4a0e )
by Daniel
02:19
created

PathTranslationParserFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 39
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A make() 0 11 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