Completed
Push — api ( cecea0...116a36 )
by Kamil
29:57 queued 30s
created

PaymentStateMachineTransitionApplicator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 23
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A complete() 0 6 1
A applyTransition() 0 5 1
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
declare(strict_types=1);
13
14
namespace Sylius\Bundle\ApiBundle\Applicator;
15
16
use SM\Factory\FactoryInterface as StateMachineFactoryInterface;
17
use Sylius\Component\Payment\Model\PaymentInterface;
18
use Sylius\Component\Payment\PaymentTransitions;
19
20
final class PaymentStateMachineTransitionApplicator
21
{
22
    /** @var StateMachineFactoryInterface $stateMachineFactory */
23
    private $stateMachineFactory;
24
25
    public function __construct(StateMachineFactoryInterface $stateMachineFactory)
26
    {
27
        $this->stateMachineFactory = $stateMachineFactory;
28
    }
29
30
    public function complete(PaymentInterface $data): PaymentInterface
31
    {
32
        $this->applyTransition($data, PaymentTransitions::TRANSITION_COMPLETE);
33
34
        return $data;
35
    }
36
37
    private function applyTransition(PaymentInterface $payment, string $transition): void
38
    {
39
        $stateMachine = $this->stateMachineFactory->get($payment, PaymentTransitions::GRAPH);
40
        $stateMachine->apply($transition);
41
    }
42
}
43