Completed
Push — master ( c1f29a...e6c0c9 )
by Ruud
11:31
created

GeneratorBundle/Command/GenerateConfigCommand.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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()
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