Passed
Pull Request — master (#39)
by Daniel
02:27
created

SchedulerFactory::createJob()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Jellyfish\Scheduler;
4
5
use Cron\CronExpression;
6
use Jellyfish\Process\ProcessFacadeInterface;
7
8
class SchedulerFactory
9
{
10
    /**
11
     * @var \Jellyfish\Process\ProcessFacadeInterface
12
     */
13
    protected $processFacade;
14
15
    /**
16
     * @var \Jellyfish\Scheduler\SchedulerInterface
17
     */
18
    protected $scheduler;
19
20
    /**
21
     * @param \Jellyfish\Process\ProcessFacadeInterface $processFacade
22
     */
23
    public function __construct(ProcessFacadeInterface $processFacade)
24
    {
25
        $this->processFacade = $processFacade;
26
    }
27
28
    /**
29
     * @param string $expression
30
     *
31
     * @return \Cron\CronExpression
32
     */
33
    protected function createCronExpression(string $expression): CronExpression
34
    {
35
        return CronExpression::factory($expression);
36
    }
37
38
    /**
39
     * @param string[] $command
40
     * @param string $cronExpression
41
     *
42
     * @return \Jellyfish\Scheduler\JobInterface
43
     */
44
    public function createJob(array $command, string $cronExpression): JobInterface
45
    {
46
        return new Job(
47
            $this->processFacade->createProcess($command),
48
            $this->createCronExpression($cronExpression)
49
        );
50
    }
51
52
    /**
53
     * @return \Jellyfish\Scheduler\SchedulerInterface
54
     */
55
    public function getScheduler(): SchedulerInterface
56
    {
57
        if ($this->scheduler === null) {
58
            $this->scheduler = new Scheduler();
59
        }
60
61
        return $this->scheduler;
62
    }
63
}
64