Completed
Push — master ( c612e7...f3e1c8 )
by Christian
06:23
created

ComposerTaskFactory::createInstance()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 22
rs 6.9811
c 1
b 0
f 0
cc 7
eloc 16
nc 7
nop 2
1
<?php
2
3
/**
4
 * This file is part of tenside/core.
5
 *
6
 * (c) Christian Schiffler <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * This project is provided in good faith and hope to be usable by anyone.
12
 *
13
 * @package    tenside/core
14
 * @author     Christian Schiffler <[email protected]>
15
 * @copyright  2015 Christian Schiffler <[email protected]>
16
 * @license    https://github.com/tenside/core/blob/master/LICENSE MIT
17
 * @link       https://github.com/tenside/core
18
 * @filesource
19
 */
20
21
namespace Tenside\Core\Task\Composer;
22
23
use Tenside\Core\Task\TaskFactoryInterface;
24
use Tenside\Core\Util\JsonArray;
25
26
/**
27
 * This class provides loading of the tenside core configuration.
28
 */
29
class ComposerTaskFactory implements TaskFactoryInterface
30
{
31
    /**
32
     * The home path determinator.
33
     *
34
     * @var string
35
     */
36
    private $home;
37
38
    /**
39
     * Create a new instance.
40
     *
41
     * @param string $home The home path to use.
42
     */
43
    public function __construct($home)
44
    {
45
        $this->home = $home;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function isTypeSupported($taskType)
52
    {
53
        return in_array($taskType, ['install', 'upgrade', 'require-package', 'remove-package']);
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function createInstance($taskType, JsonArray $metaData)
60
    {
61
        switch ($taskType) {
62
            case 'install':
63
                return new InstallTask($metaData);
64
            case 'upgrade':
65
                return new UpgradeTask($metaData);
66
            case 'require-package':
67
                if (!$metaData->has(RequirePackageTask::SETTING_HOME)) {
68
                    $metaData->set(RequirePackageTask::SETTING_HOME, $this->home);
69
                }
70
                return new RequirePackageTask($metaData);
71
            case 'remove-package':
72
                if (!$metaData->has(RemovePackageTask::SETTING_HOME)) {
73
                    $metaData->set(RemovePackageTask::SETTING_HOME, $this->home);
74
                }
75
                return new RemovePackageTask($metaData);
76
            default:
77
        }
78
79
        throw new \InvalidArgumentException('Do not know how to create task.');
80
    }
81
}
82