Completed
Push — wip-subtree ( 04b705...405079 )
by
unknown
12:15
created

HandlesRelationsAdmin::configureShowFields()   C

Complexity

Conditions 7
Paths 18

Size

Total Lines 24
Code Lines 12

Duplication

Lines 24
Ratio 100 %

Importance

Changes 0
Metric Value
dl 24
loc 24
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 12
nc 18
nop 1
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\Bundle\CoreBundle\Admin\Traits;
14
15
use Doctrine\ORM\Mapping\ClassMetadataInfo;
16
use Blast\Bundle\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
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...
28
    {
29
        CoreAdmin::configureFormFields($mapper);
0 ignored issues
show
Bug introduced by
The method configureFormFields() cannot be called from this context as it is declared protected in class Blast\Bundle\CoreBundle\Admin\CoreAdmin.

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

If you need to make a method accessible to another context you can raise its visibility level in the defining class.

Loading history...
30
31
        // relationships that will be handled by CollectionsManager
32
        $type = 'sonata_type_collection';
33
34
        foreach ($this->formFieldDescriptions as $fieldname => $fieldDescription) {
0 ignored issues
show
Bug introduced by
The property formFieldDescriptions does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
35
            if ($fieldDescription->getType() == $type) {
36
                $this->addManagedCollections($fieldname);
0 ignored issues
show
Bug introduced by
It seems like addManagedCollections() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
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);
0 ignored issues
show
Bug introduced by
It seems like addManyToManyCollections() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
45
            }
46
        }
47
48
        if (method_exists($this, 'postConfigureFormFields')) {
49
            $this->postConfigureFormFields($mapper);
0 ignored issues
show
Bug introduced by
The method postConfigureFormFields() does not exist on Blast\Bundle\CoreBundle\...s\HandlesRelationsAdmin. Did you maybe mean configureFormFields()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
50
        }
51
    }
52
53
    /**
54
     * @param ShowMapper $mapper
55
     */
56 View Code Duplication
    protected function configureShowFields(ShowMapper $mapper)
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...
57
    {
58
        CoreAdmin::configureShowFields($mapper);
0 ignored issues
show
Bug introduced by
The method configureShowFields() cannot be called from this context as it is declared protected in class Blast\Bundle\CoreBundle\Admin\CoreAdmin.

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

If you need to make a method accessible to another context you can raise its visibility level in the defining class.

Loading history...
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) {
0 ignored issues
show
Bug introduced by
The property showFieldDescriptions does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
63
            if (in_array($fieldDescription->getType(), $types)) {
64
                $this->addManagedCollections($fieldname);
0 ignored issues
show
Bug introduced by
It seems like addManagedCollections() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
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);
0 ignored issues
show
Bug introduced by
It seems like addManyToManyCollections() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
73
            }
74
        }
75
76
        if (method_exists($this, 'postConfigureShowFields')) {
77
            $this->postConfigureShowFields($mapper);
0 ignored issues
show
Bug introduced by
The method postConfigureShowFields() does not exist on Blast\Bundle\CoreBundle\...s\HandlesRelationsAdmin. Did you maybe mean configureShowFields()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
78
        }
79
    }
80
}
81