Cron::addCron()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 14
ccs 0
cts 5
cp 0
rs 9.4286
cc 1
eloc 8
nc 1
nop 1
crap 2
1
<?php
2
3
namespace BrainExe\Expression\Controller;
4
5
use BrainExe\Annotations\Annotations\Inject;
6
use BrainExe\Core\Annotations\Controller as ControllerAnnotation;
7
use BrainExe\Core\Annotations\Route;
8
use BrainExe\Core\EventDispatcher\EventDispatcher;
9
use BrainExe\Core\EventDispatcher\Events\TimingEvent;
10
use BrainExe\Core\EventDispatcher\CronEvent;
11
use Symfony\Component\HttpFoundation\Request;
12
13
/**
14
 * @ControllerAnnotation("Expression.Controller.Cron")
15
 */
16
class Cron
17
{
18
    /**
19
     * @var EventDispatcher
20
     */
21
    private $dispatcher;
22
23
    /**
24
     * @Inject({
25
     *  "@EventDispatcher",
26
     * })
27
     * @param EventDispatcher $dispatcher
28
     */
29
    public function __construct(
30
        EventDispatcher $dispatcher
31
    ) {
32
        $this->dispatcher = $dispatcher;
33
    }
34
35
    /**
36
     * @param Request $request
37
     * @Route("/expressions/cron/", name="expressions.cron")
38
     * @return bool
39
     */
40
    public function addCron(Request $request)
41
    {
42
        $cronExpression = $request->request->get('expression');
43
        $cronId         = $request->request->get('cronId');
44
45
        $event = new CronEvent(
46
            new TimingEvent($cronId),
47
            $cronExpression
48
        );
49
50
        $this->dispatcher->dispatchEvent($event);
51
52
        return true;
53
    }
54
}
55