Completed
Pull Request — master (#2657)
by Jeroen
06:22
created

ArticleGenerator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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