Completed
Push — master ( 9fa50b...106089 )
by Andrii
21:34 queued 06:37
created

Thread::getThreadUrlArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * HiPanel tickets module
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-ticket
6
 * @package   hipanel-module-ticket
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\ticket\models;
12
13
use hipanel\behaviors\File;
14
use hipanel\helpers\Markdown;
15
use hipanel\modules\client\models\Client;
16
use stdClass;
17
use Yii;
18
use yii\helpers\HtmlPurifier;
19
use yii\web\NotFoundHttpException;
20
21
/**
22
 * Class Ticket.
23
 *
24
 * @property string $priority
25
 * @property string $responsible_id
26
 */
27
class Thread extends \hipanel\base\Model
28
{
29
    use \hipanel\base\ModelTrait;
30
31
    const DEFAULT_SHOW_ALL = 'all';
32
33
    public static $i18nDictionary = 'hipanel:ticket';
34
35
    const STATE_OPEN = 'opened';
36
    const STATE_CLOSE = 'closed';
37
38
    const PRIORITY_HIGH = 'high';
39
40
    public $search_form;
41
42
    public function init()
43
    {
44
        $this->on(static::EVENT_BEFORE_INSERT, [$this, 'beforeChange']);
45
        $this->on(static::EVENT_BEFORE_UPDATE, [$this, 'beforeChange']);
46
    }
47
48
    public function beforeChange($event)
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
49
    {
50
        $this->prepareSpentTime();
51
        $this->prepareTopic();
52
53
        return true;
54
    }
55
56
    /**
57
     * @return array
58
     */
59 View Code Duplication
    public function behaviors()
0 ignored issues
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...
60
    {
61
        return [
62
            [
63
                'class' => File::class,
64
                'attribute' => 'file',
65
                'targetAttribute' => 'file_ids',
66
                'scenarios' => ['create', 'answer'],
67
            ],
68
        ];
69
    }
70
71
    /**
72
     * @return array
73
     */
74
    public function attributes()
75
    {
76
        return [
77
            'id',
78
            'subject',
79
            'state',
80
            'state_label',
81
            'author_email',
82
            'author',
83
            'author_id',
84
            'responsible_id',
85
            'responsible_email',
86
            'author_seller',
87
            'author_seller_id',
88
            'recipient_id',
89
            'recipient',
90
            'recipient_seller',
91
            'recipient_seller_id',
92
            'replier_id',
93
            'replier',
94
            'replier_seller',
95
            'replier_name',
96
            'responsible',
97
            'priority',
98
            'priority_label',
99
            'spent', 'spent_hours',
100
            'answer_count',
101
            'status',
102
            'reply_time',
103
            'create_time',
104
            'a_reply_time',
105
            'elapsed',
106
            'topics',
107
            'topic',
108
            'watchers',
109
            'watcher_ids',
110
            'watcher',
111
            'watcher_id',
112
            'add_tag_ids',
113
            'file_ids',
114
            'file',
115
            'message', // 'answer_message',
116
            'is_private',
117
118
            'anonym_name',
119
            'anonym_email',
120
            'anonym_seller',
121
122
            'lastanswer',
123
            'time',
124
            'add_watchers', 'del_watchers',
125
126
            'time_from',
127
            'time_till',
128
129
            'contact',
130
        ];
131
    }
132
133
    /**
134
     * {@inheritdoc}
135
     */
136
    public function rules()
137
    {
138
        $rules = [
139
            [['author_id', 'responsible_id'], 'integer'],
140
            [['subject', 'message'], 'required', 'on' => ['create']],
141
            [['subject'], 'string', 'min' => 3],
142
            [['id'], 'required', 'on' => ['answer', 'update-answer', 'open', 'close']],
143
            [['recipient_id'], 'required', 'when' => function () {
144
                return Yii::$app->user->can('support');
145
            }, 'on' => 'create'],
146
            [
147
                [
148
                    'topics',
149
                    'state',
150
                    'priority',
151
                    'responsible',
152
                    'recipient_id',
153
                    'watchers',
154
                    'spent', 'spent_hours',
155
                    'file_ids',
156
                ],
157
                'safe',
158
                'on' => 'create',
159
            ],
160
            [
161
                [
162
                    'message',
163
                    'topics', 'state', 'priority',
164
                    'responsible', 'recipient_id',
165
                    'watchers', 'add_watchers', 'del_watchers', 'watcher_ids',
166
                    'is_private',
167
                    'file_ids',
168
                    'spent', 'spent_hours',
169
                ],
170
                'safe',
171
                'on' => 'answer',
172
            ],
173
            [['state'], 'safe', 'on' => ['close', 'open']],
174
            // only client-side validation. Answer is actually possible without a message,
175
            // but does not make any sense.
176
            [['message'], 'required', 'on' => ['answer'], 'when' => function () {
177
                return false;
178
            }],
179
            [['state'], 'default', 'value' => self::DEFAULT_SHOW_ALL, 'on' => ['default']],
180
            [['id'], 'integer', 'on' => 'answer'],
181
            [['file'], 'file', 'maxFiles' => 15],
182
            [['lastanswer', 'create_time', 'recipient'], 'safe'],
183
            [['author', 'author_seller'], 'safe', 'when' => Yii::$app->user->can('support')],
184
        ];
185
186
        return $rules;
187
    }
188
189
    /**
190
     * {@inheritdoc}
191
     */
192
    public function attributeLabels()
193
    {
194
        return $this->mergeAttributeLabels([
195
            'author' => Yii::t('hipanel:ticket', 'Author'),
196
            'author_id' => Yii::t('hipanel:ticket', 'Author'),
197
            'recipient' => Yii::t('hipanel:ticket', 'Recipient'),
198
            'is_private' => Yii::t('hipanel:ticket', 'Make private'),
199
            'responsible' => Yii::t('hipanel:ticket', 'Assignee'),
200
            'responsible_id' => Yii::t('hipanel:ticket', 'Assignee'),
201
            'spent' => Yii::t('hipanel:ticket', 'Spent time'),
202
            'create_time' => Yii::t('hipanel:ticket', 'Created'),
203
            'a_reply_time' => Yii::t('hipanel:ticket', 'a_reply_time'),
204
            'file' => Yii::t('hipanel:ticket', 'Files'),
205
            'lastanswer' => Yii::t('hipanel:ticket', 'Last answer'),
206
            'author_seller' => Yii::t('hipanel:ticket', 'Seller'),
207
            'watcher_ids' => Yii::t('hipanel:ticket', 'Watchers'),
208
        ]);
209
    }
210
211
    public function getClient()
212
    {
213
        return $this->author;
0 ignored issues
show
Documentation introduced by
The property author does not exist on object<hipanel\modules\ticket\models\Thread>. 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...
214
    }
215
216
    public function getClient_id()
217
    {
218
        return $this->author_id;
0 ignored issues
show
Documentation introduced by
The property author_id does not exist on object<hipanel\modules\ticket\models\Thread>. 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...
219
    }
220
221
    public function getSeller()
222
    {
223
        return $this->author_seller;
0 ignored issues
show
Documentation introduced by
The property author_seller does not exist on object<hipanel\modules\ticket\models\Thread>. 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...
224
    }
225
226
    public function getSeller_id()
227
    {
228
        return $this->author_seller_id;
0 ignored issues
show
Documentation introduced by
The property author_seller_id does not exist on object<hipanel\modules\ticket\models\Thread>. 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...
229
    }
230
231
    public function getThreadUrlArray()
232
    {
233
        return ['@ticket/view', 'id' => $this->id];
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<hipanel\modules\ticket\models\Thread>. 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...
234
    }
235
236
    public static function parseMessage($message)
237
    {
238
        $message = str_replace(["\n\r", "\r\r", "\r\n"], "\n", $message); // "\n\n",
239
        $message = Markdown::process($message);
240
        $message = HtmlPurifier::process($message, [
241
            'HTML.SafeObject' => true, // Allow safe HTML entities
242
            'Core.EscapeInvalidTags' => true, // Escape not allowed tags instead of stripping them
243
            'Core.LexerImpl' => 'DirectLex', // Do not try to close unclosed tags
244
        ]);
245
246
        return $message;
247
    }
248
249
    public function prepareSpentTime()
250
    {
251
        list($this->spent_hours, $this->spent) = explode(':', $this->spent, 2);
0 ignored issues
show
Documentation introduced by
The property spent_hours does not exist on object<hipanel\modules\ticket\models\Thread>. 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...
Documentation introduced by
The property spent does not exist on object<hipanel\modules\ticket\models\Thread>. 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...
252
    }
253
254
    public function prepareTopic()
255
    {
256
        $this->topics = is_array($this->topics) ? implode(',', $this->topics) : $this->topics;
0 ignored issues
show
Documentation introduced by
The property topics does not exist on object<hipanel\modules\ticket\models\Thread>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
Documentation introduced by
The property topics does not exist on object<hipanel\modules\ticket\models\Thread>. 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...
257
    }
258
259
    public function getWatchersLogin()
260
    {
261
        $results = [];
262
        foreach ((array)$this->watchers as $id => $watcher) {
263
            list($login, $email) = explode(' ', $watcher);
0 ignored issues
show
Unused Code introduced by
The assignment to $email is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
264
            $results[$id] = $login;
265
        }
266
267
        return $results;
268
    }
269
270
    public function xFormater(array $items)
271
    {
272
        $result = [];
273
        foreach ($items as $id => $label) {
274
            $object = new stdClass();
275
            $object->value = $id;
276
            $object->text = $label;
277
            $result[] = $object;
278
        }
279
280
        return $result;
281
    }
282
283
    public function getAnswers()
284
    {
285
        // TODO: redo API in order to have different `Thread` and `ThreadMessage` models
286
        return $this->hasMany(Answer::class, ['id' => 'id'])->joinWith('files')->indexBy('answer_id');
287
    }
288
289
    /**
290
     * Returns array of client types, that can be set as responsible for the thread.
291
     *
292
     * @return array
293
     */
294
    public static function getResponsibleClientTypes()
295
    {
296
        return [Client::TYPE_SELLER, Client::TYPE_ADMIN, Client::TYPE_MANAGER, Client::TYPE_OWNER];
297
    }
298
299
    /**
300
     * @param integer $id
301
     * @param bool $throwOnError whether to throw an exception when answer is not found in thread
302
     * @throws NotFoundHttpException
303
     * @return Answer
304
     */
305
    public function getAnswer($id, $throwOnError = true)
306
    {
307
        if (!isset($this->answers[$id]) && $throwOnError) {
0 ignored issues
show
Documentation introduced by
The property answers does not exist on object<hipanel\modules\ticket\models\Thread>. 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...
308
            throw new NotFoundHttpException('Answer does not belong to this model');
309
        }
310
311
        return $this->answers[$id];
0 ignored issues
show
Documentation introduced by
The property answers does not exist on object<hipanel\modules\ticket\models\Thread>. 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...
312
    }
313
314
    public function getMaxAnswerId()
315
    {
316
        if ($this->isRelationPopulated('answers')) {
317
            return max(array_keys($this->answers));
0 ignored issues
show
Documentation introduced by
The property answers does not exist on object<hipanel\modules\ticket\models\Thread>. 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...
318
        }
319
320
        return $this->id;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<hipanel\modules\ticket\models\Thread>. 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...
321
    }
322
323
    public function scenarioActions()
324
    {
325
        return [
326
            'open' => 'answer',
327
            'close' => 'answer',
328
        ];
329
    }
330
331
    public function canSetSpent()
332
    {
333
        if (isset(Yii::$app->params['ticket.canSetSpent']) && is_callable(Yii::$app->params['ticket.canSetSpent'])) {
334
            return call_user_func(Yii::$app->params['ticket.canSetSpent'], $this);
335
        }
336
337
        return true;
338
    }
339
340
    public function isOpen()
341
    {
342
        return $this->state === self::STATE_OPEN;
0 ignored issues
show
Documentation introduced by
The property state does not exist on object<hipanel\modules\ticket\models\Thread>. 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...
343
    }
344
345
    public function isHighPriority(): bool
346
    {
347
        return $this->priority === self::PRIORITY_HIGH;
348
    }
349
350
    public function isUserAssigned(): bool
351
    {
352
        return $this->responsible_id === Yii::$app->getUser()->getId();
0 ignored issues
show
Bug introduced by
The method getUser does only exist in yii\web\Application, but not in yii\console\Application.

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...
353
    }
354
}
355