Completed
Push — 5.0 ( a48099...63af02 )
by
unknown
11:33
created

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