Completed
Push — master ( 61406b...1dbe37 )
by Ruud
11:21
created

GenerateConfigCommand   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 86
Duplicated Lines 8.14 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 4
dl 7
loc 86
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 8 1
A getWelcomeText() 0 4 1
A doExecute() 0 8 1
A doInteract() 0 18 4
A createGenerator() 7 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
    /** @var bool */
20
    private $overwriteFosHttpCache;
21
22
    /**
23
     * @param string $projectDir
24
     */
25
    public function __construct(string $projectDir)
26
    {
27
        $this->projectDir = $projectDir;
0 ignored issues
show
Bug introduced by Ruud Denivel
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...
28
29
        parent::__construct();
30
    }
31
32
    /**
33
     * @see Command
34
     */
35
    protected function configure()
36
    {
37
        $this->setDescription('Generates all needed config files not generated by recipes')
38
            ->addOption('overwrite-security', '', InputOption::VALUE_REQUIRED, 'Whether the command should generate an example or just overwrite the already existing config file')
39
            ->addOption('overwrite-liipimagine', '', InputOption::VALUE_REQUIRED, 'Whether the command should generate an example or just overwrite the already existing config file')
40
            ->addOption('overwrite-foshttpcache', '', InputOption::VALUE_REQUIRED, 'Whether the command should generate an example or just overwrite the already existing config file')
41
            ->setName('kuma:generate:config');
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    protected function getWelcomeText()
48
    {
49
        return 'Welcome to the Kunstmaan config generator';
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    protected function doExecute()
56
    {
57
        $this->assistant->writeSection('Config generation');
58
59
        $this->createGenerator()->generate($this->projectDir, $this->overwriteSecurity, $this->overwriteLiipImagine, $this->overwriteFosHttpCache);
60
61
        $this->assistant->writeSection('Config successfully created', 'bg=green;fg=black');
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    protected function doInteract()
68
    {
69
        $this->assistant->writeLine(array("This helps you to set all default config files needed to run KunstmaanCMS.\n"));
70
71
        $this->overwriteSecurity = $this->assistant->getOptionOrDefault('overwrite-security', null);
72
        $this->overwriteLiipImagine = $this->assistant->getOptionOrDefault('overwrite-liipimagine', null);
73
        $this->overwriteFosHttpCache = $this->assistant->getOptionOrDefault('overwrite-foshttpcache', null);
74
75
        if (null === $this->overwriteSecurity) {
76
            $this->overwriteSecurity = $this->assistant->askConfirmation('Do you want to overwrite the default security.yaml configuration file? (y/n)', 'y');
77
        }
78
        if (null === $this->overwriteLiipImagine) {
79
            $this->overwriteLiipImagine = $this->assistant->askConfirmation('Do you want to overwrite the default liip_imagine.yaml configuration file? (y/n)', 'y');
80
        }
81
        if (null === $this->overwriteFosHttpCache) {
82
            $this->overwriteFosHttpCache = $this->assistant->askConfirmation('Do you want to overwrite the production fos_http_cache.yaml configuration file? (y/n)', 'y');
83
        }
84
    }
85
86
    /**
87
     * @return ConfigGenerator
88
     */
89 View Code Duplication
    protected function createGenerator()
0 ignored issues
show
Duplication introduced by Ruud Denivel
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...
90
    {
91
        $filesystem = $this->getContainer()->get('filesystem');
92
        $registry = $this->getContainer()->get('doctrine');
93
94
        return new ConfigGenerator($filesystem, $registry, '/config', $this->assistant, $this->getContainer());
95
    }
96
}
97