hasCacheableSupportsMethod()   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 0
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\Hydra\Serializer\DocumentationNormalizer;
15
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
16
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
17
18
/**
19
 * Class ActionsDocumentationNormalizer.
20
 *
21
 * @author Wesley O. Nichols <[email protected]>
22
 */
23
class ActionsDocumentationNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
24
{
25
    public const FORMAT = 'jsonld';
26
27
    private $decorated;
28
29
    public function __construct(DocumentationNormalizer $decorated)
30
    {
31
        $this->decorated = $decorated;
32
    }
33
34
    public function hasCacheableSupportsMethod(): bool
35
    {
36
        return true;
37
    }
38
39
    public function normalize($object, $format = null, array $context = [])
40
    {
41
        // @TODO: review that this is even gets hydra to do anything extra
42
        $data = $this->decorated->normalize($object, $format, $context);
43
44
        // Add in our empty payload class
45
        $data['hydra:supportedClass'][] = [
46
            '@id' => '#WorkflowDTO',
47
            '@type' => 'hydra:Class',
48
            'hydra:title' => 'WorkflowDTO',
49
            'hydra:label' => 'WorkflowDTO',
50
            'hydra:description' => 'Represents workflow name and transition.',
51
        ];
52
53
        return $data;
54
    }
55
56
    public function supportsNormalization($data, $format = null)
57
    {
58
        return $this->decorated->supportsNormalization($data, $format);
59
    }
60
}
61