Completed
Push — master ( 719a5f...bedda6 )
by Kristof
53:09 queued 32:05
created

ArticleGenerator::generateRouting()   B

Complexity

Conditions 6
Paths 17

Size

Total Lines 36

Duplication

Lines 10
Ratio 27.78 %

Importance

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