CronServiceFactory::createService()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 1
1
<?php
2
3
namespace T4web\Cron\Service;
4
5
use Zend\ServiceManager\ServiceLocatorInterface;
6
use Zend\ServiceManager\FactoryInterface;
7
use Cron\Cron;
8
use T4web\Cron\Resolver\ArrayResolver;
9
use T4web\Cron\Executor\Executor;
10
use T4web\Cron\Config;
11
12
class CronServiceFactory implements FactoryInterface
13
{
14
    /**
15
     * Create service
16
     *
17
     * @param ServiceLocatorInterface $serviceLocator
18
     * @return CronService
19
     */
20
    public function createService(ServiceLocatorInterface $serviceLocator)
21
    {
22
        $config = $serviceLocator->get(Config::class);
23
24
        $resolver = new ArrayResolver($config->getPhpPath(), $config->getScriptPath());
25
        $resolver->buildFromConfig($config->getJobs());
26
27
        $cron = new Cron();
28
        $cron->setResolver($resolver);
29
        $cron->setExecutor(new Executor());
30
31
        return new CronService(
32
            $config->getTimeout(),
33
            $cron
34
        );
35
    }
36
}
37