JWSNormalizer   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 38
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsNormalization() 0 4 2
A supportsDenormalization() 0 4 2
A normalize() 0 4 1
A denormalize() 0 4 1
A componentInstalled() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2019 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace Jose\Bundle\JoseFramework\Normalizer;
15
16
use Jose\Component\Signature\JWS;
17
use Jose\Component\Signature\Serializer\JWSSerializerManager;
18
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
19
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
20
21
final class JWSNormalizer implements NormalizerInterface, DenormalizerInterface
22
{
23
    public function supportsNormalization($data, $format = null)
24
    {
25
        return $data instanceof JWS && $this->componentInstalled();
26
    }
27
28
    public function supportsDenormalization($data, $type, $format = null)
29
    {
30
        return JWS::class === $type && $this->componentInstalled();
31
    }
32
33
    public function normalize($object, $format = null, array $context = [])
34
    {
35
        return $object;
36
    }
37
38
    /**
39
     * @param mixed  $data    Data to restore
40
     * @param string $type    The expected class to instantiate
41
     * @param string $format  Format the given data was extracted from
42
     * @param array  $context Options available to the denormalizer
43
     *
44
     * @return array|object
45
     */
46
    public function denormalize($data, $type, $format = null, array $context = [])
47
    {
48
        return $data;
49
    }
50
51
    /**
52
     * Check if encryption component is installed.
53
     */
54
    private function componentInstalled(): bool
55
    {
56
        return class_exists(JWSSerializerManager::class);
57
    }
58
}
59