UpdateConfigurationCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 169
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Importance

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

3 Methods

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