Completed
Push — master ( 1e3fe5...2c0ff3 )
by
unknown
02:52
created

src/Admin/Traits/HandlesRelationsAdmin.php (2 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
/*
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\Traits;
14
15
use Doctrine\ORM\Mapping\ClassMetadataInfo;
16
use Blast\CoreBundle\Admin\CoreAdmin;
17
use Sonata\AdminBundle\Form\FormMapper;
18
use Sonata\AdminBundle\Show\ShowMapper;
19
20
trait HandlesRelationsAdmin
21
{
22
    use Base;
23
24
    /**
25
     * @param FormMapper $mapper
26
     */
27 View Code Duplication
    protected function configureFormFields(FormMapper $mapper)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
    {
29
        CoreAdmin::configureFormFields($mapper);
30
31
        // relationships that will be handled by CollectionsManager
32
        $type = 'sonata_type_collection';
33
34
        foreach ($this->formFieldDescriptions as $fieldname => $fieldDescription) {
35
            if ($fieldDescription->getType() == $type) {
36
                $this->addManagedCollections($fieldname);
37
            }
38
        }
39
40
        // relationships that will be handled by ManyToManyManager
41
        foreach ($this->formFieldDescriptions as $fieldname => $fieldDescription) {
42
            $mapping = $fieldDescription->getAssociationMapping();
43
            if ($mapping['type'] == ClassMetadataInfo::MANY_TO_MANY && !$mapping['isOwningSide']) {
44
                $this->addManyToManyCollections($fieldname);
45
            }
46
        }
47
48
        if (method_exists($this, 'postConfigureFormFields')) {
49
            $this->postConfigureFormFields($mapper);
50
        }
51
    }
52
53
    /**
54
     * @param ShowMapper $mapper
55
     */
56 View Code Duplication
    protected function configureShowFields(ShowMapper $mapper)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
    {
58
        CoreAdmin::configureShowFields($mapper);
59
60
        // relationships that will be handled by CollectionsManager
61
        $types = ['sonata_type_collection', 'orm_one_to_many'];
62
        foreach ($this->showFieldDescriptions as $fieldname => $fieldDescription) {
63
            if (in_array($fieldDescription->getType(), $types)) {
64
                $this->addManagedCollections($fieldname);
65
            }
66
        }
67
68
        // relationships that will be handled by ManyToManyManager
69
        foreach ($this->showFieldDescriptions as $fieldname => $fieldDescription) {
70
            $mapping = $fieldDescription->getAssociationMapping();
71
            if ($mapping['type'] == ClassMetadataInfo::MANY_TO_MANY && !$mapping['isOwningSide']) {
72
                $this->addManyToManyCollections($fieldname);
73
            }
74
        }
75
76
        if (method_exists($this, 'postConfigureShowFields')) {
77
            $this->postConfigureShowFields($mapper);
78
        }
79
    }
80
}
81