createStateMachine()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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