Completed
Pull Request — master (#2414)
by Ruud
13:25
created

GenerateConfigCommand::doInteract()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
nc 4
nop 0
1
<?php
2
3
namespace Kunstmaan\GeneratorBundle\Command;
4
5
use Kunstmaan\GeneratorBundle\Generator\ConfigGenerator;
6
use Symfony\Component\Console\Input\InputOption;
7
8
/**
9
 * Generates config files
10
 */
11
class GenerateConfigCommand extends KunstmaanGenerateCommand
12
{
13
    /** @var bool */
14
    private $overwriteSecurity;
15
16
    /** @var bool */
17
    private $overwriteLiipImagine;
18
19
    /**
20
     * @param string $rootDir
0 ignored issues
show
Bug introduced by
There is no parameter named $rootDir. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
21
     */
22
    public function __construct(string $projectDir)
23
    {
24
        $this->projectDir = $projectDir;
0 ignored issues
show
Bug introduced by
The property projectDir does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
25
26
        parent::__construct();
27
    }
28
29
    /**
30
     * @see Command
31
     */
32
    protected function configure()
33
    {
34
        $this->setDescription('Generates all needed config files not generated by recipes')
35
            ->addOption('overwrite-security', '', InputOption::VALUE_REQUIRED, 'Whether the command should generate a copy or just overwrite the already existing config file')
36
            ->addOption('overwrite-liipimagine', '', InputOption::VALUE_REQUIRED, 'Whether the command should generate a copy or just overwrite the already existing config file')
37
            ->setName('kuma:generate:config');
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    protected function getWelcomeText()
44
    {
45
        return 'Welcome to the Kunstmaan config generator';
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    protected function doExecute()
52
    {
53
        $this->assistant->writeSection('Config generation');
54
55
        $this->createGenerator()->generate($this->projectDir, $this->overwriteSecurity, $this->overwriteLiipImagine);
56
57
        $this->assistant->writeSection('Config successfully created', 'bg=green;fg=black');
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    protected function doInteract()
64
    {
65
        $this->assistant->writeLine(array("This helps you to set all default config files needed to run KunstmaanCMS.\n"));
66
67
        $this->overwriteSecurity = $this->assistant->getOptionOrDefault('overwrite-security', null);
68
        $this->overwriteLiipImagine = $this->assistant->getOptionOrDefault('overwrite-liipimagine', null);
69
70
        if (null === $this->overwriteSecurity) {
71
            $this->overwriteSecurity = $this->assistant->askConfirmation('Do you want to overwrite the default security.yaml configuration file? (y/n)', 'y');
72
        }
73
        if (null === $this->overwriteLiipImagine) {
74
            $this->overwriteLiipImagine = $this->assistant->askConfirmation('Do you want to overwrite the default liip_imagine.yaml configuration file? (y/n)', 'y');
75
        }
76
    }
77
78
    /**
79
     * @return ConfigGenerator
80
     */
81 View Code Duplication
    protected function createGenerator()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
82
    {
83
        $filesystem = $this->getContainer()->get('filesystem');
84
        $registry = $this->getContainer()->get('doctrine');
85
86
        return new ConfigGenerator($filesystem, $registry, '/config', $this->assistant, $this->getContainer());
87
    }
88
}
89