Completed
Push — master ( 39986e...13eb1c )
by Christian
02:43
created

AbstractPackageManipulatingTask   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 1
cbo 3
dl 0
loc 63
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPackage() 0 4 1
A getHome() 0 4 1
A isNoUpdate() 0 4 1
A prepareInput() 0 12 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 Symfony\Component\Console\Input\ArrayInput;
24
25
/**
26
 * This task provides the basic framework for building tasks that perform composer commands.
27
 */
28
abstract class AbstractPackageManipulatingTask extends AbstractComposerCommandTask
29
{
30
    /**
31
     * The package to install.
32
     */
33
    const SETTING_PACKAGE = 'package';
34
35
    /**
36
     * The home path of tenside.
37
     */
38
    const SETTING_HOME = 'home';
39
40
    /**
41
     * The no update flag.
42
     */
43
    const SETTING_NO_UPDATE = 'no-update';
44
45
    /**
46
     * Retrieve the names of the packages to manipulate.
47
     *
48
     * @return array
49
     */
50
    public function getPackage()
51
    {
52
        return (array) $this->file->get(self::SETTING_PACKAGE);
53
    }
54
55
    /**
56
     * Retrieve the home path of tenside.
57
     *
58
     * @return string
59
     */
60
    public function getHome()
61
    {
62
        return (string) $this->file->get(self::SETTING_HOME);
63
    }
64
65
    /**
66
     * Check if the update shall be omitted and only the composer.json shall be manipulated.
67
     *
68
     * @return bool
69
     */
70
    public function isNoUpdate()
71
    {
72
        return (bool) $this->file->has(self::SETTING_NO_UPDATE);
73
    }
74
75
    /**
76
     * {@inheritDoc}
77
     */
78
    protected function prepareInput()
79
    {
80
        $arguments = ['packages' => $this->getPackage()];
81
        if ($this->isNoUpdate()) {
82
            $arguments['no-update'] = '';
83
        }
84
85
        $input = new ArrayInput($arguments);
86
        $input->setInteractive(false);
87
88
        return $input;
89
    }
90
}
91