Completed
Pull Request — 5.6 (#2830)
by Jeroen
14:14
created

GeneratorBundle/Generator/ArticleGenerator.php (19 issues)

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\Generator;
4
5
use Kunstmaan\GeneratorBundle\Helper\CommandAssistant;
6
use Kunstmaan\GeneratorBundle\Helper\GeneratorUtils;
7
use Symfony\Bridge\Doctrine\RegistryInterface;
8
use Symfony\Component\DependencyInjection\ContainerInterface;
9
use Symfony\Component\Filesystem\Filesystem;
10
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
11
12
/**
13
 * Generates an Article section
14
 */
15
class ArticleGenerator extends KunstmaanGenerator
16
{
17
    /**
18
     * @var BundleInterface
19
     */
20
    private $bundle;
21
22
    /**
23
     * @var string
24
     */
25
    private $entity;
26
27
    /**
28
     * @var array
29
     */
30
    private $parentPages = [];
31
32
    /**
33
     * ArticleGenerator constructor.
34
     *
35
     * @param string $skeletonDir
36
     */
37
    public function __construct(Filesystem $filesystem, RegistryInterface $registry, $skeletonDir, array $parentPages, CommandAssistant $assistant, ContainerInterface $container)
38
    {
39
        parent::__construct($filesystem, $registry, $skeletonDir, $assistant, $container);
40
        $this->parentPages = $parentPages;
41
    }
42
43
    /**
44
     * @param BundleInterface $bundle         The bundle
45
     * @param string          $entity
46
     * @param string          $prefix         The prefix
47
     * @param bool            $multilanguage
48
     * @param bool            $usesAuthor
49
     * @param bool            $usesCategories
50
     * @param bool            $usesTags
51
     * @param bool            $dummydata
52
     */
53
    public function generate(BundleInterface $bundle, $entity, $prefix, $multilanguage, $usesAuthor, $usesCategories, $usesTags, $bundleWithHomePage, $dummydata)
54
    {
55
        $this->bundle = $bundle;
56
        $this->entity = $entity;
57
58
        $parameters = [
59
            'namespace' => $bundle->getNamespace(),
60
            'bundle' => $bundle,
61
            'prefix' => GeneratorUtils::cleanPrefix($prefix),
62
            'entity_class' => $entity,
63
            'uses_author' => $usesAuthor,
64
            'uses_category' => $usesCategories,
65
            'uses_tag' => $usesTags,
66
            'isV4' => $this->isSymfony4(),
67
        ];
68
69
        $this->generateEntities($parameters);
70
        $this->generateRepositories($parameters);
71
        $this->generateForm($parameters);
72
        $this->generateAdminList($parameters);
73
        $this->generateController($parameters);
74
        $this->generatePageTemplateConfigs($parameters);
75
        $this->generateTemplates($parameters, $bundleWithHomePage);
76
        $this->generateRouting($parameters, $multilanguage);
77
        $this->generateMenu($parameters);
78
        $this->generateServices($parameters);
79
        $this->updateParentPages();
80
        if ($dummydata) {
81
            $this->generateFixtures($parameters);
82
        }
83
    }
84
85
    /**
86
     * @param array $parameters The template parameters
87
     */
88
    public function generateServices(array $parameters)
89
    {
90
        if ($this->isSymfony4()) {
91
            return;
92
        }
93
94
        $dirPath = sprintf('%s/Resources/config', $this->bundle->getPath());
95
        $skeletonDir = sprintf('%s/Resources/config', $this->skeletonDir);
96
        $this->setSkeletonDirs([$skeletonDir]);
97
98
        $routing = $this->render('/services.yml', $parameters);
99
        GeneratorUtils::append($routing, $dirPath . '/services.yml');
100
101
        $this->assistant->writeLine('Generating services : <info>OK</info>');
102
    }
103
104
    /**
105
     * @param array $parameters The template parameters
106
     */
107
    public function generateMenu(array $parameters)
108
    {
109
        $relPath = '/Helper/Menu/';
110
        $sourceDir = $this->skeletonDir . $relPath;
111
        $targetDir = $this->bundle->getPath() . $relPath;
112
113
        $filename = 'MenuAdaptor.php';
114
        $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . 'MenuAdaptor.php');
115
116
        $dirPath = sprintf('%s/Helper/Menu', $this->bundle->getPath());
117
        $skeletonDir = sprintf('%s/Helper/Menu', $this->skeletonDir);
118
        $this->setSkeletonDirs([$skeletonDir]);
119
        $partial = '';
120
        $twigParameters = $parameters;
121
122
        if ($parameters['uses_author']) {
123
            $twigParameters['type'] = 'Author';
124
            $partial .= $this->render('/MenuAdaptorPartial.php.twig', $twigParameters);
125
        }
126
        if ($parameters['uses_category']) {
127
            $twigParameters['type'] = 'Category';
128
            $partial .= $this->render('/MenuAdaptorPartial.php.twig', $twigParameters);
129
        }
130
        if ($parameters['uses_tag']) {
131
            $twigParameters['type'] = 'Tag';
132
            $partial .= $this->render('/MenuAdaptorPartial.php.twig', $twigParameters);
133
        }
134
        GeneratorUtils::replace('//%menuAdaptorPartial.php.twig%', $partial, $dirPath . '/' . $this->entity . $filename);
135
136
        $this->assistant->writeLine('Generating menu : <info>OK</info>');
137
    }
138
139
    /**
140
     * @param array $parameters    The template parameters
141
     * @param bool  $multilanguage
142
     */
143
    public function generateRouting(array $parameters, $multilanguage)
144
    {
145
        if ($this->isSymfony4()) {
146
            return;
147
        }
148
149
        $dirPath = sprintf('%s/Resources/config', $this->bundle->getPath());
150
        $skeletonDir = sprintf('%s/Resources/config', $this->skeletonDir);
151
        $this->setSkeletonDirs([$skeletonDir]);
152
153
        $routingSource = $multilanguage ? 'routing_multilanguage' : 'routing_singlelanguage';
154
        $routing = $this->render('/' . $routingSource . '.yml', $parameters);
155
156
        GeneratorUtils::append($routing, $dirPath . '/routing.yml');
157
158
        $twigParameters = $parameters;
159
160 View Code Duplication
        if ($parameters['uses_author']) {
0 ignored issues
show
This code seems to be duplicated across 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...
161
            $twigParameters['type'] = 'Author';
162
            $routing = $this->render('/routing_partial.yml', $twigParameters);
163
            GeneratorUtils::append($routing, $dirPath . '/routing.yml');
164
        }
165
166 View Code Duplication
        if ($parameters['uses_category']) {
0 ignored issues
show
This code seems to be duplicated across 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...
167
            $twigParameters['type'] = 'Category';
168
            $routing = $this->render('/routing_partial.yml', $twigParameters);
169
            GeneratorUtils::append($routing, $dirPath . '/routing.yml');
170
        }
171
        if ($parameters['uses_tag']) {
172
            $twigParameters['type'] = 'Tag';
173
            $routing = $this->render('/routing_partial.yml', $twigParameters);
174
            GeneratorUtils::append($routing, $dirPath . '/routing.yml');
175
        }
176
177
        $this->assistant->writeLine('Generating routing : <info>OK</info>');
178
    }
179
180
    /**
181
     * @param array  $parameters         The template parameters
182
     * @param string $bundleWithHomePage
183
     */
184
    public function generateTemplates(array $parameters, $bundleWithHomePage)
185
    {
186
        $relPath = '/Resources/views/Pages/%sOverviewPage/';
187
        $sourceDir = $this->skeletonDir . sprintf($relPath, '');
188
        $targetDir = $this->getTemplateDir($this->bundle) . sprintf('/Pages/%sOverviewPage/', $this->entity);
189
        $twigParameters = $parameters;
190
        $twigParameters['bundleWithHomePage'] = $bundleWithHomePage;
191
192
        $this->renderSingleFile($sourceDir, $targetDir, 'pagetemplate.html.twig', $twigParameters);
193
        $this->renderSingleFile($sourceDir, $targetDir, 'view.html.twig', $twigParameters);
194
195
        if ($twigParameters['uses_category']) {
196
            $this->renderSingleFile($sourceDir, $targetDir, '_filter-category.html.twig', $twigParameters);
197
            $this->renderSingleFile($sourceDir, $targetDir, '_list-category.html.twig', $twigParameters);
198
        }
199
200
        if ($twigParameters['uses_tag']) {
201
            $this->renderSingleFile($sourceDir, $targetDir, '_filter-tag.html.twig', $twigParameters);
202
            $this->renderSingleFile($sourceDir, $targetDir, '_list-tag.html.twig', $twigParameters);
203
        }
204
205
        $relPath = '/Resources/views/Pages/%sPage/';
206
        $sourceDir = $this->skeletonDir . sprintf($relPath, '');
207
        $targetDir = $this->getTemplateDir($this->bundle) . sprintf('/Pages/%sPage/', $this->entity);
208
209
        $this->renderSingleFile($sourceDir, $targetDir, 'pagetemplate.html.twig', $twigParameters);
210
        $this->renderSingleFile($sourceDir, $targetDir, 'view.html.twig', $twigParameters);
211
212
        $relPath = '/Resources/views/AdminList/%sPageAdminList/';
213
        $sourceDir = $this->skeletonDir . sprintf($relPath, '');
214
        $targetDir = $this->getTemplateDir($this->bundle) . sprintf('/AdminList/%sPageAdminList/', $this->entity);
215
216
        $this->renderSingleFile($sourceDir, $targetDir, 'list.html.twig', $twigParameters);
217
218
        $this->assistant->writeLine('Generating twig templates : <info>OK</info>');
219
    }
220
221
    /**
222
     * @param array $parameters The template parameters
223
     */
224
    public function generateController(array $parameters)
225
    {
226
        $relPath = '/Controller/';
227
        $sourceDir = $this->skeletonDir . $relPath;
228
        $targetDir = $this->bundle->getPath() . $relPath;
229
230
        $filename = 'PageAdminListController.php';
231
        $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . $filename);
232
233 View Code Duplication
        if ($parameters['uses_author']) {
0 ignored issues
show
This code seems to be duplicated across 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...
234
            $filename = 'AuthorAdminListController.php';
235
            $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . $filename);
236
        }
237
238 View Code Duplication
        if ($parameters['uses_category']) {
0 ignored issues
show
This code seems to be duplicated across 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...
239
            $filename = 'CategoryAdminListController.php';
240
            $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . $filename);
241
        }
242
243 View Code Duplication
        if ($parameters['uses_tag']) {
0 ignored issues
show
This code seems to be duplicated across 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...
244
            $filename = 'TagAdminListController.php';
245
            $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . $filename);
246
        }
247
248
        $filename = 'ArticleController.php';
249
        $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . $filename);
250
251
        $this->assistant->writeLine('Generating controllers : <info>OK</info>');
252
    }
253
254
    /**
255
     * @param array $parameters The template parameters
256
     */
257
    public function generatePageTemplateConfigs(array $parameters)
258
    {
259
        $basePath = $this->isSymfony4() ? $this->container->getParameter('kernel.project_dir') : $this->bundle->getPath();
260
        $relPath = $this->isSymfony4() ? '/config/kunstmaancms/pagetemplates/' : '/Resources/config/pagetemplates/';
261
        $sourceDir = $this->skeletonDir . '/Resources/config/pagetemplates/';
262
        $targetDir = $basePath . $relPath;
263
264
        $this->renderSingleFile($sourceDir, $targetDir, 'page.yml', $parameters, false, strtolower($this->entity) . 'page.yml');
265
        $this->renderSingleFile($sourceDir, $targetDir, 'overviewpage.yml', $parameters, false, strtolower($this->entity) . 'overviewpage.yml');
266
267
        $basePath = $this->isSymfony4() ? $this->container->getParameter('kernel.project_dir') : $this->bundle->getPath();
268
        $relPath = $this->isSymfony4() ? '/config/kunstmaancms/pageparts/' : '/Resources/config/pageparts/';
269
        $sourceDir = $this->skeletonDir . '/Resources/config/pageparts/';
270
        $targetDir = $basePath . $relPath;
271
272
        $this->renderSingleFile($sourceDir, $targetDir, 'main.yml', $parameters, false, strtolower($this->entity) . 'main.yml');
273
274
        $this->assistant->writeLine('Generating PagePart configurators : <info>OK</info>');
275
    }
276
277
    /**
278
     * @param array $parameters The template parameters
279
     */
280
    public function generateAdminList(array $parameters)
281
    {
282
        $relPath = '/AdminList/';
283
        $sourceDir = $this->skeletonDir . $relPath;
284
        $targetDir = $this->bundle->getPath() . $relPath;
285
286
        $filename = 'PageAdminListConfigurator.php';
287
        $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . $filename);
288
289 View Code Duplication
        if ($parameters['uses_author']) {
0 ignored issues
show
This code seems to be duplicated across 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...
290
            $filename = 'AuthorAdminListConfigurator.php';
291
            $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . $filename);
292
        }
293
294 View Code Duplication
        if ($parameters['uses_category']) {
0 ignored issues
show
This code seems to be duplicated across 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...
295
            $filename = 'CategoryAdminListConfigurator.php';
296
            $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . $filename);
297
        }
298
299 View Code Duplication
        if ($parameters['uses_tag']) {
0 ignored issues
show
This code seems to be duplicated across 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...
300
            $filename = 'TagAdminListConfigurator.php';
301
            $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . $filename);
302
        }
303
304
        $this->assistant->writeLine('Generating AdminList configurators : <info>OK</info>');
305
    }
306
307
    /**
308
     * @param array $parameters The template parameters
309
     */
310
    public function generateForm(array $parameters)
311
    {
312
        $relPath = '/Form/Pages/';
313
        $sourceDir = $this->skeletonDir . $relPath;
314
        $targetDir = $this->bundle->getPath() . $relPath;
315
316
        $filename = 'OverviewPageAdminType.php';
317
        $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . $filename);
318
319
        $filename = 'PageAdminType.php';
320
        $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . $filename);
321
322
        $relPath = '/Form/';
323
        $sourceDir = $this->skeletonDir . $relPath;
324
        $targetDir = $this->bundle->getPath() . $relPath;
325
326 View Code Duplication
        if ($parameters['uses_author']) {
0 ignored issues
show
This code seems to be duplicated across 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...
327
            $filename = 'AuthorAdminType.php';
328
            $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . $filename);
329
        }
330
331 View Code Duplication
        if ($parameters['uses_category']) {
0 ignored issues
show
This code seems to be duplicated across 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...
332
            $filename = 'CategoryAdminType.php';
333
            $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . $filename);
334
        }
335
336 View Code Duplication
        if ($parameters['uses_tag']) {
0 ignored issues
show
This code seems to be duplicated across 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...
337
            $filename = 'TagAdminType.php';
338
            $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . $filename);
339
        }
340
341
        $dirPath = sprintf('%s/Form/Pages', $this->bundle->getPath());
342
        $skeletonDir = sprintf('%s/Form/Pages', $this->skeletonDir);
343
        $this->setSkeletonDirs([$skeletonDir]);
344
        $partial = '';
345
        $twigParameters = $parameters;
346
347 View Code Duplication
        if ($parameters['uses_author']) {
0 ignored issues
show
This code seems to be duplicated across 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...
348
            $twigParameters['type'] = 'Author';
349
            $twigParameters['pluralType'] = 'authors';
350
            $partial .= $this->render('/PageAdminTypePartial.php.twig', $twigParameters);
351
        }
352
353
        if ($parameters['uses_category']) {
354
            $twigParameters['type'] = 'Category';
355
            $twigParameters['pluralType'] = 'categories';
356
            $partial .= $this->render('/PageAdminTypePartial.php.twig', $twigParameters);
357
        }
358
359
        if ($parameters['uses_tag']) {
360
            $twigParameters['type'] = 'Tag';
361
            $twigParameters['pluralType'] = 'tags';
362
            $partial .= $this->render('/PageAdminTypePartial.php.twig', $twigParameters);
363
        }
364
        GeneratorUtils::replace('//%PageAdminTypePartial.php.twig%', $partial, $dirPath . '/' . $this->entity . 'PageAdminType.php');
365
366
        $this->assistant->writeLine('Generating forms : <info>OK</info>');
367
    }
368
369
    /**
370
     * @param array $parameters The template parameters
371
     */
372
    public function generateRepositories(array $parameters)
373
    {
374
        $relPath = '/Repository/';
375
        $sourceDir = $this->skeletonDir . $relPath;
376
        $targetDir = $this->bundle->getPath() . $relPath;
377
378
        $filename = 'PageRepository.php';
379
        $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . $filename);
380
381
        $filename = 'OverviewPageRepository.php';
382
        $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . $filename);
383
384
        $dirPath = sprintf('%s/Repository', $this->bundle->getPath());
385
        $skeletonDir = sprintf('%s/Repository', $this->skeletonDir);
386
        $this->setSkeletonDirs([$skeletonDir]);
387
388
        $repository = $this->render('/PageRepositoryPartial.php.twig', $parameters);
389
        GeneratorUtils::replace('%PageRepository.php%', $repository, $dirPath . '/' . $this->entity . 'PageRepository.php');
390
391
        $this->assistant->writeLine('Generating repositories : <info>OK</info>');
392
    }
393
394
    /**
395
     * @param array $parameters The template parameters
396
     */
397
    public function generateEntities(array $parameters)
398
    {
399
        $relPath = '/Entity/Pages/';
400
        $sourceDir = $this->skeletonDir . $relPath;
401
        $targetDir = $this->bundle->getPath() . $relPath;
402
403
        $filename = 'OverviewPage.php';
404
        $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . $filename);
405
406
        $filename = 'Page.php';
407
        $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . $filename);
408
409
        $relPath = '/Entity/';
410
        $sourceDir = $this->skeletonDir . $relPath;
411
        $targetDir = $this->bundle->getPath() . $relPath;
412
413 View Code Duplication
        if ($parameters['uses_author']) {
0 ignored issues
show
This code seems to be duplicated across 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...
414
            $filename = 'Author.php';
415
            $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . $filename);
416
        }
417
418 View Code Duplication
        if ($parameters['uses_category']) {
0 ignored issues
show
This code seems to be duplicated across 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...
419
            $filename = 'Category.php';
420
            $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . $filename);
421
        }
422
423 View Code Duplication
        if ($parameters['uses_tag']) {
0 ignored issues
show
This code seems to be duplicated across 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...
424
            $filename = 'Tag.php';
425
            $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . $filename);
426
        }
427
428
        $dirPath = sprintf('%s/Entity/Pages', $this->bundle->getPath());
429
        $skeletonDir = sprintf('%s/Entity/Pages', $this->skeletonDir);
430
        $this->setSkeletonDirs([$skeletonDir]);
431
        $partial = '';
432
        $partialFunctions = '';
433
        $constructor = '';
434
        $twigParameters = $parameters;
435
436 View Code Duplication
        if ($parameters['uses_author']) {
0 ignored issues
show
This code seems to be duplicated across 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...
437
            $twigParameters['type'] = 'Author';
438
            $twigParameters['pluralType'] = 'authors';
439
            $partial .= $this->render('/PagePartial.php.twig', $twigParameters);
440
            $partialFunctions .= $this->render('/PagePartialFunctions.php.twig', $twigParameters);
441
        }
442
443 View Code Duplication
        if ($parameters['uses_category']) {
0 ignored issues
show
This code seems to be duplicated across 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...
444
            $twigParameters['type'] = 'Category';
445
            $twigParameters['pluralType'] = 'categories';
446
            $partial .= $this->render('/PagePartial.php.twig', $twigParameters);
447
            $partialFunctions .= $this->render('/PagePartialFunctions.php.twig', $twigParameters);
448
            $constructor .= '$this->categories = new ArrayCollection();' . "\n";
449
        }
450
451 View Code Duplication
        if ($parameters['uses_tag']) {
0 ignored issues
show
This code seems to be duplicated across 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...
452
            $twigParameters['type'] = 'Tag';
453
            $twigParameters['pluralType'] = 'tags';
454
            $partial .= $this->render('/PagePartial.php.twig', $twigParameters);
455
            $partialFunctions .= $this->render('/PagePartialFunctions.php.twig', $twigParameters);
456
            $constructor .= '$this->tags = new ArrayCollection();' . "\n";
457
        }
458
        GeneratorUtils::replace('//%PagePartial.php.twig%', $partial, $dirPath . '/' . $this->entity . 'Page.php');
459
        GeneratorUtils::replace('//%PagePartialFunctions.php.twig%', $partialFunctions, $dirPath . '/' . $this->entity . 'Page.php');
460
        GeneratorUtils::replace('//%constructor%', $constructor, $dirPath . '/' . $this->entity . 'Page.php');
461
462
        $this->assistant->writeLine('Generating entities : <info>OK</info>');
463
    }
464
465
    /**
466
     * @param array $parameters The template parameters
467
     */
468 View Code Duplication
    public function generateFixtures(array $parameters)
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...
469
    {
470
        $relPath = '/DataFixtures/ORM/ArticleGenerator/';
471
        $sourceDir = $this->skeletonDir . $relPath;
472
        $targetDir = $this->bundle->getPath() . $relPath;
473
474
        $filename = 'ArticleFixtures.php';
475
        $this->renderSingleFile($sourceDir, $targetDir, $filename, $parameters, false, $this->entity . $filename);
476
477
        $this->assistant->writeLine('Generating fixtures : <info>OK</info>');
478
    }
479
480
    /**
481
     * Update the getPossibleChildTypes function of the parent Page classes
482
     */
483 View Code Duplication
    public function updateParentPages()
484
    {
485
        $phpCode = "            [\n";
486
        $phpCode .= "                'name' => '" . $this->entity . "OverviewPage',\n";
487
        $phpCode .= "                'class'=> '" . $this->bundle->getNamespace() . '\\Entity\\Pages\\' . $this->entity . "OverviewPage'\n";
488
        $phpCode .= '            ],' . "\n        ";
489
490
        // When there is a BehatTestPage, we should also allow the new page as sub page
491
        $behatTestPage = $this->bundle->getPath() . '/Entity/Pages/BehatTestPage.php';
492
        if (file_exists($behatTestPage)) {
493
            $this->parentPages[] = $behatTestPage;
494
        }
495
496
        foreach ($this->parentPages as $file) {
497
            $data = file_get_contents($file);
498
            $data = preg_replace(
499
                '/(function\s*getPossibleChildTypes\s*\(\)\s*\{\s*)(return\s*\[|return\s*array\()/',
500
                "$1$2\n$phpCode",
501
                $data
502
            );
503
            file_put_contents($file, $data);
504
        }
505
    }
506
}
507