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 | return 0; |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * {@inheritdoc} |
||
101 | */ |
||
102 | protected function doInteract() |
||
103 | { |
||
104 | $this->assistant->writeLine(["This helps you to set all default config files needed to run KunstmaanCMS.\n"]); |
||
105 | |||
106 | $this->overwriteSecurity = $this->assistant->getOptionOrDefault('overwrite-security', null); |
||
107 | $this->overwriteLiipImagine = $this->assistant->getOptionOrDefault('overwrite-liipimagine', null); |
||
108 | $this->overwriteFosHttpCache = $this->assistant->getOptionOrDefault('overwrite-foshttpcache', null); |
||
109 | $this->overwriteFosUser = $this->assistant->getOptionOrDefault('overwrite-fosuser', null); |
||
110 | |||
111 | if (null === $this->overwriteSecurity) { |
||
112 | $this->overwriteSecurity = $this->assistant->askConfirmation( |
||
113 | 'Do you want to overwrite the default security.yaml configuration file? (y/n)', |
||
114 | 'y' |
||
115 | ); |
||
116 | } |
||
117 | if (null === $this->overwriteLiipImagine) { |
||
118 | $this->overwriteLiipImagine = $this->assistant->askConfirmation( |
||
119 | 'Do you want to overwrite the default liip_imagine.yaml configuration file? (y/n)', |
||
120 | 'y' |
||
121 | ); |
||
122 | } |
||
123 | if (null === $this->overwriteFosHttpCache) { |
||
124 | $this->overwriteFosHttpCache = $this->assistant->askConfirmation( |
||
125 | 'Do you want to overwrite the production fos_http_cache.yaml configuration file? (y/n)', |
||
126 | 'y' |
||
127 | ); |
||
128 | } |
||
129 | if (null === $this->overwriteFosUser) { |
||
130 | $this->overwriteFosUser = $this->assistant->askConfirmation( |
||
131 | 'Do you want to overwrite the fos_user.yaml configuration file? (y/n)', |
||
132 | 'y' |
||
133 | ); |
||
134 | } |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * @return ConfigGenerator |
||
139 | */ |
||
140 | View Code Duplication | protected function createGenerator() |
|
0 ignored issues
–
show
|
|||
141 | { |
||
142 | $filesystem = $this->getContainer()->get('filesystem'); |
||
143 | $registry = $this->getContainer()->get('doctrine'); |
||
144 | |||
145 | return new ConfigGenerator($filesystem, $registry, '/config', $this->assistant, $this->getContainer()); |
||
146 | } |
||
147 | } |
||
148 |
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.