CronExpressionGenerator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 9
c 1
b 0
f 0
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 9 1
A __construct() 0 3 1
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