Cron   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 1
cbo 3
dl 0
loc 39
ccs 0
cts 7
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A addCron() 0 14 1
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