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

UpdateConfigurationCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 165
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 2
cbo 6
dl 0
loc 165
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
B configure() 0 120 1
A execute() 0 14 1
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
            ->setHelp(<<<DESC
45
 - <info>keywords</info> will be appended to existing ones
46
 - <info>other plain values</info> (package name, version, ...) will replace old ones if they are already present, else they will be added
47
 - <info>nested values</info> (authors, autoload, script, ...) will replace old ones if they are already present, else they will be appended
48
DESC
49
            )
50
            ->addArgument(
51
                self::ARGUMENT_CONFIGURATION_DEST_FOLDER,
52
                InputArgument::OPTIONAL,
53
                'Existing onfiguration file path',
54
                '.'
55
            )
56
            ->addOption(
57
                InputTransformer::KEY_PACKAGE_NAME,
58
                null,
59
                InputOption::VALUE_REQUIRED,
60
                'Name for the composer package'
61
            )
62
            ->addOption(
63
                InputTransformer::KEY_TYPE,
64
                null,
65
                InputOption::VALUE_REQUIRED,
66
                'Package type. Ex : "library" / "project"'
67
            )
68
            ->addOption(
69
                InputTransformer::KEY_LICENSE,
70
                null,
71
                InputOption::VALUE_REQUIRED,
72
                'Package license type'
73
            )
74
            ->addOption(
75
                InputTransformer::KEY_PACKAGE_VERSION,
76
                null,
77
                InputOption::VALUE_REQUIRED,
78
                'Package version number. Ex : "X.Y.Z"'
79
            )
80
            ->addOption(
81
                InputTransformer::KEY_DESCRIPTION,
82
                null,
83
                InputOption::VALUE_REQUIRED,
84
                'Package description'
85
            )
86
            ->addOption(
87
                InputTransformer::KEY_KEYWORD,
88
                null,
89
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
90
                'Package keywords'
91
            )
92
            ->addOption(
93
                InputTransformer::KEY_AUTHOR,
94
                null,
95
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
96
                'Package authors. Format "name[#email[#role]]'
97
            )
98
            ->addOption(
99
                InputTransformer::KEY_PROVIDED_PACKAGE,
100
                null,
101
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
102
                'List of packages provided by this one. Ex : "package-name#version"'
103
            )
104
            ->addOption(
105
                InputTransformer::KEY_SUGGESTED_PACKAGE,
106
                null,
107
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
108
                'List of packages suggested by this one. Ex : "package-name#description"'
109
            )
110
            ->addOption(
111
                InputTransformer::KEY_SUPPORT,
112
                null,
113
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
114
                'List of package support urls. Ex : "type#url"'
115
            )
116
            ->addOption(
117
                InputTransformer::KEY_AUTOLOAD_PSR0,
118
                null,
119
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
120
                'List of package PSR-0 autoload. Ex : "namespace#path"'
121
            )
122
            ->addOption(
123
                InputTransformer::KEY_AUTOLOAD_PSR4,
124
                null,
125
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
126
                'List of package PSR-4 autoload. Ex : "namespace#path"'
127
            )
128
            ->addOption(
129
                InputTransformer::KEY_AUTOLOAD_DEV_PSR0,
130
                null,
131
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
132
                'List of packages PSR-0 dev autoload. Ex : "namespace#path"'
133
            )
134
            ->addOption(
135
                InputTransformer::KEY_AUTOLOAD_DEV_PSR4,
136
                null,
137
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
138
                'List of package PSR-4 dev autoload. Ex : "namespace#path"'
139
            )
140
            ->addOption(
141
                InputTransformer::KEY_REQUIRE,
142
                null,
143
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
144
                'List of required packages. Ex "vendor/package-name#~x.y"'
145
            )
146
            ->addOption(
147
                InputTransformer::KEY_REQUIRE_DEV,
148
                null,
149
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
150
                'List of required dev packages. Ex "vendor/package-name#~x.y"'
151
            )
152
            ->addOption(
153
                InputTransformer::KEY_SCRIPT,
154
                null,
155
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
156
                'List of scripts for the package. Ex : "script-name#command"'
157
            )
158
        ;
159
    }
160
161
    /**
162
     * {@inheritdoc}
163
     */
164
    protected function execute(InputInterface $input, OutputInterface $output)
165
    {
166
        $path = $input->getArgument(self::ARGUMENT_CONFIGURATION_DEST_FOLDER);
167
        $newConfiguration = $this->inputTransformer->fromCommandLine($input->getOptions());
168
        $baseConfiguration = $this->configurationLoader->fromPath($path);
169
170
        $this->updateConfiguration->run(
171
            new UpdateConfigurationRequest(
172
                $baseConfiguration,
173
                $newConfiguration,
174
                $path
175
            )
176
        );
177
    }
178
}
179