Passed
Push — master ( 304892...44e430 )
by Raffael
04:59
created

Jobs::getOperands()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 2
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 operands
68
     *
69
     * @return array
70
     */
71
    public static function getOperands(): array
72
    {
73
        return [
74
            \GetOpt\Operand::create('action', \GetOpt\Operand::REQUIRED),
75
            \GetOpt\Operand::create('id', \GetOpt\Operand::OPTIONAL),
76
        ];
77
    }
78
79
    /**
80
     * Get help.
81
     */
82
    public function help(): Jobs
83
    {
84
        echo "listen\n";
85
        echo "Start job listener (blocking process)\n\n";
86
87
        echo "once\n";
88
        echo "Execute all leftover jobs\n\n";
89
        echo $this->getopt->getHelpText();
90
91
        return $this;
92
    }
93
94
    /**
95
     * Get options.
96
     *
97
     * @return array
98
     */
99
    public static function getOptions(): array
100
    {
101
        return [];
102
    }
103
104
    /**
105
     * Start.
106
     *
107
     * @return bool
108
     */
109
    public function listen(): bool
110
    {
111
        $this->logger->info('daemon execution requested, fire up daemon', [
112
            'category' => get_class($this),
113
        ]);
114
115
        $this->hook->run('preExecuteAsyncJobs');
116
        $this->async->startDaemon();
117
    }
118
119
    /*
120
     * Start.
121
     *
122
     * @return bool
123
     */
124
    public function once(): bool
125
    {
126
        $this->hook->run('preExecuteAsyncJobs');
127
        $this->async->startOnce();
128
        $this->hook->run('postExecuteAsyncJobs');
129
130
        return true;
131
    }
132
}
133