Completed
Push — master ( 1ecbe4...61c842 )
by Michał
264:53 queued 250:28
created

StateMachine::apply()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\ResourceBundle\Controller;
13
14
use Sylius\Component\Resource\Model\ResourceInterface;
15
use SM\Factory\FactoryInterface;
16
17
/**
18
 * @author Paweł Jędrzejewski <[email protected]>
19
 */
20
class StateMachine implements StateMachineInterface
21
{
22
    /**
23
     * @var FactoryInterface
24
     */
25
    private $stateMachineFactory;
26
27
    /**
28
     * @param FactoryInterface $stateMachineFactory
29
     */
30
    public function __construct(FactoryInterface $stateMachineFactory)
31
    {
32
        $this->stateMachineFactory = $stateMachineFactory;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function apply(RequestConfiguration $configuration, ResourceInterface $resource)
39
    {
40
        if (!$configuration->hasStateMachine()) {
41
            throw new \InvalidArgumentException('State machine must be configured to apply transition, check your routing.');
42
        }
43
44
        $this->stateMachineFactory->get($resource, $configuration->getStateMachineGraph())->apply($configuration->getStateMachineTransition());
45
    }
46
}
47