WorkflowActionContextBuilder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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