CommentEventJob::execute()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 2
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of Jitamin.
5
 *
6
 * Copyright (C) Jitamin Team
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 Jitamin\Bus\Job;
13
14
use Jitamin\Bus\EventBuilder\CommentEventBuilder;
15
use Jitamin\Model\CommentModel;
16
17
/**
18
 * Class CommentEventJob.
19
 */
20
class CommentEventJob extends BaseJob
21
{
22
    /**
23
     * Set job params.
24
     *
25
     * @param int    $commentId
26
     * @param string $eventName
27
     *
28
     * @return $this
29
     */
30
    public function withParams($commentId, $eventName)
31
    {
32
        $this->jobParams = [$commentId, $eventName];
33
34
        return $this;
35
    }
36
37
    /**
38
     * Execute job.
39
     *
40
     * @param int    $commentId
41
     * @param string $eventName
42
     *
43
     * @return $this
44
     */
45
    public function execute($commentId, $eventName)
46
    {
47
        $event = CommentEventBuilder::getInstance($this->container)
48
            ->withCommentId($commentId)
49
            ->buildEvent();
50
51
        if ($event !== null) {
52
            $this->dispatcher->dispatch($eventName, $event);
0 ignored issues
show
Documentation introduced by
The property dispatcher does not exist on object<Jitamin\Bus\Job\CommentEventJob>. 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...
53
54
            if ($eventName === CommentModel::EVENT_CREATE) {
55
                $this->userMentionModel->fireEvents($event['comment']['comment'], CommentModel::EVENT_USER_MENTION, $event);
0 ignored issues
show
Documentation introduced by
The property userMentionModel does not exist on object<Jitamin\Bus\Job\CommentEventJob>. 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...
56
            }
57
        }
58
    }
59
}
60