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

DeploystrategyFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace MagentoHackathon\Composer\Magento\Factory;
4
5
use Composer\Package\PackageInterface;
6
use MagentoHackathon\Composer\Magento\ProjectConfig;
7
use MagentoHackathon\Composer\Magento\Deploystrategy\DeploystrategyAbstract;
8
9
/**
10
 * Class DeploystrategyFactory
11
 * @package MagentoHackathon\Composer\Magento\Deploystrategy
12
 */
13
class DeploystrategyFactory
14
{
15
16
    /**
17
     * @var ProjectConfig
18
     */
19
    protected $config;
20
21
    /**
22
     * @var array
23
     */
24
    protected static $strategies = array(
25
        'copy'      => '\MagentoHackathon\Composer\Magento\Deploystrategy\Copy',
26
        'symlink'   => '\MagentoHackathon\Composer\Magento\Deploystrategy\Symlink',
27
        'link'      => '\MagentoHackathon\Composer\Magento\Deploystrategy\Link',
28
        'none'      => '\MagentoHackathon\Composer\Magento\Deploystrategy\None',
29
    );
30
31
    /**
32
     * @param ProjectConfig $config
33
     */
34 12
    public function __construct(ProjectConfig $config)
35
    {
36 12
        $this->config = $config;
37 12
    }
38
39
    /**
40
     * @param PackageInterface $package
41
     * @param string $packageSourcePath
42
     * @return DeploystrategyAbstract
43
     */
44 6
    public function make(PackageInterface $package, $packageSourcePath)
45
    {
46 6
        $strategyName = $this->config->getDeployStrategy();
47 6
        if ($this->config->hasDeployStrategyOverwrite()) {
48 1
            $moduleSpecificDeployStrategies = $this->config->getDeployStrategyOverwrite();
49
50 1
            if (isset($moduleSpecificDeployStrategies[$package->getName()])) {
51 1
                $strategyName = $moduleSpecificDeployStrategies[$package->getName()];
52 1
            }
53 1
        }
54
55 6
        if (!isset(static::$strategies[$strategyName])) {
56 1
            $className = static::$strategies['symlink'];
57 1
        } else {
58 5
            $className = static::$strategies[$strategyName];
59
        }
60
61 6
        $strategy = new $className($packageSourcePath, realpath($this->config->getMagentoRootDir()));
62 6
        $strategy->setIgnoredMappings($this->config->getModuleSpecificDeployIgnores($package->getName()));
63 6
        $strategy->setIsForced($this->config->getMagentoForceByPackageName($package->getName()));
64 6
        return $strategy;
65
    }
66
}
67