WorkflowActionContextBuilder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createFromRequest() 0 13 4
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) 2019, Wesley O. Nichols
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 Wesnick\WorkflowBundle\Serializer;
13
14
use ApiPlatform\Core\Serializer\SerializerContextBuilderInterface;
15
use Symfony\Component\HttpFoundation\Request;
16
use Wesnick\WorkflowBundle\Model\PotentialActionInterface;
17
18
/**
19
 * Class WorkflowActionContextBuilder.
20
 *
21
 * @author Wesley O. Nichols <[email protected]>
22
 */
23
class WorkflowActionContextBuilder implements SerializerContextBuilderInterface
24
{
25
    private $decorated;
26
27
    public function __construct(SerializerContextBuilderInterface $decorated)
28
    {
29
        $this->decorated = $decorated;
30
    }
31
32
    public function createFromRequest(Request $request, bool $normalization, ?array $extractedAttributes = null): array
33
    {
34
        $context = $this->decorated->createFromRequest($request, $normalization, $extractedAttributes);
35
        $resourceClass = $context['resource_class'] ?? null;
36
37
        if (is_a($resourceClass, PotentialActionInterface::class, true)
38
            && isset($context['groups'])
39
            && true === $normalization
40
        ) {
41
            $context['groups'][] = 'workflowAction:output';
42
        }
43
44
        return $context;
45
    }
46
}
47