Completed
Push — develop ( fea319...7a0090 )
by Mohamed
07:15
created

SendMessages::wantToReceiveMessage()   C

Complexity

Conditions 8
Paths 7

Size

Total Lines 36
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 8.1515

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 36
ccs 13
cts 15
cp 0.8667
rs 5.3846
cc 8
eloc 15
nc 7
nop 2
crap 8.1515
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Model\Project\Issue;
13
14
use Illuminate\Database\Eloquent\Collection;
15
use Tinyissue\Model\Message\Queue;
16
use Tinyissue\Model\Project;
17
use Tinyissue\Model\Project\Issue;
18
use Tinyissue\Model\Tag;
19
use Tinyissue\Model\User;
20
use Tinyissue\Services\SendMessagesAbstract;
21
22
/**
23
 * SendMessages is a class to manage & process of sending messages about issue changes.
24
 *
25
 * @author Mohamed Alsharaf <[email protected]>
26
 */
27
class SendMessages extends SendMessagesAbstract
28
{
29
    protected $template = 'update_issue';
30
31
    /**
32
     * Collection of tags.
33
     *
34
     * @var Collection
35
     */
36
    protected $tags;
37
38
    /**
39
     * Returns an instance of Issue.
40
     *
41
     * @return bool
42
     */
43 3
    protected function getIssue()
44
    {
45 3
        if (null === $this->issue) {
46 3
            $this->issue = $this->getModel();
47
        }
48
49 3
        return $this->issue;
50
    }
51
52
    /**
53
     * Returns an instance of Project.
54
     *
55
     * @return Project
56
     */
57 3
    protected function getProject()
58
    {
59 3
        return $this->getIssue()->project;
60
    }
61
62
    /**
63
     * Returns the project id.
64
     *
65
     * @return int
66
     */
67 3
    protected function getProjectId()
68
    {
69 3
        return $this->getIssue()->project_id;
70
    }
71
72
    /**
73
     * Returns message data belongs to adding an issue.
74
     *
75
     * @param Queue $queue
76
     *
77
     * @return array
78
     */
79 3
    protected function getMessageDataForAddIssue(Queue $queue)
80
    {
81 3
        $messageData                    = ['changes' => []];
82 3
        $messageData['changeByHeading'] = $queue->changeBy->fullname . ' created a new issue';
0 ignored issues
show
Documentation introduced by
The property fullname does not exist on object<Tinyissue\Model\Project\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
83 3
        if ($this->issue->assigned) {
0 ignored issues
show
Bug introduced by
The property assigned does not seem to exist. Did you mean assigned_to?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
84 1
            $messageData['changes']['assignee'] = $this->issue->assigned->fullname;
0 ignored issues
show
Bug introduced by
The property assigned does not seem to exist. Did you mean assigned_to?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
85
        }
86
87 3
        $tags = $this->issue->tags()->with('parent')->get();
88 3
        foreach ($tags as $tag) {
89 2
            $tagArray                                   = $tag->toShortArray();
90 2
            $tagArray['now']                            = $tagArray['name'];
91 2
            $messageData['changes'][$tag->parent->name] = $tagArray;
92
        }
93
94 3
        if ($this->issue->time_quote) {
95
            $messageData['changes']['time_quote'] = \Html::duration($this->issue->time_quote);
96
        }
97
98 3
        return $messageData;
99
    }
100
101
    /**
102
     * Returns message data belongs to updating an issue.
103
     *
104
     * @param Queue $queue
105
     *
106
     * @return array
107
     */
108 1
    protected function getMessageDataForUpdateIssue(Queue $queue)
109
    {
110 1
        $messageData                    = [];
111 1
        $messageData['changeByHeading'] = $queue->changeBy->fullname . ' updated an issue';
0 ignored issues
show
Documentation introduced by
The property fullname does not exist on object<Tinyissue\Model\Project\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
112
113 1
        foreach ($queue->payload['dirty'] as $field => $value) {
0 ignored issues
show
Bug introduced by
The expression $queue->payload['dirty'] of type string is not traversable.
Loading history...
114
            // Skip fields that not part of the white list
115 1
            if (!in_array($field,
116 1
                ['change_by', 'title', 'body', 'assignee', 'status', 'type', 'resolution', 'time_quote'])
117
            ) {
118 1
                continue;
119
            }
120
            // Format quote to readable time
121 1
            $value                          = $field === 'time_quote' ? \Html::duration($value) : $value;
122 1
            $value                          = $field === 'body' ? \Html::format($value) : $value;
123 1
            $messageData['changes'][$field] = [
124 1
                'now' => $value,
125 1
                'was' => $queue->getDataFromPayload('origin.' . $field),
126
            ];
127
        }
128
129 1
        return $messageData;
130
    }
131
132
    /**
133
     * Returns message data belongs to reopening an issue.
134
     *
135
     * @param Queue $queue
136
     *
137
     * @return array
138
     */
139
    protected function getMessageDataForReopenIssue(Queue $queue)
140
    {
141
        $messageData                    = [];
142
        $messageData['changeByHeading'] = $queue->changeBy->fullname . ' reopened an issue';
0 ignored issues
show
Documentation introduced by
The property fullname does not exist on object<Tinyissue\Model\Project\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
143
        $statusNow                      = $this->issue
144
            ->tags()->with('parent')->get()->where('parent.name', Tag::GROUP_STATUS)->last();
145
        $messageData['changes']['status'] = [
146
            'was' => trans('tinyissue.closed'),
147
            'now' => ($statusNow ? $statusNow->fullname : ''),
148
            'id'  => ($statusNow ? $statusNow->id : ''),
149
        ];
150
151
        return $messageData;
152
    }
153
154
    /**
155
     * Returns message data belongs to closing an issue.
156
     *
157
     * @param Queue $queue
158
     *
159
     * @return array
160
     */
161
    protected function getMessageDataForCloseIssue(Queue $queue)
162
    {
163
        $messageData                    = [];
164
        $messageData['changeByHeading'] = $queue->changeBy->fullname . ' closed an issue';
0 ignored issues
show
Documentation introduced by
The property fullname does not exist on object<Tinyissue\Model\Project\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
165
        $statusWas                      = $this->issue
166
            ->tags()->with('parent')->get()->where('parent.name', Tag::GROUP_STATUS)->last();
167
        $messageData['changes']['status'] = [
168
            'was' => ($statusWas ? $statusWas->fullname : ''),
169
            'now' => trans('tinyissue.closed'),
170
        ];
171
172
        return $messageData;
173
    }
174
175
    /**
176
     * Returns message data belongs to assigning an issue to a user.
177
     *
178
     * @param Queue $queue
179
     * @param array $extraData
180
     *
181
     * @return array
182
     */
183
    protected function getMessageDataForAssignIssue(Queue $queue, array $extraData)
184
    {
185
        $messageData = [];
186
        if (!array_key_exists('now', $extraData)) {
187
            $assignTo  = $this->getUserById($queue->getDataFromPayload('dirty.assigned_to'));
188
            $extraData = ['now' => $assignTo->fullname];
189
        }
190
191
        $messageData['changes']['assignee'] = $extraData;
192
        $messageData['changeByHeading']     = $queue->changeBy->fullname . ' assigned an issue to ' . $extraData['now'];
0 ignored issues
show
Documentation introduced by
The property fullname does not exist on object<Tinyissue\Model\Project\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
193
194
        return $messageData;
195
    }
196
197
    /**
198
     * Returns message data belongs to changing an issue tags.
199
     *
200
     * @param Queue $queue
201
     *
202
     * @return array
203
     */
204 2
    protected function getMessageDataForChangeTagIssue(Queue $queue)
205
    {
206 2
        $messageData                    = [];
207 2
        $messageData['changeByHeading'] = $queue->changeBy->fullname . ' changed an issue tag';
0 ignored issues
show
Documentation introduced by
The property fullname does not exist on object<Tinyissue\Model\Project\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
208
209 2
        foreach ($queue->payload['added'] as $tag) {
0 ignored issues
show
Bug introduced by
The expression $queue->payload['added'] of type string is not traversable.
Loading history...
210 2
            $group                          = strtolower($tag['group']);
211 2
            $messageData['changes'][$group] = [
212 2
                'now'           => $tag['name'],
213 2
                'id'            => $tag['id'],
214 2
                'message_limit' => $tag['message_limit'],
215
            ];
216
        }
217
218 2
        foreach ($queue->payload['removed'] as $tag) {
0 ignored issues
show
Bug introduced by
The expression $queue->payload['removed'] of type string is not traversable.
Loading history...
219 1
            $group                                 = strtolower($tag['group']);
220 1
            $messageData['changes'][$group]['was'] = $tag['name'];
221
        }
222
223 2
        return $messageData;
224
    }
225
226
    /**
227
     * Check that the issue is load.
228
     *
229
     * @return bool
230
     */
231 3
    protected function validateData()
232
    {
233
        // if issue closed and last issue not closed, then something is wrong skip
234 3
        if (!$this->issue->isOpen() && $this->latestMessage->event !== Queue::CLOSE_ISSUE) {
235
            return false;
236
        }
237
238 3
        return $this->issue;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->issue; (Tinyissue\Model\Project\Issue) is incompatible with the return type declared by the abstract method Tinyissue\Services\SendM...sAbstract::validateData of type boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
239
    }
240
241
    /**
242
     * Populate assigned relation in the current issue.
243
     *
244
     * @return void
245
     */
246 3 View Code Duplication
    protected function populateData()
1 ignored issue
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...
247
    {
248 3
        $this->issue->setRelation('assigned', $this->getUserById($this->issue->assigned_to));
249 3
        $creator = $this->getUserById($this->issue->created_by);
250 3
        if ($creator) {
251 3
            $this->issue->setRelation('user', $creator);
252
        }
253 3
        $this->loadIssueCreatorToProjectUsers();
254 3
    }
255
256
    /**
257
     * Check if the latest message is about closing or reopening an issue.
258
     *
259
     * @return bool
260
     */
261 3
    public function isStatusMessage()
262
    {
263 3
        return ((!$this->issue->isOpen() && $this->latestMessage->event === Queue::CLOSE_ISSUE)
264 3
            || ($this->issue->isOpen() && $this->latestMessage->event === Queue::REOPEN_ISSUE));
265
    }
266
267
    /**
268
     * Process assign to user message. Send direct message to new and previous users and full subscribers.
269
     *
270
     * @return void
271
     */
272 3
    protected function processDirectMessages()
273
    {
274
        // Stop if issue is closed
275 3
        if (!$this->getIssue()->isOpen()) {
276
            return;
277
        }
278
279
        // Fetch all of the assign issue changes
280 3
        $assignMessages = $this->allMessages->where('event', Queue::ASSIGN_ISSUE);
281
282
        // Skip if no changes
283 3
        if ($assignMessages->isEmpty()) {
284 3
            return;
285
        }
286
287
        // Fetch the latest assignee
288
        /** @var Queue $assignMessage */
289
        $assignMessage = $assignMessages->first();
290
291
        // Fetch the user details of the new assignee & previous assignee if this isn't new issue
292
        $assigns        = [];
293
        $assigns['new'] = (int) $assignMessage->getDataFromPayload('dirty.assigned_to');
294
        if (!$this->addMessage) {
295
            $previousAssignMessage = $assignMessages->last();
296
            $assigns['old']        = (int) $previousAssignMessage->getDataFromPayload('origin.assigned_to');
297
        }
298
299
        // Fetch users objects for old and new assignee
300
        /** @var \Illuminate\Database\Eloquent\Collection $assignObjects */
301
        $assignObjects = (new User())->whereIn('id', $assigns)->get();
0 ignored issues
show
Documentation Bug introduced by
The method whereIn does not exist on object<Tinyissue\Model\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
302
303
        // If for what ever reason the user does not exists, skip this change
304
        // or if there is only one user and is not matching the new assignee.
305
        // then skip this message
306
        if ($assignObjects->count() === 0
307
            || ($assignObjects->count() === 1 && (int) $assignObjects->first()->id !== $assigns['new'])
308
        ) {
309
            return;
310
        }
311
312
        // Get the object of the new assignee
313
        $assignTo = $assignObjects->where('id', $assigns['new'], false)->first();
314
        $users    = collect([$this->createProjectUserObject($assignTo)]);
315
316
        // Exclude the user from any other message for this issue
317
        $this->addToExcludeUsers($assignTo);
318
319
        // Data about new and previous assignee
320
        $extraMessageData = [
321
            'now' => $assignTo->fullname,
322
        ];
323
324
        // Make sure that the previous assignee was not the same as the new user
325
        if (array_key_exists('old', $assigns) && $assigns['old'] > 0 && $assigns['new'] !== $assigns['old']) {
326
            $previousAssign = $assignObjects->where('id', $assigns['old'], false)->first();
327
            if ($previousAssign) {
328
                $extraMessageData['was'] = $previousAssign->fullname;
329
                $users->push($this->createProjectUserObject($previousAssign));
330
            }
331
        }
332
333
        // Get message data needed for the message & send
334
        $messageData = $this->getMessageData($assignMessage, $extraMessageData);
335
        $this->sendMessages($users, $messageData);
336
    }
337
338
    /**
339
     * Create user project object for a user.
340
     *
341
     * @param User $user
342
     *
343
     * @return Project\User
344
     */
345
    protected function createProjectUserObject(User $user)
346
    {
347
        $userProject = new Project\User([
348
            'user_id'    => $user->id,
349
            'project_id' => $this->getProjectId(),
350
        ]);
351
        $userProject->setRelation('user', $user);
352
        $userProject->setRelation('project', $this->getProject());
353
354
        return $userProject;
355
    }
356
357
    /**
358
     * Get collection of tags or one by ID.
359
     *
360
     * @param null|int $tagId
361
     *
362
     * @return \Illuminate\Support\Collection|Tag
363
     */
364 2
    protected function getTags($tagId = null)
365
    {
366 2
        if (null === $this->tags) {
367 2
            $this->tags = collect([]);
368
        }
369
370
        // Load & extract tag by ID
371 2
        if (null !== $tagId) {
372 2
            $tag = $this->tags->where('id', $tagId, false)->first();
373 2
            if (!$tag) {
374 2
                $tag = (new Tag())->find($tagId);
0 ignored issues
show
Documentation Bug introduced by
The method find does not exist on object<Tinyissue\Model\Tag>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
375 2
                $this->tags->push($tag);
376
            }
377
378 2
            return $tag;
379
        }
380
381
        return $this->tags;
382
    }
383
384
    /**
385
     * Whether or not the user wants to receive the message.
386
     *
387
     * @param Project\User $user
388
     * @param array        $data
389
     *
390
     * @return bool
391
     */
392 3
    protected function wantToReceiveMessage(Project\User $user, array $data)
393
    {
394 3
        $status = parent::wantToReceiveMessage($user, $data);
395
396 3
        if (!$status) {
397 3
            return false;
398
        }
399
400
        // Search for tag changes and verify if the user can receive messages
401 3
        foreach ($data['changes'] as $label => $change) {
402
            // Skip other changes that are not related to tag
403 3
            if (!in_array($label, Tag::getCoreGroups())) {
404 3
                continue;
405
            }
406
407
            // If the change was only remove a tag
408 2
            if (!array_key_exists('now', $change) && array_key_exists('was', $change)) {
409
                return true;
410
            }
411
412
            // If tag id not found
413 2
            if (!array_key_exists('id', $change)) {
414
                return true;
415
            }
416
417
            // Fetch tag details
418 2
            $tag = $this->getTags($change['id']);
419
420
            // Check if user allowed to receive the message
421 2
            if (!$tag->allowMessagesToUser($user->user)) {
0 ignored issues
show
Documentation introduced by
The property user does not exist on object<Tinyissue\Model\Project\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The method allowMessagesToUser does only exist in Tinyissue\Model\Tag, but not in Illuminate\Support\Collection.

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...
422 2
                return false;
423
            }
424
        }
425
426 3
        return true;
427
    }
428
}
429