SymfonyDependencyInjectionFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
cbo 3
dl 0
loc 39
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 2
A createStateMachine() 0 4 1
1
<?php
2
3
namespace Finite\Factory;
4
5
use Finite\Exception\FactoryException;
6
use Symfony\Component\DependencyInjection\ContainerInterface;
7
8
/**
9
 * A concrete implementation of State Machine Factory using the sf2 DIC.
10
 *
11
 * @author Yohan Giarelli <[email protected]>
12
 */
13
class SymfonyDependencyInjectionFactory extends AbstractFactory
14
{
15
    /**
16
     * @var ContainerInterface
17
     */
18
    protected $container;
19
20
    /**
21
     * @var string
22
     */
23
    protected $key;
24
25
    /**
26
     * @param ContainerInterface $container
27
     * @param string             $key
28
     */
29 10
    public function __construct(ContainerInterface $container, $key)
30
    {
31 10
        $this->container = $container;
32 10
        $this->key = $key;
33
34 10
        if (!$container->has($key)) {
35 5
            throw new FactoryException(
36 5
                sprintf(
37 5
                    'You must define the "%s" service as your StateMachine definition',
38 2
                    $key
39 3
                )
40 3
            );
41
        }
42 10
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 5
    protected function createStateMachine()
48
    {
49 5
        return $this->container->get($this->key);
50
    }
51
}
52