ContainerAwareJob   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 57
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setKernelOptions() 0 4 1
A tearDown() 0 6 2
A getContainer() 0 9 2
A createKernel() 0 15 3
1
<?php
2
3
namespace Mpclarkson\ResqueBundle;
4
5
use Symfony\Component\DependencyInjection\ContainerInterface;
6
use Symfony\Component\Finder\Finder;
7
use Symfony\Component\HttpKernel\KernelInterface;
8
9
/**
10
 * Class ContainerAwareJob
11
 * @package Mpclarkson\ResqueBundle
12
 */
13
abstract class ContainerAwareJob extends Job
14
{
15
    /**
16
     * @var KernelInterface
17
     */
18
    private $kernel = NULL;
19
20
    /**
21
     * @param array $kernelOptions
22
     */
23
    public function setKernelOptions(array $kernelOptions)
24
    {
25
        $this->args = \array_merge($this->args, $kernelOptions);
26
    }
27
28
    /**
29
     *
30
     */
31
    public function tearDown()
32
    {
33
        if ($this->kernel) {
34
            $this->kernel->shutdown();
35
        }
36
    }
37
38
    /**
39
     * @return ContainerInterface
40
     */
41
    protected function getContainer()
42
    {
43
        if ($this->kernel === NULL) {
44
            $this->kernel = $this->createKernel();
45
            $this->kernel->boot();
46
        }
47
48
        return $this->kernel->getContainer();
49
    }
50
51
    /**
52
     * @return KernelInterface
53
     */
54
    protected function createKernel()
55
    {
56
        $finder = new Finder();
57
        $finder->name('*Kernel.php')->depth(0)->in($this->args['kernel.root_dir']);
58
        $results = iterator_to_array($finder);
59
        $file = current($results);
60
        $class = $file->getBasename('.php');
61
62
        require_once $file;
63
64
        return new $class(
65
            isset($this->args['kernel.environment']) ? $this->args['kernel.environment'] : 'dev',
66
            isset($this->args['kernel.debug']) ? $this->args['kernel.debug'] : TRUE
67
        );
68
    }
69
}
70