Passed
Pull Request — master (#6798)
by Zacharias
12:59
created

GH4252Resident::getCity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\ORM\Functional\Ticket;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Doctrine\ORM\Annotation as ORM;
10
11
/**
12
 * @group GH-4252
13
 */
14
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...
15
{
16
    protected function setUp() : void
17
    {
18
        parent::setUp();
19
20
        $this->schemaTool->createSchema(array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
21
            $this->em->getClassMetadata(GH4252City::class),
22
            $this->em->getClassMetadata(GH4252Resident::class),
23
            $this->em->getClassMetadata(GH4252Address::class),
24
        ));
25
    }
26
27
    public function testIssue() : void
28
    {
29
        $city = new GH4252City([new GH4252Resident([new GH4252Address()])]);
30
31
        $this->em->persist($city);
32
        $this->em->flush();
33
        $this->em->clear();
34
35
        /** @var GH4252City $city */
36
        $city = $this->em->find(GH4252City::class, $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
 * @ORM\Entity
58
 */
59
class GH4252City
60
{
61
    /**
62
     * @var int
63
     * @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue
64
     */
65
    private $id;
66
67
    /**
68
     * @var bool
69
     * @ORM\Column(type="boolean")
70
     */
71
    private $flag;
72
73
    /**
74
     * @var GH4252Resident[]|Collection
75
     *
76
     * @ORM\OneToMany(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH4252Resident", mappedBy="city", cascade={"persist","refresh"})
77
     */
78
    private $residents;
79
80
    public function __construct(array $residents)
81
    {
82
        $this->residents = new ArrayCollection();
83
        foreach ($residents as $resident) {
84
            $this->residents->add($resident);
85
            $resident->setCity($this);
86
        }
87
        $this->flag = true;
88
    }
89
90
    public function getId() : int
91
    {
92
        return $this->id;
93
    }
94
95
    public function getFlag() : bool
96
    {
97
        return $this->flag;
98
    }
99
100
    public function setFlag(bool $flag) : void
101
    {
102
        $this->flag = $flag;
103
    }
104
105
    public function getResidents() : Collection
106
    {
107
        return $this->residents;
108
    }
109
}
110
111
/**
112
 * @ORM\Entity
113
 */
114
class GH4252Resident
115
{
116
    /**
117
     * @var int
118
     * @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue
119
     */
120
    private $id;
121
122
    /**
123
     * @var GH4252City
124
     * @ORM\ManyToOne(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH4252City", inversedBy="residents")
125
     */
126
    private $city;
127
128
    /**
129
     * @var bool
130
     * @ORM\Column(type="boolean")
131
     */
132
    private $flag;
133
134
    /**
135
     * @var GH4252Address[]|Collection
136
     *
137
     * @ORM\ManyToMany(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH4252Address", fetch="EXTRA_LAZY", cascade={"persist","refresh"})
138
     */
139
    private $addresses;
140
141
    public function __construct(array $addresses)
142
    {
143
        $this->addresses = new ArrayCollection();
144
        foreach ($addresses as $address) {
145
            $this->addresses->add($address);
146
        }
147
        $this->flag = true;
148
    }
149
150
    public function getId() : int
151
    {
152
        return $this->id;
153
    }
154
155
    public function getCity() : GH4252City
156
    {
157
        return $this->city;
158
    }
159
160
    public function setCity(GH4252City $city) : void
161
    {
162
        $this->city = $city;
163
    }
164
165
    public function getFlag() : bool
166
    {
167
        return $this->flag;
168
    }
169
170
    public function setFlag(bool $flag) : void
171
    {
172
        $this->flag = $flag;
173
    }
174
175
    public function getAddresses() : Collection
176
    {
177
        return $this->addresses;
178
    }
179
}
180
181
/** @ORM\Entity */
182
class GH4252Address
183
{
184
    /**
185
     * @var int
186
     * @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue
187
     */
188
    private $id;
189
190
    /**
191
     * @var bool
192
     * @ORM\Column(type="boolean")
193
     */
194
    private $flag;
195
196
    public function __construct()
197
    {
198
        $this->flag = true;
199
    }
200
201
    public function getId() : int
202
    {
203
        return $this->id;
204
    }
205
206
    public function getFlag() : bool
207
    {
208
        return $this->flag;
209
    }
210
211
    public function setFlag(bool $flag) : void
212
    {
213
        $this->flag = $flag;
214
    }
215
}
216