TaskEventJob::execute()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 3
nop 5
dl 0
loc 15
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\Event\TaskEvent;
15
use Jitamin\Bus\EventBuilder\TaskEventBuilder;
16
use Jitamin\Model\TaskModel;
17
18
/**
19
 * Class TaskEventJob.
20
 */
21
class TaskEventJob extends BaseJob
22
{
23
    /**
24
     * Set job params.
25
     *
26
     * @param int   $taskId
27
     * @param array $eventNames
28
     * @param array $changes
29
     * @param array $values
30
     * @param array $task
31
     *
32
     * @return $this
33
     */
34
    public function withParams($taskId, array $eventNames, array $changes = [], array $values = [], array $task = [])
35
    {
36
        $this->jobParams = [$taskId, $eventNames, $changes, $values, $task];
37
38
        return $this;
39
    }
40
41
    /**
42
     * Execute job.
43
     *
44
     * @param int   $taskId
45
     * @param array $eventNames
46
     * @param array $changes
47
     * @param array $values
48
     * @param array $task
49
     *
50
     * @return $this
51
     */
52
    public function execute($taskId, array $eventNames, array $changes = [], array $values = [], array $task = [])
53
    {
54
        $event = TaskEventBuilder::getInstance($this->container)
55
            ->withTaskId($taskId)
56
            ->withChanges($changes)
57
            ->withValues($values)
58
            ->withTask($task)
59
            ->buildEvent();
60
61
        if ($event !== null) {
62
            foreach ($eventNames as $eventName) {
63
                $this->fireEvent($eventName, $event);
64
            }
65
        }
66
    }
67
68
    /**
69
     * Trigger event.
70
     *
71
     * @param string    $eventName
72
     * @param TaskEvent $event
73
     */
74
    protected function fireEvent($eventName, TaskEvent $event)
75
    {
76
        $this->logger->debug(__METHOD__.' Event fired: '.$eventName);
0 ignored issues
show
Documentation introduced by
The property logger does not exist on object<Jitamin\Bus\Job\TaskEventJob>. 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...
77
        $this->dispatcher->dispatch($eventName, $event);
0 ignored issues
show
Documentation introduced by
The property dispatcher does not exist on object<Jitamin\Bus\Job\TaskEventJob>. 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...
78
79
        if ($eventName === TaskModel::EVENT_CREATE) {
80
            $this->userMentionModel->fireEvents($event['task']['description'], TaskModel::EVENT_USER_MENTION, $event);
0 ignored issues
show
Documentation introduced by
The property userMentionModel does not exist on object<Jitamin\Bus\Job\TaskEventJob>. 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...
81
        }
82
    }
83
}
84