ConfigureCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 46
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 12 1
A execute() 0 19 3
1
<?php
2
namespace PressCLI\Command;
3
4
use RuntimeException;
5
use PressCLI\Lib\FileSystem;
6
use PressCLI\Option\Configuration;
7
use PressCLI\Option\GlobalConfiguration;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
class ConfigureCommand extends Command
15
{
16
    use FileSystem;
17
18
    /**
19
     * Configure create command.
20
     */
21
    protected function configure()
22
    {
23
        $this->setName('configure')
24
             ->setDescription('Creates a new project directory and configuration.')
25
             ->addArgument('project-name', InputArgument::OPTIONAL, 'The project name.')
26
             ->addOption(
27
                 'global',
28
                 null,
29
                 InputOption::VALUE_NONE,
30
                 'Creates the global configuration if it does not already exist.'
31
             );
32
    }
33
34
    /**
35
     * Execute create command.
36
     *
37
     * @param  InputInterface  $input
38
     * @param  OutputInterface $output
39
     */
40
    protected function execute(InputInterface $input, OutputInterface $output)
41
    {
42
        $global = $input->getOption('global');
43
        if ($global) {
44
            GlobalConfiguration::create($output);
45
46
            return;
47
        }
48
49
        $name = $input->getArgument('project-name');
50
        if (!$name) {
51
            throw new RuntimeException("Project name is required when not using the --global option!");
52
        }
53
54
        // Handle directory creation and local configuration.
55
        $directory = getcwd() . "/{$name}";
56
        $this->createProjectDirectory($directory, $output);
57
        Configuration::create($directory, $name, $input, $output, $this->getHelper('question'));
0 ignored issues
show
Compatibility introduced by
$this->getHelper('question') of type object<Symfony\Component...Helper\HelperInterface> is not a sub-type of object<Symfony\Component...\Helper\QuestionHelper>. It seems like you assume a concrete implementation of the interface Symfony\Component\Console\Helper\HelperInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
58
    }
59
}
60