TaskTriggerCommand::getProjectIds()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 11
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\Console;
13
14
use Jitamin\Bus\Event\TaskListEvent;
15
use Jitamin\Model\TaskModel;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
/**
20
 * Task trigger command class.
21
 */
22
class TaskTriggerCommand extends BaseCommand
23
{
24
    /**
25
     * Configure the console command.
26
     *
27
     * @return void
28
     */
29
    protected function configure()
30
    {
31
        $this
32
            ->setName('trigger:tasks')
33
            ->setDescription('Trigger scheduler event for all tasks');
34
    }
35
36
    /**
37
     * Execute the console command.
38
     *
39
     * @param InputInterface  $output
40
     * @param OutputInterface $output
41
     *
42
     * @return void
43
     */
44
    protected function execute(InputInterface $input, OutputInterface $output)
45
    {
46
        foreach ($this->getProjectIds() as $project_id) {
47
            $tasks = $this->taskFinderModel->getAll($project_id);
0 ignored issues
show
Documentation introduced by
The property taskFinderModel does not exist on object<Jitamin\Console\TaskTriggerCommand>. 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...
48
            $nb_tasks = count($tasks);
49
50
            if ($nb_tasks > 0) {
51
                $output->writeln('Trigger task event: project_id='.$project_id.', nb_tasks='.$nb_tasks);
52
                $this->sendEvent($tasks, $project_id);
53
            }
54
        }
55
    }
56
57
    /**
58
     * Get the project ids.
59
     *
60
     * @return int[]
61
     */
62
    private function getProjectIds()
63
    {
64
        $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_DAILY_CRONJOB);
0 ignored issues
show
Documentation introduced by
The property dispatcher does not exist on object<Jitamin\Console\TaskTriggerCommand>. 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...
65
        $project_ids = [];
66
67
        foreach ($listeners as $listener) {
68
            $project_ids[] = $listener[0]->getProjectId();
69
        }
70
71
        return array_unique($project_ids);
72
    }
73
74
    /**
75
     * Send the event.
76
     *
77
     * @param array $tasks
78
     * @param int   $project_id
79
     *
80
     * @return void
81
     */
82
    private function sendEvent(array &$tasks, $project_id)
83
    {
84
        $event = new TaskListEvent(['project_id' => $project_id]);
85
        $event->setTasks($tasks);
86
87
        $this->dispatcher->dispatch(TaskModel::EVENT_DAILY_CRONJOB, $event);
0 ignored issues
show
Documentation introduced by
The property dispatcher does not exist on object<Jitamin\Console\TaskTriggerCommand>. 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...
88
    }
89
}
90