Completed
Branch master (3adcdb)
by Raffael
08:09 queued 04:17
created

Jobs::listen()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * balloon
7
 *
8
 * @copyright   Copryright (c) 2012-2018 gyselroth GmbH (https://gyselroth.com)
9
 * @license     GPL-3.0 https://opensource.org/licenses/GPL-3.0
10
 */
11
12
namespace Balloon\App\Cli\Console;
13
14
use Balloon\Hook;
15
use GetOpt\GetOpt;
16
use Psr\Log\LoggerInterface;
17
use TaskScheduler\Async;
18
19
class Jobs
20
{
21
    /**
22
     * Logger.
23
     *
24
     * @var LoggerInterface
25
     */
26
    protected $logger;
27
28
    /**
29
     * Getopt.
30
     *
31
     * @var GetOpt
32
     */
33
    protected $getopt;
34
35
    /**
36
     * Async.
37
     *
38
     * @var Async
39
     */
40
    protected $async;
41
42
    /**
43
     * Hook.
44
     *
45
     * @var Hook
46
     */
47
    protected $hook;
48
49
    /**
50
     * Constructor.
51
     *
52
     * @param App             $app
0 ignored issues
show
Bug introduced by
There is no parameter named $app. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
53
     * @param Async           $async
54
     * @param LoggerInterface $logger
55
     * @param GetOpt          $getopt
56
     */
57
    public function __construct(Hook $hook, Async $async, LoggerInterface $logger, GetOpt $getopt)
58
    {
59
        $this->async = $async;
60
        $this->hook = $hook;
61
        $this->logger = $logger;
62
        $this->getopt = $getopt;
63
        $this->async = $async;
64
    }
65
66
    /**
67
     * Get description.
68
     *
69
     * @return string
70
     */
71
    public function getDescription(): string
72
    {
73
        return 'Handles asynchronous job queue';
74
    }
75
76
    /**
77
     * Start.
78
     *
79
     * @return bool
80
     */
81
    public function listen(): bool
82
    {
83
        $this->logger->info('daemon execution requested, fire up daemon', [
84
            'category' => get_class($this),
85
        ]);
86
87
        $this->hook->run('preExecuteAsyncJobs');
88
        $this->async->startDaemon();
89
    }
90
91
    /*
92
     * Start.
93
     *
94
     * @return bool
95
     */
96
    public function once(): bool
97
    {
98
        $this->hook->run('preExecuteAsyncJobs');
99
        $this->async->startOnce();
100
        $this->hook->run('postExecuteAsyncJobs');
101
102
        return true;
103
    }
104
}
105