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

complete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 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