Completed
Pull Request — wip-lisem (#49)
by
unknown
02:42
created

CoreAdmin::getLabelTranslatorStrategy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Blast Project package.
5
 *
6
 * Copyright (C) 2015-2017 Libre Informatique
7
 *
8
 * This file is licenced under the GNU LGPL v3.
9
 * For the full copyright and license information, please view the LICENSE.md
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Blast\CoreBundle\Admin;
14
15
use Sonata\AdminBundle\Datagrid\DatagridMapper;
16
use Sonata\AdminBundle\Datagrid\ListMapper;
17
use Sonata\AdminBundle\Form\FormMapper;
18
use Sonata\AdminBundle\Mapper\BaseMapper;
19
use Sonata\AdminBundle\Show\ShowMapper;
20
use Sonata\AdminBundle\Route\RouteCollection;
21
use Sonata\AdminBundle\Admin\AbstractAdmin as SonataAdmin;
22
use Sonata\DoctrineORMAdminBundle\Admin\FieldDescription;
23
use Blast\CoreBundle\Tools\Reflection\ClassAnalyzer;
24
use Blast\CoreBundle\Admin\Traits\CollectionsManager;
25
use Blast\CoreBundle\Admin\Traits\Mapper;
26
use Blast\CoreBundle\Admin\Traits\Templates;
27
use Blast\CoreBundle\Admin\Traits\PreEvents;
28
use Blast\CoreBundle\Admin\Traits\ManyToManyManager;
29
use Blast\CoreBundle\Admin\Traits\Actions;
30
use Blast\CoreBundle\Admin\Traits\ListActions;
31
use Blast\CoreBundle\CodeGenerator\CodeGeneratorRegistry;
32
use Symfony\Component\PropertyAccess\PropertyAccess;
33
34
abstract class CoreAdmin extends SonataAdmin implements \JsonSerializable
35
{
36
    use CollectionsManager,
37
        ManyToManyManager,
38
        Mapper,
39
        Templates,
40
        PreEvents,
41
        Actions,
42
        ListActions
43
    ;
44
45
    protected $extraTemplates = [];
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function getLabelTranslatorStrategy()
51
    {
52
        $this->labelTranslatorStrategy->setAdmin($this);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Sonata\AdminBundle\Trans...slatorStrategyInterface as the method setAdmin() does only exist in the following implementations of said interface: Blast\CoreBundle\Transla...LabelTranslatorStrategy.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
53
54
        return $this->labelTranslatorStrategy;
55
    }
56
57
    /**
58
     * Configure routes for list actions.
59
     *
60
     * @param RouteCollection $collection
61
     */
62
    protected function configureRoutes(RouteCollection $collection)
63
    {
64
        parent::configureRoutes($collection);
65
        $collection->add('duplicate', $this->getRouterIdParameter() . '/duplicate');
66
        $collection->add('generateEntityCode');
67
    }
68
69 View Code Duplication
    public function getBaseRouteName()
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...
70
    {
71
        $configuredBaseRoute = $this->getBaseRouteMapping();
72
73
        if (count($configuredBaseRoute) > 0) {
74
            $this->cachedBaseRouteName = null;
0 ignored issues
show
Bug introduced by
The property cachedBaseRouteName cannot be accessed from this context as it is declared private in class Sonata\AdminBundle\Admin\AbstractAdmin.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
75
            if (isset($configuredBaseRoute['name']) && $this->baseRouteName === null) {
76
                $this->baseRouteName = $configuredBaseRoute['name'];
77
            }
78
        }
79
80
        return parent::getBaseRouteName();
81
    }
82
83 View Code Duplication
    public function getBaseRoutePattern()
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...
84
    {
85
        $configuredBaseRoute = $this->getBaseRouteMapping();
86
87
        if (count($configuredBaseRoute) > 0) {
88
            $this->cachedBaseRoutePattern = null;
0 ignored issues
show
Bug introduced by
The property cachedBaseRoutePattern cannot be accessed from this context as it is declared private in class Sonata\AdminBundle\Admin\AbstractAdmin.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
89
            if (isset($configuredBaseRoute['pattern']) && $this->baseRoutePattern === null) {
90
                $this->baseRoutePattern = $configuredBaseRoute['pattern'];
91
            }
92
        }
93
94
        return parent::getBaseRoutePattern();
95
    }
96
97
    public function getFormTheme()
98
    {
99
        return array_merge($this->formTheme, $this->getFormThemeMapping());
100
    }
101
102
    /**
103
     * @param DatagridMapper $mapper
104
     */
105
    protected function configureDatagridFilters(DatagridMapper $mapper)
106
    {
107
        if (!$this->configureMapper($mapper)) {
108
            $this->fallbackConfiguration($mapper, __FUNCTION__);
109
        }
110
    }
111
112
    /**
113
     * @param ListMapper $mapper
114
     */
115
    protected function configureListFields(ListMapper $mapper)
116
    {
117
        if (!$this->configureMapper($mapper)) {
118
            $this->fallbackConfiguration($mapper, __FUNCTION__);
119
        }
120
    }
121
122
    /**
123
     * @param FormMapper $mapper
124
     */
125
    protected function configureFormFields(FormMapper $mapper)
126
    {
127
        if (!$this->configureMapper($mapper)) {
128
            $this->fallbackConfiguration($mapper, __FUNCTION__);
129
        }
130
    }
131
132
    /**
133
     * @param ShowMapper $mapper
134
     */
135
    protected function configureShowFields(ShowMapper $mapper)
136
    {
137
        if (!$this->configureMapper($mapper)) {
138
            $this->fallbackConfiguration($mapper, __FUNCTION__);
139
        }
140
    }
141
142
    /**
143
     * @param BaseMapper $mapper
144
     */
145
    protected function fixShowRoutes(BaseMapper $mapper)
0 ignored issues
show
Unused Code introduced by
The parameter $mapper is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
146
    {
147
        foreach (['getShow', 'getList'] as $fct) {
148
            foreach ($this->$fct()->getElements() as $field) {
149
                if ($field instanceof FieldDescription) {
150
                    $options = $field->getOptions();
151
                    if ($options['route']['name'] != 'edit') {
152
                        continue;
153
                    }
154
155
                    $options['route']['name'] = 'show';
156
                    $field->setOptions($options);
157
                }
158
            }
159
        }
160
161
        return $this;
162
    }
163
164
    protected function getCurrentComposition()
165
    {
166
        // traits of the current Entity
167
        $classes = ClassAnalyzer::getTraits($this->getClass());
168
        // inheritance of the current Entity
169
        foreach (array_reverse([$this->getClass()] + class_parents($this->getClass())) as $class) {
170
            $classes[] = $class;
171
        }
172
        // inheritance of the current Admin
173
        foreach (array_reverse([$this->getOriginalClass()] + $this->getParentClasses()) as $admin) {
174
            $classes[] = $admin;
175
        }
176
177
        return $classes;
178
    }
179
180
    private function fallbackConfiguration(BaseMapper $mapper, $function)
181
    {
182
        // fallback
183
        $rm = new \ReflectionMethod($this->getParentClass(), $function);
184
        if ($rm->class == $this->getParentClass()) {
185
            $this->configureFields($function, $mapper, $this->getParentClass());
186
        }
187
    }
188
189
    /**
190
     * Returns the level of depth of an array.
191
     *
192
     * @param array $array
193
     * @param int   $level : do not use, just used for recursivity
194
     *
195
     * @return int : depth
196
     */
197
    private static function arrayDepth($array, $level = 0)
198
    {
199
        if (!$array) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $array of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
200
            return $level;
201
        }
202
203
        if (!is_array($array)) {
204
            return $level;
205
        }
206
207
        ++$level;
208
        foreach ($array as $key => $value) {
209
            if (is_array($value)) {
210
                $level = $level < self::arrayDepth($value, $level) ? self::arrayDepth($value, $level) : $level;
211
            }
212
        }
213
214
        return $level;
215
    }
216
217
    protected function getOriginalClass()
218
    {
219
        return get_called_class();
220
    }
221
222
    protected function getParentClasses()
223
    {
224
        return class_parents($this->getOriginalClass());
225
    }
226
227
    protected function getParentClass()
228
    {
229
        return get_parent_class($this->getOriginalClass());
230
    }
231
232
    protected function getGrandParentClass()
233
    {
234
        return get_parent_class(get_parent_class($this->getOriginalClass()));
235
    }
236
237
    /**
238
     * @param string $view     'list', 'show', 'form', etc
239
     * @param string $template template name
240
     */
241
    public function addExtraTemplate($view, $template)
242
    {
243
        if (empty($this->extraTemplates[$view])) {
244
            $this->extraTemplates[$view] = [];
245
        }
246
        if (!in_array($template, $this->extraTemplates[$view])) {
247
            $this->extraTemplates[$view][] = $template;
248
        }
249
    }
250
251
    /**
252
     * @param string $view 'list', 'show', 'form', etc
253
     *
254
     * @return array array of template names
255
     */
256
    public function getExtraTemplates($view)
257
    {
258
        if (empty($this->extraTemplates[$view])) {
259
            $this->extraTemplates[$view] = [];
260
        }
261
262
        return $this->extraTemplates[$view];
263
    }
264
265
    /**
266
     * @param string $view 'list', 'show', 'form', etc
267
     * @param array  $link link (array keys should be: 'label', 'url', 'class', 'title')
268
     */
269
    public function addHelperLink($view, $link)
270
    {
271
        if (empty($this->helperLinks[$view])) {
272
            $this->helperLinks[$view] = [];
273
        }
274
275
        // Do not add links without URL
276
        if (empty($link['url'])) {
277
            return;
278
        }
279
280
        // Do not add two links with the same URL
281
        foreach ($this->helperLinks[$view] as $l) {
282
            if ($l['url'] == $link['url']) {
283
                return;
284
            }
285
        }
286
287
        $this->helperLinks[$view][] = $link;
288
    }
289
290
    /**
291
     * @param string $view 'list', 'show', 'form', etc
292
     *
293
     * @return array array of links (each link is an array with keys 'label', 'url', 'class' and 'title')
294
     */
295
    public function getHelperLinks($view)
296
    {
297
        if (empty($this->helperLinks[$view])) {
298
            $this->helperLinks[$view] = [];
299
        }
300
301
        return $this->helperLinks[$view];
302
    }
303
304
    /**
305
     * Checks if a Bundle is installed.
306
     *
307
     * @param string $bundle Bundle name or class FQN
308
     */
309
    public function bundleExists($bundle)
310
    {
311
        $kernelBundles = $this->getConfigurationPool()->getContainer()->getParameter('kernel.bundles');
312
        if (array_key_exists($bundle, $kernelBundles)) {
313
            return true;
314
        }
315
        if (in_array($bundle, $kernelBundles)) {
316
            return true;
317
        }
318
319
        return false;
320
    }
321
322
    /**
323
     * Rename a form tab after form fields have been configured.
324
     *
325
     * TODO: groups of the renamed tab are still prefixed with the old tab name
326
     *
327
     * @param type $tabName    the name of the tab to be renamed
328
     * @param type $newTabName the new name for the tab
329
     */
330 View Code Duplication
    public function renameFormTab($tabName, $newTabName, $keepOrder = true)
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...
331
    {
332
        $tabs = $this->getFormTabs();
333
334
        if (!$tabs) {
335
            return;
336
        }
337
338
        if (!isset($tabs[$tabName])) {
339
            throw new \Exception(sprintf('Tab %s does not exist.', $tabName));
340
        }
341
        if (isset($tabs[$newTabName])) {
342
            return;
343
        }
344
345
        if ($keepOrder) {
346
            $keys = array_keys($tabs);
347
            $keys[array_search($tabName, $keys)] = $newTabName;
348
            $tabs = array_combine($keys, $tabs);
349
        } else {
350
            $tabs[$newTabName] = $tabs[$tabName];
351
            unset($tabs[$tabName]);
352
        }
353
354
        $this->setFormTabs($tabs);
0 ignored issues
show
Bug introduced by
It seems like $tabs defined by $this->getFormTabs() on line 332 can also be of type boolean; however, Sonata\AdminBundle\Admin...actAdmin::setFormTabs() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
355
    }
356
357
    /**
358
     * Rename a show tab after show fields have been configured.
359
     *
360
     * TODO: groups of the renamed tab are still prefixed with the old tab name
361
     *
362
     * @param type $tabName    the name of the tab to be renamed
363
     * @param type $newTabName the new name for the tab
364
     */
365 View Code Duplication
    public function renameShowTab($tabName, $newTabName, $keepOrder = true)
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...
366
    {
367
        $tabs = $this->getShowTabs();
368
369
        if (!$tabs) {
370
            return;
371
        }
372
373
        if (!isset($tabs[$tabName])) {
374
            throw new \Exception(sprintf('Tab %s does not exist.', $tabName));
375
        }
376
        if (isset($tabs[$newTabName])) {
377
            return;
378
        }
379
380
        if ($keepOrder) {
381
            $keys = array_keys($tabs);
382
            $keys[array_search($tabName, $keys)] = $newTabName;
383
            $tabs = array_combine($keys, $tabs);
384
        } else {
385
            $tabs[$newTabName] = $tabs[$tabName];
386
            unset($tabs[$tabName]);
387
        }
388
389
        $this->setShowTabs($tabs);
0 ignored issues
show
Bug introduced by
It seems like $tabs defined by $this->getShowTabs() on line 367 can also be of type boolean; however, Sonata\AdminBundle\Admin...actAdmin::setShowTabs() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
390
    }
391
392
    /**
393
     * Rename a form group.
394
     *
395
     * @param string $group        the old group name
396
     * @param string $tab          the tab the group belongs to
397
     * @param string $newGroupName the new group name
398
     *
399
     * @return self
400
     */
401
    public function renameFormGroup($group, $tab, $newGroupName)
402
    {
403
        $groups = $this->getFormGroups();
404
405
        // When the default tab is used, the tabname is not prepended to the index in the group array
406
        if ($tab !== 'default') {
407
            $group = $tab . '.' . $group;
408
        }
409
        $newGroup = ($tab !== 'default') ? $tab . '.' . $newGroupName : $newGroupName;
410
411
        if (isset($groups[$newGroup])) {
412
            throw new \Exception(sprintf('%s form group already exists.', $newGroup));
413
        }
414
        if (!array_key_exists($group, $groups)) {
415
            throw new \Exception(sprintf('form group « %s » doesn\'t exist.', $group));
416
        }
417
418
        $groups[$newGroup] = $groups[$group];
419
        $groups[$newGroup]['name'] = $newGroupName;
420
        unset($groups[$group]);
421
422
        $tabs = $this->getFormTabs();
423
        $key = array_search($group, $tabs[$tab]['groups']);
424
425
        if (false !== $key) {
426
            $tabs[$tab]['groups'][$key] = $newGroup;
427
        }
428
429
        $this->setFormTabs($tabs);
0 ignored issues
show
Bug introduced by
It seems like $tabs defined by $this->getFormTabs() on line 422 can also be of type boolean; however, Sonata\AdminBundle\Admin...actAdmin::setFormTabs() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
430
        $this->setFormGroups($groups);
0 ignored issues
show
Bug introduced by
It seems like $groups defined by $this->getFormGroups() on line 403 can also be of type boolean; however, Sonata\AdminBundle\Admin...tAdmin::setFormGroups() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
431
432
        return $this;
433
    }
434
435
    /**
436
     * Removes tab in current form Mapper.
437
     *
438
     * @param string|array $tabNames name or array of names of tabs to be removed
439
     * @param FormMapper   $mapper   Sonata Admin form mapper
440
     */
441
    public function removeTab($tabNames, $mapper)
442
    {
443
        $currentTabs = $this->getFormTabs();
444
        foreach ($currentTabs as $k => $item) {
0 ignored issues
show
Bug introduced by
The expression $currentTabs of type array|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
445
            if (is_array($tabNames) && in_array($item['name'], $tabNames) || !is_array($tabNames) && $item['name'] === $tabNames) {
446
                foreach ($item['groups'] as $groupName) {
447
                    $this->removeAllFieldsFromFormGroup($groupName, $mapper);
448
                }
449
                unset($currentTabs[$k]);
450
            }
451
        }
452
        $this->setFormTabs($currentTabs);
0 ignored issues
show
Bug introduced by
It seems like $currentTabs defined by $this->getFormTabs() on line 443 can also be of type boolean; however, Sonata\AdminBundle\Admin...actAdmin::setFormTabs() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
453
    }
454
455
    /**
456
     * Removes all fields from form groups and remove them from mapper.
457
     *
458
     * @param string     $groupName Name of the group to remove
459
     * @param FormMapper $mapper    Sonata Admin form mapper
460
     */
461
    public function removeAllFieldsFromFormGroup($groupName, $mapper)
462
    {
463
        $formGroups = $this->getFormGroups();
464
        foreach ($formGroups as $name => $formGroup) {
0 ignored issues
show
Bug introduced by
The expression $formGroups of type array|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
465
            if ($name === $groupName) {
466
                foreach ($formGroups[$name]['fields'] as $key => $field) {
467
                    $mapper->remove($key);
468
                }
469
            }
470
        }
471
    }
472
473
    public function jsonSerialize()
474
    {
475
        $propertiesToShow = [
476
            'baseRouteName',
477
            'baseRoutePattern',
478
            'extraTemplates',
479
            'listFieldDescriptions',
480
            'showFieldDescriptions',
481
            'formFieldDescriptions',
482
            'filterFieldDescriptions',
483
            'maxPerPage',
484
            'maxPageLinks',
485
            'classnameLabel',
486
            'translationDomain',
487
            'formOptions',
488
            'datagridValues',
489
            'perPageOptions',
490
            'pagerType',
491
            'code',
492
            'label',
493
            'routes',
494
            'subject',
495
            'children',
496
            'parent',
497
            'baseCodeRoute',
498
            'uniqid',
499
            'extensions',
500
            'class',
501
            'subClasses',
502
            'list',
503
            'show',
504
            'form',
505
            'filter',
506
            'formGroups',
507
            'formTabs',
508
            'showGroups',
509
            'showTabs',
510
            'managedCollections',
511
            'helperLinks',
512
            'titles',
513
        ];
514
515
        $properties = [];
516
        foreach ($this as $key => $value) {
0 ignored issues
show
Bug introduced by
The expression $this of type this<Blast\CoreBundle\Admin\CoreAdmin> is not traversable.
Loading history...
517
            if (in_array($key, $propertiesToShow)) {
518
                $properties[$key] = $value;
519
            }
520
        }
521
522
        return $properties;
523
    }
524
525
    /**
526
     * {@inheritdoc}
527
     */
528
    public function prePersist($object)
529
    {
530
        parent::prePersist($object);
531
532
        $hasCodeGenerator = CodeGeneratorRegistry::hasGeneratorForClass(get_class($object));
533
        if ($hasCodeGenerator) {
534
            $accessor = PropertyAccess::createPropertyAccessor();
535
            foreach (CodeGeneratorRegistry::getCodeGenerators(get_class($object)) as $name => $generator) {
536
                $accessor->setValue($object, $name, $generator->generate($object));
537
            }
538
        }
539
    }
540
}
541