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

UpgradeTask   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 6
dl 0
loc 72
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getPackages() 0 4 1
A isSelectiveUpgrade() 0 4 1
A getType() 0 4 1
A prepareCommand() 0 9 1
A prepareInput() 0 13 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 Composer\Command\UpdateCommand;
24
use Composer\Factory;
25
use Symfony\Component\Console\Input\ArrayInput;
26
use Tenside\Core\Util\RuntimeHelper;
27
28
/**
29
 * This class holds the information for an upgrade of some or all packages.
30
 */
31
class UpgradeTask extends AbstractComposerCommandTask
32
{
33
    /**
34
     * The packages to upgrade.
35
     */
36
    const SETTING_PACKAGES = 'packages';
37
38
    /**
39
     * The home path of tenside.
40
     */
41
    const SETTING_HOME = 'home';
42
43
    /**
44
     * Retrieve the names of the packages to upgrade or null if none.
45
     *
46
     * @return string[]|null
0 ignored issues
show
Documentation introduced by
Should the return type not be array|string|integer|null? Also, consider making the array more specific, something like array<String>, or String[].

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

If the return type contains the type array, this check recommends the use of a more specific type like String[] or array<String>.

Loading history...
47
     */
48
    public function getPackages()
49
    {
50
        return $this->file->get(self::SETTING_PACKAGES);
51
    }
52
53
    /**
54
     * Check if the upgrade is selective or for all packages.
55
     *
56
     * @return bool
57
     */
58
    public function isSelectiveUpgrade()
59
    {
60
        return (null !== $this->getPackages());
61
    }
62
63
    /**
64
     * Returns 'upgrade'.
65
     *
66
     * {@inheritdoc}
67
     */
68
    public function getType()
69
    {
70
        return 'upgrade';
71
    }
72
73
    /**
74
     * {@inheritDoc}
75
     */
76
    protected function prepareCommand()
77
    {
78
        RuntimeHelper::setupHome($this->file->get(self::SETTING_HOME));
79
80
        $command = new UpdateCommand();
81
        $command->setComposer(Factory::create($this->getIO()));
82
83
        return $command;
84
    }
85
86
    /**
87
     * {@inheritDoc}
88
     */
89
    protected function prepareInput()
90
    {
91
        $arguments = [];
92
93
        if ($this->isSelectiveUpgrade()) {
94
            $arguments['packages'] = $this->getPackages();
95
        }
96
97
        $input = new ArrayInput($arguments);
98
        $input->setInteractive(false);
99
100
        return $input;
101
    }
102
}
103