CronPatternRule   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A passes() 0 7 6
A message() 0 4 1
1
<?php
2
3
namespace Schubu\Cronify\Rules;
4
5
use Cron\CronExpression;
6
use Illuminate\Contracts\Validation\Rule;
7
8
class CronPatternRule implements Rule
9
{
10
    /**
11
     * Determine if the validation rule passes.
12
     *
13
     * @param  string  $attribute
14
     * @param  mixed  $value
15
     * @return bool
16
     */
17
    public function passes($attribute, $value)
18
    {
19
        $keys = array_flip(["minute","hour","day","month","weekday"]);
20
        if((is_array($value) && count($value) == 5 && array_diff_key($keys,$value) === []) !== true) return false;
21
        if(in_array(null, $value, true) || in_array('', $value, true)) return false;
22
        return CronExpression::isValidExpression($value['minute']." ".$value['hour']." ".$value['day']." ".$value['month']." ".$value['weekday']);
23
    }
24
25
    /**
26
     * Get the validation error message.
27
     *
28
     * @return string
29
     */
30
    public function message()
31
    {
32
        return 'The :attribute pattern is invalid';
33
    }
34
}
35