Completed
Push — master ( aba493...5356ed )
by Ruud
315:38 queued 305:00
created

GeneratorBundle/Command/GenerateConfigCommand.php (1 issue)

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 string */
14
    private $projectDir;
15
16
    /** @var bool */
17
    private $overwriteSecurity;
18
19
    /** @var bool */
20
    private $overwriteLiipImagine;
21
22
    /** @var bool */
23
    private $overwriteFosHttpCache;
24
25
    /** @var bool */
26
    private $overwriteFosUser;
27
28
    /**
29
     * @param string $projectDir
30
     */
31
    public function __construct(string $projectDir)
32
    {
33
        $this->projectDir = $projectDir;
34
35
        parent::__construct();
36
    }
37
38
    /**
39
     * @see Command
40
     */
41
    protected function configure()
42
    {
43
        $this->setDescription('Generates all needed config files not generated by recipes')
44
            ->addOption(
45
                'overwrite-security',
46
                '',
47
                InputOption::VALUE_REQUIRED,
48
                'Whether the command should generate an example or just overwrite the already existing config file'
49
            )
50
            ->addOption(
51
                'overwrite-liipimagine',
52
                '',
53
                InputOption::VALUE_REQUIRED,
54
                'Whether the command should generate an example or just overwrite the already existing config file'
55
            )
56
            ->addOption(
57
                'overwrite-foshttpcache',
58
                '',
59
                InputOption::VALUE_REQUIRED,
60
                'Whether the command should generate an example or just overwrite the already existing config file'
61
            )
62
            ->addOption(
63
                'overwrite-fosuser',
64
                '',
65
                InputOption::VALUE_REQUIRED,
66
                'Whether the command should generate an example or just overwrite the already existing config file'
67
            )
68
            ->setName('kuma:generate:config');
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    protected function getWelcomeText()
75
    {
76
        return 'Welcome to the Kunstmaan config generator';
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    protected function doExecute()
83
    {
84
        $this->assistant->writeSection('Config generation');
85
86
        $this->createGenerator()->generate(
87
            $this->projectDir,
88
            $this->overwriteSecurity,
89
            $this->overwriteLiipImagine,
90
            $this->overwriteFosHttpCache,
91
            $this->overwriteFosUser
92
        );
93
94
        $this->assistant->writeSection('Config successfully created', 'bg=green;fg=black');
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100
    protected function doInteract()
101
    {
102
        $this->assistant->writeLine(["This helps you to set all default config files needed to run KunstmaanCMS.\n"]);
103
104
        $this->overwriteSecurity = $this->assistant->getOptionOrDefault('overwrite-security', null);
105
        $this->overwriteLiipImagine = $this->assistant->getOptionOrDefault('overwrite-liipimagine', null);
106
        $this->overwriteFosHttpCache = $this->assistant->getOptionOrDefault('overwrite-foshttpcache', null);
107
        $this->overwriteFosUser = $this->assistant->getOptionOrDefault('overwrite-fosuser', null);
108
109
        if (null === $this->overwriteSecurity) {
110
            $this->overwriteSecurity = $this->assistant->askConfirmation(
111
                'Do you want to overwrite the default security.yaml configuration file? (y/n)',
112
                'y'
113
            );
114
        }
115
        if (null === $this->overwriteLiipImagine) {
116
            $this->overwriteLiipImagine = $this->assistant->askConfirmation(
117
                'Do you want to overwrite the default liip_imagine.yaml configuration file? (y/n)',
118
                'y'
119
            );
120
        }
121
        if (null === $this->overwriteFosHttpCache) {
122
            $this->overwriteFosHttpCache = $this->assistant->askConfirmation(
123
                'Do you want to overwrite the production fos_http_cache.yaml configuration file? (y/n)',
124
                'y'
125
            );
126
        }
127
        if (null === $this->overwriteFosUser) {
128
            $this->overwriteFosUser = $this->assistant->askConfirmation(
129
                'Do you want to overwrite the fos_user.yaml configuration file? (y/n)',
130
                'y'
131
            );
132
        }
133
    }
134
135
    /**
136
     * @return ConfigGenerator
137
     */
138 View Code Duplication
    protected function createGenerator()
0 ignored issues
show
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...
139
    {
140
        $filesystem = $this->getContainer()->get('filesystem');
141
        $registry = $this->getContainer()->get('doctrine');
142
143
        return new ConfigGenerator($filesystem, $registry, '/config', $this->assistant, $this->getContainer());
144
    }
145
}
146