Completed
Push — master ( 8e56f4...9f919b )
by Christian
03:16
created

UpgradeTask::getDataDir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
     * The data directory of tenside.
45
     */
46
    const SETTING_DATA_DIR = 'data-dir';
47
48
    /**
49
     * Retrieve the names of the packages to upgrade or null if none.
50
     *
51
     * @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...
52
     */
53
    public function getPackages()
54
    {
55
        return $this->file->get(self::SETTING_PACKAGES);
56
    }
57
58
    /**
59
     * Check if the upgrade is selective or for all packages.
60
     *
61
     * @return bool
62
     */
63
    public function isSelectiveUpgrade()
64
    {
65
        return (null !== $this->getPackages());
66
    }
67
68
    /**
69
     * Retrieve the home path of tenside.
70
     *
71
     * @return string
72
     */
73
    public function getHome()
74
    {
75
        return (string) $this->file->get(self::SETTING_HOME);
76
    }
77
78
    /**
79
     * Retrieve the data path of tenside.
80
     *
81
     * @return string
82
     */
83
    public function getDataDir()
84
    {
85
        return (string) $this->file->get(self::SETTING_DATA_DIR);
86
    }
87
88
    /**
89
     * Returns 'upgrade'.
90
     *
91
     * {@inheritdoc}
92
     */
93
    public function getType()
94
    {
95
        return 'upgrade';
96
    }
97
98
    /**
99
     * {@inheritDoc}
100
     */
101
    protected function prepareCommand()
102
    {
103
        RuntimeHelper::setupHome($this->getHome());
104
105
        $command = new UpdateCommand();
106
        $command->setComposer(Factory::create($this->getIO()));
107
108
        return $command;
109
    }
110
111
    /**
112
     * {@inheritDoc}
113
     */
114
    protected function prepareInput()
115
    {
116
        $arguments = [];
117
118
        if ($this->isSelectiveUpgrade()) {
119
            $arguments['packages'] = $this->getPackages();
120
        }
121
122
        $input = new ArrayInput($arguments);
123
        $input->setInteractive(false);
124
125
        return $input;
126
    }
127
}
128