Failed Conditions
Pull Request — develop (#1577)
by Marco
66:01
created

DDC964User::loadMetadata()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 63
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 63
rs 9.4347
c 0
b 0
f 0
cc 1
eloc 40
nc 1
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\Models\DDC964;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\DBAL\Types\Type;
9
use Doctrine\ORM\Annotation as ORM;
10
use Doctrine\ORM\Mapping;
11
12
/**
13
 * @ORM\MappedSuperclass
14
 */
15
class DDC964User
16
{
17
    /**
18
     * @ORM\Id
19
     * @ORM\GeneratedValue
20
     * @ORM\Column(type="integer", name="user_id")
21
     */
22
    protected $id;
23
24
    /**
25
     * @ORM\Column(name="user_name", nullable=true, unique=false, length=250)
26
     */
27
    protected $name;
28
29
    /**
30
     * @var ArrayCollection
31
     *
32
     * @ORM\ManyToMany(targetEntity="DDC964Group", inversedBy="users", cascade={"persist"})
33
     * @ORM\JoinTable(name="ddc964_users_groups",
34
     *  joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
35
     *  inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
36
     * )
37
     */
38
    protected $groups;
39
40
    /**
41
     * @var DDC964Address
42
     *
43
     * @ORM\ManyToOne(targetEntity="DDC964Address", cascade={"persist"})
44
     * @ORM\JoinColumn(name="address_id", referencedColumnName="id")
45
     */
46
    protected $address;
47
48
    /**
49
     * @param string $name
50
     */
51
    public function __construct($name = null)
52
    {
53
        $this->name     = $name;
54
        $this->groups   = new ArrayCollection;
55
    }
56
57
    /**
58
     * @return int
59
     */
60
    public function getId()
61
    {
62
        return $this->id;
63
    }
64
65
    /**
66
     * @return string
67
     */
68
    public function getName()
69
    {
70
        return $this->name;
71
    }
72
73
    /**
74
     * @param string $name
75
     */
76
    public function setName($name)
77
    {
78
        $this->name = $name;
79
    }
80
81
    /**
82
     * @param DDC964Group $group
83
     */
84
    public function addGroup(DDC964Group $group)
85
    {
86
        $this->groups->add($group);
87
        $group->addUser($this);
88
    }
89
90
    /**
91
     * @return ArrayCollection
92
     */
93
    public function getGroups()
94
    {
95
        return $this->groups;
96
    }
97
98
    /**
99
     * @return DDC964Address
100
     */
101
    public function getAddress()
102
    {
103
        return $this->address;
104
    }
105
106
    /**
107
     * @param DDC964Address $address
108
     */
109
    public function setAddress(DDC964Address $address)
110
    {
111
        $this->address = $address;
112
    }
113
114
    public static function loadMetadata(Mapping\ClassMetadata $metadata)
115
    {
116
        $fieldMetadata = new Mapping\FieldMetadata('id');
117
        $fieldMetadata->setType(Type::getType('integer'));
118
        $fieldMetadata->setColumnName('user_id');
119
        $fieldMetadata->setPrimaryKey(true);
120
121
        $metadata->addProperty($fieldMetadata);
122
123
        $fieldMetadata = new Mapping\FieldMetadata('name');
124
        $fieldMetadata->setType(Type::getType('string'));
125
        $fieldMetadata->setLength(250);
126
        $fieldMetadata->setColumnName('user_name');
127
        $fieldMetadata->setNullable(true);
128
        $fieldMetadata->setUnique(false);
129
130
        $metadata->addProperty($fieldMetadata);
131
132
        $joinColumns = [];
133
134
        $joinColumn = new Mapping\JoinColumnMetadata();
135
136
        $joinColumn->setColumnName('address_id');
137
        $joinColumn->setReferencedColumnName('id');
138
139
        $joinColumns[] = $joinColumn;
140
141
        $association = new Mapping\ManyToOneAssociationMetadata('address');
142
143
        $association->setJoinColumns($joinColumns);
144
        $association->setTargetEntity('DDC964Address');
145
        $association->setCascade(['persist']);
146
147
        $metadata->addProperty($association);
148
149
        $joinTable = new Mapping\JoinTableMetadata();
150
        $joinTable->setName('ddc964_users_groups');
151
152
        $joinColumn = new Mapping\JoinColumnMetadata();
153
154
        $joinColumn->setColumnName('user_id');
155
        $joinColumn->setReferencedColumnName('id');
156
157
        $joinTable->addJoinColumn($joinColumn);
158
159
        $joinColumn = new Mapping\JoinColumnMetadata();
160
161
        $joinColumn->setColumnName('group_id');
162
        $joinColumn->setReferencedColumnName('id');
163
164
        $joinTable->addInverseJoinColumn($joinColumn);
165
166
        $association = new Mapping\ManyToManyAssociationMetadata('groups');
167
168
        $association->setJoinTable($joinTable);
169
        $association->setTargetEntity('DDC964Group');
170
        $association->setInversedBy('users');
171
        $association->setCascade(['persist']);
172
173
        $metadata->addProperty($association);
174
175
        $metadata->setIdGeneratorType(Mapping\GeneratorType::AUTO);
0 ignored issues
show
Bug introduced by
The method setIdGeneratorType() does not seem to exist on object<Doctrine\ORM\Mapping\ClassMetadata>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
176
    }
177
}
178