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

ProductReviewStateMachineTransitionApplicator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A accept() 0 6 1
A reject() 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\Core\ProductReviewTransitions;
18
use Sylius\Component\Review\Model\ReviewInterface;
19
20
final class ProductReviewStateMachineTransitionApplicator
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 accept(ReviewInterface $data): ReviewInterface
31
    {
32
        $this->applyTransition($data, ProductReviewTransitions::TRANSITION_ACCEPT);
33
34
        return $data;
35
    }
36
37
    public function reject(ReviewInterface $data): ReviewInterface
38
    {
39
        $this->applyTransition($data, ProductReviewTransitions::TRANSITION_REJECT);
40
41
        return $data;
42
    }
43
44
    private function applyTransition(ReviewInterface $review, string $transition): void
45
    {
46
        $stateMachine = $this->stateMachineFactory->get($review, ProductReviewTransitions::GRAPH);
47
        $stateMachine->apply($transition);
48
    }
49
}
50