Test Failed
Pull Request — master (#10)
by Yo
02:35
created

UpdateConfigurationCommand::configure()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 122
Code Lines 96

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 122
rs 8.2857
c 0
b 0
f 0
cc 1
eloc 96
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace Yoanm\ComposerConfigManager\Infrastructure\Command;
3
4
use Symfony\Component\Console\Command\Command;
5
use Symfony\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Yoanm\ComposerConfigManager\Application\UpdateConfiguration;
10
use Yoanm\ComposerConfigManager\Application\UpdateConfigurationRequest;
11
use Yoanm\ComposerConfigManager\Application\Loader\ConfigurationLoaderInterface;
12
use Yoanm\ComposerConfigManager\Infrastructure\Command\Transformer\InputTransformer;
13
14
class UpdateConfigurationCommand extends Command
15
{
16
    const NAME = 'update';
17
    const ARGUMENT_CONFIGURATION_DEST_FOLDER = 'path';
18
19
    /** @var InputTransformer */
20
    private $inputTransformer;
21
    /** @var UpdateConfiguration */
22
    private $updateConfiguration;
23
    /** @var ConfigurationLoaderInterface */
24
    private $configurationLoader;
25
26
    public function __construct(
27
        InputTransformer $inputTransformer,
28
        UpdateConfiguration $updateConfiguration,
29
        ConfigurationLoaderInterface $configurationLoader
30
    ) {
31
        parent::__construct(self::NAME);
32
33
        $this->inputTransformer = $inputTransformer;
34
        $this->updateConfiguration = $updateConfiguration;
35
        $this->configurationLoader = $configurationLoader;
36
    }
37
    /**
38
     * {@inheritdoc}
39
     */
40
    protected function configure()
41
    {
42
        $this
43
            ->setDescription('Will update a composer configuration file.')
44
// @codingStandardsIgnoreStart
45
            ->setHelp(<<<DESC
46
 - <info>keywords</info> will be appended to existing ones
47
 - <info>other plain values</info> (package name, version, ...) will replace old ones if they are already present, else they will be added
48
 - <info>nested values</info> (authors, autoload, script, ...) will replace old ones if they are already present, else they will be appended
49
DESC
50
            )
51
// @codingStandardsIgnoreEnd
52
            ->addArgument(
53
                self::ARGUMENT_CONFIGURATION_DEST_FOLDER,
54
                InputArgument::OPTIONAL,
55
                'Existing onfiguration file path',
56
                '.'
57
            )
58
            ->addOption(
59
                InputTransformer::KEY_PACKAGE_NAME,
60
                null,
61
                InputOption::VALUE_REQUIRED,
62
                'Name for the composer package'
63
            )
64
            ->addOption(
65
                InputTransformer::KEY_TYPE,
66
                null,
67
                InputOption::VALUE_REQUIRED,
68
                'Package type. Ex : "library" / "project"'
69
            )
70
            ->addOption(
71
                InputTransformer::KEY_LICENSE,
72
                null,
73
                InputOption::VALUE_REQUIRED,
74
                'Package license type'
75
            )
76
            ->addOption(
77
                InputTransformer::KEY_PACKAGE_VERSION,
78
                null,
79
                InputOption::VALUE_REQUIRED,
80
                'Package version number. Ex : "X.Y.Z"'
81
            )
82
            ->addOption(
83
                InputTransformer::KEY_DESCRIPTION,
84
                null,
85
                InputOption::VALUE_REQUIRED,
86
                'Package description'
87
            )
88
            ->addOption(
89
                InputTransformer::KEY_KEYWORD,
90
                null,
91
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
92
                'Package keywords'
93
            )
94
            ->addOption(
95
                InputTransformer::KEY_AUTHOR,
96
                null,
97
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
98
                'Package authors. Format "name[#email[#role]]'
99
            )
100
            ->addOption(
101
                InputTransformer::KEY_PROVIDED_PACKAGE,
102
                null,
103
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
104
                'List of packages provided by this one. Ex : "package-name#version"'
105
            )
106
            ->addOption(
107
                InputTransformer::KEY_SUGGESTED_PACKAGE,
108
                null,
109
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
110
                'List of packages suggested by this one. Ex : "package-name#description"'
111
            )
112
            ->addOption(
113
                InputTransformer::KEY_SUPPORT,
114
                null,
115
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
116
                'List of package support urls. Ex : "type#url"'
117
            )
118
            ->addOption(
119
                InputTransformer::KEY_AUTOLOAD_PSR0,
120
                null,
121
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
122
                'List of package PSR-0 autoload. Ex : "namespace#path"'
123
            )
124
            ->addOption(
125
                InputTransformer::KEY_AUTOLOAD_PSR4,
126
                null,
127
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
128
                'List of package PSR-4 autoload. Ex : "namespace#path"'
129
            )
130
            ->addOption(
131
                InputTransformer::KEY_AUTOLOAD_DEV_PSR0,
132
                null,
133
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
134
                'List of packages PSR-0 dev autoload. Ex : "namespace#path"'
135
            )
136
            ->addOption(
137
                InputTransformer::KEY_AUTOLOAD_DEV_PSR4,
138
                null,
139
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
140
                'List of package PSR-4 dev autoload. Ex : "namespace#path"'
141
            )
142
            ->addOption(
143
                InputTransformer::KEY_REQUIRE,
144
                null,
145
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
146
                'List of required packages. Ex "vendor/package-name#~x.y"'
147
            )
148
            ->addOption(
149
                InputTransformer::KEY_REQUIRE_DEV,
150
                null,
151
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
152
                'List of required dev packages. Ex "vendor/package-name#~x.y"'
153
            )
154
            ->addOption(
155
                InputTransformer::KEY_SCRIPT,
156
                null,
157
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
158
                'List of scripts for the package. Ex : "script-name#command"'
159
            )
160
        ;
161
    }
162
163
    /**
164
     * {@inheritdoc}
165
     */
166
    protected function execute(InputInterface $input, OutputInterface $output)
167
    {
168
        $path = $input->getArgument(self::ARGUMENT_CONFIGURATION_DEST_FOLDER);
169
        $newConfiguration = $this->inputTransformer->fromCommandLine($input->getOptions());
170
        $baseConfiguration = $this->configurationLoader->fromPath($path);
171
172
        $this->updateConfiguration->run(
173
            new UpdateConfigurationRequest(
174
                $baseConfiguration,
175
                $newConfiguration,
176
                $path
177
            )
178
        );
179
    }
180
}
181