Failed Conditions
Pull Request — master (#6798)
by Zacharias
05:19
created

GH4252City::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
introduced by
Missing declare(strict_types = 1).
Loading history...
2
3
namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
0 ignored issues
show
introduced by
Type Doctrine\ORM\Mapping (as ORM) is not used in this file.
Loading history...
7
8
/**
9
 * @group GH-4252
10
 */
11
class GH4252Test extends \Doctrine\Tests\OrmFunctionalTestCase
0 ignored issues
show
introduced by
Class \Doctrine\Tests\OrmFunctionalTestCase should not be referenced via a fully qualified name, but via a use statement.
Loading history...
12
{
13
    /**
14
     * {@inheritDoc}
15
     */
16
    protected function setup()
17
    {
18
        parent::setup();
19
20
        $this->_schemaTool->createSchema(array(
0 ignored issues
show
Bug introduced by
The property _schemaTool does not exist on Doctrine\Tests\ORM\Functional\Ticket\GH4252Test. Did you mean schemaTool?
Loading history...
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
21
            $this->_em->getClassMetadata(__NAMESPACE__ . '\\GH4252City'),
0 ignored issues
show
Bug Best Practice introduced by
The property _em does not exist on Doctrine\Tests\ORM\Functional\Ticket\GH4252Test. Did you maybe forget to declare it?
Loading history...
22
            $this->_em->getClassMetadata(__NAMESPACE__ . '\\GH4252Resident'),
23
            $this->_em->getClassMetadata(__NAMESPACE__ . '\\GH4252Address'),
24
        ));
25
    }
26
27
    public function testIssue()
28
    {
29
        $city = new GH4252City([new GH4252Resident([new GH4252Address()])]);
30
31
        $this->_em->persist($city);
0 ignored issues
show
Bug Best Practice introduced by
The property _em does not exist on Doctrine\Tests\ORM\Functional\Ticket\GH4252Test. Did you maybe forget to declare it?
Loading history...
32
        $this->_em->flush();
33
        $this->_em->clear();
34
35
        /** @var GH4252City $city */
36
        $city = $this->_em->find(__NAMESPACE__ . '\\GH4252City', $city->getId());
37
        $city->setFlag(false);
38
        /** @var GH4252Resident $resident */
39
        $resident = $city->getResidents()->first();
40
        $resident->setFlag(false);
41
        /** @var GH4252Address $address */
42
        $address = $resident->getAddresses()->first();
43
        $address->setFlag(false);
44
45
        $this->_em->refresh($city);
46
47
        $resident = $city->getResidents()->first();
48
        $address = $resident->getAddresses()->first();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
49
50
        $this->assertTrue($city->getFlag());
51
        $this->assertTrue($resident->getFlag());
52
        $this->assertTrue($address->getFlag());
53
    }
54
}
55
56
/**
57
 * @Entity
58
 */
59
class GH4252City
60
{
61
    /** @Id @Column(type="integer") @GeneratedValue */
62
    private $id;
63
64
    /**
65
     * @var bool
66
     * @Column(type="boolean")
67
     */
68
    private $flag;
69
70
    /**
71
     * @var GH4252Resident[]|\Doctrine\Common\Collections\Collection
0 ignored issues
show
introduced by
Class \Doctrine\Common\Collections\Collection should not be referenced via a fully qualified name, but via a use statement.
Loading history...
72
     *
73
     * @OneToMany(targetEntity="GH4252Resident", mappedBy="city", cascade={"persist","refresh"})
74
     */
75
    private $residents;
76
77
    /** Constructor */
78
    public function __construct(array $residents)
79
    {
80
        $this->residents = new ArrayCollection();
81
        foreach ($residents as $resident) {
82
            $this->residents->add($resident);
83
            $resident->setCity($this);
84
        }
85
        $this->flag = true;
86
    }
87
88
    public function getId()
89
    {
90
        return $this->id;
91
    }
92
93
    public function getFlag()
94
    {
95
        return $this->flag;
96
    }
97
98
    public function setFlag($flag)
99
    {
100
        $this->flag = $flag;
101
    }
102
103
    public function getResidents()
104
    {
105
        return $this->residents;
106
    }
107
}
108
109
/**
110
 * @Entity
111
 */
112
class GH4252Resident
113
{
114
    /** @Id @Column(type="integer") @GeneratedValue */
115
    private $id;
116
117
    /**
118
     * @var GH4252City
119
     * @ManyToOne(targetEntity="GH4252City", inversedBy="residents")
120
     */
121
    private $city;
122
123
    /**
124
     * @var bool
125
     * @Column(type="boolean")
126
     */
127
    private $flag;
128
129
    /**
130
     * @var GH4252Address[]|\Doctrine\Common\Collections\Collection
0 ignored issues
show
introduced by
Class \Doctrine\Common\Collections\Collection should not be referenced via a fully qualified name, but via a use statement.
Loading history...
131
     *
132
     * @ManyToMany(targetEntity="GH4252Address", fetch="EXTRA_LAZY", cascade={"persist","refresh"})
133
     */
134
    private $addresses;
135
136
    /** Constructor */
137
    public function __construct(array $addresses)
138
    {
139
        $this->addresses = new ArrayCollection();
140
        foreach ($addresses as $address) {
141
            $this->addresses->add($address);
142
        }
143
        $this->flag = true;
144
    }
145
146
    public function getId()
147
    {
148
        return $this->id;
149
    }
150
151
    public function getCity()
152
    {
153
        return $this->city;
154
    }
155
156
    public function setCity(GH4252City $city)
157
    {
158
        $this->city = $city;
159
    }
160
161
    public function getFlag()
162
    {
163
        return $this->flag;
164
    }
165
166
    public function setFlag($flag)
167
    {
168
        $this->flag = $flag;
169
    }
170
171
    public function getAddresses()
172
    {
173
        return $this->addresses;
174
    }
175
}
176
177
/** @Entity */
178
class GH4252Address
179
{
180
    /** @Id @Column(type="integer") @GeneratedValue */
181
    private $id;
182
183
    /**
184
     * @var bool
185
     * @Column(type="boolean")
186
     */
187
    private $flag;
188
189
    /** Constructor */
190
    public function __construct()
191
    {
192
        $this->flag = true;
193
    }
194
195
    public function getId()
196
    {
197
        return $this->id;
198
    }
199
200
    public function getFlag()
201
    {
202
        return $this->flag;
203
    }
204
205
    public function setFlag($flag)
206
    {
207
        $this->flag = $flag;
208
    }
209
}
210