CronExpressionExtension   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getNextRunDate() 0 3 1
A getName() 0 3 1
A getFilters() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusSchedulerPlugin\Twig;
6
7
use Cron\CronExpression;
8
9
class CronExpressionExtension extends \Twig_Extension
10
{
11
    /**
12
     * @return array
13
     */
14
    public function getFilters(): array
15
    {
16
        return [
17
            new \Twig_SimpleFilter('next_run_date', [$this, 'getNextRunDate']),
18
        ];
19
    }
20
21
    /**
22
     * @param string $cronExpression
23
     *
24
     * @return \DateTime
25
     */
26
    public function getNextRunDate(string $cronExpression): \DateTime
27
    {
28
        return CronExpression::factory($cronExpression)->getNextRunDate();
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function getName(): string
35
    {
36
        return 'setono_cron_expression';
37
    }
38
}
39