Test Failed
Push — master ( cc2916...fd3cd2 )
by Alexey
03:38
created

User::getNewSubscriptionEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Skobkin\Bundle\PointToolsBundle\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
7
8
/**
9
 * @ORM\Table(name="users", schema="users")
10
 * @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\UserRepository")
11
 * @ORM\HasLifecycleCallbacks
12
 */
13
class User
14
{
15
    /**
16
     * @var int
17
     *
18
     * @ORM\Column(name="id", type="integer")
19
     * @ORM\Id
20
     */
21
    private $id;
22
23
    /**
24
     * @var string
25
     *
26
     * @ORM\Column(name="login", type="string", length=255, nullable=false)
27
     */
28
    private $login;
29
30
    /**
31
     * @var string
32
     *
33
     * @ORM\Column(name="name", type="string", length=255, nullable=true)
34
     */
35
    private $name;
36
37
    /**
38
     * @var \DateTime
39
     *
40
     * @ORM\Column(name="created_at", type="datetime")
41
     */
42
    private $createdAt;
43
44
    /**
45
     * @var \DateTime
46
     *
47
     * @ORM\Column(name="updated_at", type="datetime", nullable=true)
48
     */
49
    private $updatedAt;
50
51
    /**
52
     * @var Subscription|ArrayCollection
53
     *
54
     * @ORM\OneToMany(targetEntity="Subscription", mappedBy="author", fetch="EXTRA_LAZY")
55
     */
56
    private $subscribers;
57
58
    /**
59
     * @var Subscription|ArrayCollection
60
     *
61
     * @ORM\OneToMany(targetEntity="Subscription", mappedBy="subscriber", fetch="EXTRA_LAZY")
62
     */
63
    private $subscriptions;
64
65
    /**
66
     * @var SubscriptionEvent|ArrayCollection
67
     * @ORM\OneToMany(targetEntity="SubscriptionEvent", mappedBy="author", fetch="EXTRA_LAZY")
68
     */
69
    private $newSubscriberEvents;
70
71
72
    /**
73
     * @param int $id
74
     * @param string $login
75
     * @param string $name
76
     */
77
    public function __construct(int $id, string $login = null, string $name = null)
78
    {
79
        $this->id = $id;
80
        $this->login = $login;
81
        $this->name = $name;
82
83
        $this->subscribers = new ArrayCollection();
84
        $this->subscriptions = new ArrayCollection();
85
        $this->newSubscriberEvents = new ArrayCollection();
86 2
    }
87
88 2
    /**
89 2
     * @ORM\PrePersist
90 2
     */
91
    public function onCreate()
92 2
    {
93 2
        if (!$this->createdAt) {
94 2
            $this->createdAt = new \DateTime();
95 2
        }
96 2
    }
97
98
    /**
99
     * @ORM\PreUpdate
100
     */
101
    public function preUpdate()
102
    {
103
        $this->updatedAt = new \DateTime();
104
    }
105
106
    public function getId(): int
107
    {
108
        return $this->id;
109
    }
110
111
    /**
112
     * @param string $login
113
     * @return User
114
     */
115
    public function setLogin(string $login): self
116
    {
117
        $this->login = $login;
118
119
        return $this;
120
    }
121 3
122
    public function getLogin(): string
123 3
    {
124
        return $this->login;
125
    }
126
127
    public function setName(string $name): self
128
    {
129
        $this->name = $name;
130
131
        return $this;
132
    }
133
134
    public function getName(): string
135
    {
136
        return $this->name;
137
    }
138
139
    public function addSubscriber(Subscription $subscribers): self
140
    {
141
        $this->subscribers[] = $subscribers;
142
143
        return $this;
144
    }
145 2
146
    public function removeSubscriber(Subscription $subscribers)
147 2
    {
148
        $this->subscribers->removeElement($subscribers);
0 ignored issues
show
Bug introduced by
The method removeElement does only exist in Doctrine\Common\Collections\ArrayCollection, but not in Skobkin\Bundle\PointTool...dle\Entity\Subscription.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
149 2
    }
150
151
    /**
152
     * @return Subscription[]|ArrayCollection
153
     */
154
    public function getSubscribers()
155
    {
156
        return $this->subscribers;
157 9
    }
158
159 9
    /**
160
     * @return Subscription[]|ArrayCollection
161
     */
162
    public function getSubscriptions()
163
    {
164
        return $this->subscriptions;
165
    }
166
167
    public function addNewSubscriberEvent(SubscriptionEvent $newSubscriberEvents): self
168
    {
169
        $this->newSubscriberEvents[] = $newSubscriberEvents;
170
171
        return $this;
172
    }
173
174
    /**
175
     * @return SubscriptionEvent[]|ArrayCollection
176
     */
177
    public function getNewSubscriberEvents()
178
    {
179
        return $this->newSubscriberEvents;
180 1
    }
181
182 1
    public function getCreatedAt(): \DateTime
183
    {
184
        return $this->createdAt;
185
    }
186
187
    public function setCreatedAt(\DateTime $createdAt): self
188
    {
189
        $this->createdAt = $createdAt;
190
191
        return $this;
192
    }
193
194
    public function getUpdatedAt(): \DateTime
195
    {
196
        return $this->updatedAt;
197
    }
198
}
199