Cron::process()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 1
crap 2
1
<?php
2
3
namespace BrainExe\Core\DependencyInjection\CompilerPass;
4
5
use BrainExe\Core\Annotations\CompilerPass;
6
use BrainExe\Core\Cron\CronDefinition as CronInterface;
7
use BrainExe\Core\Traits\FileCacheTrait;
8
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
11
/**
12
 * @CompilerPass
13
 */
14
class Cron implements CompilerPassInterface
15
{
16
    use FileCacheTrait;
17
18
    const TAG = 'cron';
19
    const CACHE_FILE = 'crons';
20
21
    /**
22
     * {@inheritdoc}
23
     */
24 1
    public function process(ContainerBuilder $container)
25
    {
26 1
        $allCrons = [];
27
28 1
        $taggedServices = $container->findTaggedServiceIds(self::TAG);
29 1
        foreach (array_keys($taggedServices) as $serviceId) {
30
            /** @var CronInterface $cron */
31 1
            $definition = $container->getDefinition($serviceId);
32 1
            $cron = $definition->getClass();
33 1
            $allCrons = array_merge($allCrons, $cron::getCrons());
34
        }
35
36 1
        $this->dumpVariableToCache(self::CACHE_FILE, $allCrons);
37 1
    }
38
}
39