Issues (3)

src/CronExpressionGenerator.php (1 issue)

1
<?php
2
3
namespace AkkiIo\CronExpressionGenerator;
4
5
use Illuminate\Support\Arr;
6
use InvalidArgumentException;
7
8
class CronExpressionGenerator
9
{
10
    /**
11
     * Options related to the type.
12
     *
13
     * @var array
14
     */
15
    public array $options;
16
17
    /**
18
     * CronExpressionGenerator constructor.
19
     *
20
     * @param array $options
21
     * @throws InvalidArgumentException
22
     */
23
    public function __construct(array $options)
24
    {
25
        $this->options = $options;
26
    }
27
28
    /**
29
     * Generate the cron expression.
30
     *
31
     * @return string
32
     */
33
    public function generate(): string
34
    {
35
        $cron['minute'] = (new ParseInput(Arr::get($this->options, 'minute', []), 0, 59))->generate();
0 ignored issues
show
Comprehensibility Best Practice introduced by
$cron was never initialized. Although not strictly required by PHP, it is generally a good practice to add $cron = array(); before regardless.
Loading history...
36
        $cron['hour'] = (new ParseInput(Arr::get($this->options, 'hour', []), 0, 23))->generate();
37
        $cron['day_month'] = (new ParseInput(Arr::get($this->options, 'day_month', []), 1, 31))->generate();
38
        $cron['month'] = (new ParseInput(Arr::get($this->options, 'month', []), 1, 12))->generate();
39
        $cron['day_week'] = (new ParseInput(Arr::get($this->options, 'day_week', []), 0, 6))->generate();
40
41
        return implode(' ', $cron);
42
    }
43
}
44