InstallStrategyFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace MagentoHackathon\Composer\Magento\Factory;
4
5
use Composer\Package\PackageInterface;
6
use MagentoHackathon\Composer\Magento\Deploystrategy\DeploystrategyAbstract;
7
use MagentoHackathon\Composer\Magento\ProjectConfig;
8
9
/**
10
 * Class InstallStrategyFactory
11
 * @package MagentoHackathon\Composer\Magento\Deploystrategy
12
 */
13
class InstallStrategyFactory
14
{
15
16
    /**
17
     * @var ProjectConfig
18
     */
19
    protected $config;
20
21
    /**
22
     * @var ParserFactoryInterface
23
     */
24
    protected $parserFactory;
25
26
    /**
27
     * @param ProjectConfig $config
28
     * @param ParserFactoryInterface $parserFactory
29
     */
30 7
    public function __construct(ProjectConfig $config, ParserFactoryInterface $parserFactory)
31
    {
32 7
        $this->config = $config;
33 7
        $this->parserFactory = $parserFactory;
34 7
    }
35
36
    /**
37
     * @param PackageInterface $package
38
     * @param string $packageSourcePath
39
     * @return DeploystrategyAbstract
40
     */
41 5
    public function make(PackageInterface $package, $packageSourcePath)
42
    {
43 5
        $strategyName = $this->config->getModuleSpecificDeployStrategy($package->getName());
44
45 5
        $ns = '\MagentoHackathon\Composer\Magento\Deploystrategy\\';
46 5
        $className = $ns . ucfirst($strategyName);
47 5
        if (!class_exists($className)) {
48 5
            $className  = $ns . 'Symlink';
49
        }
50
51 5
        $strategy = new $className($packageSourcePath, realpath($this->config->getMagentoRootDir()));
52 5
        $strategy->setIgnoredMappings($this->config->getModuleSpecificDeployIgnores($package->getName()));
53 5
        $strategy->setIsForced($this->config->getMagentoForceByPackageName($package->getName()));
54
55 5
        $mappingParser = $this->parserFactory->make($package, $packageSourcePath);
56 5
        $strategy->setMappings($mappingParser->getMappings());
57
58 5
        return $strategy;
59
    }
60
}
61