JWENormalizer   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 43
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\Encryption\JWE;
17
use Jose\Component\Encryption\Serializer\JWESerializerManager;
18
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
19
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
20
21
final class JWENormalizer implements NormalizerInterface, DenormalizerInterface
22
{
23
    public function supportsNormalization($data, $format = null)
24
    {
25
        return $data instanceof JWE && $this->componentInstalled();
26
    }
27
28
    public function supportsDenormalization($data, $type, $format = null)
29
    {
30
        return JWE::class === $type && $this->componentInstalled();
31
    }
32
33
    /**
34
     * @param mixed  $object Object to normalize
35
     * @param string $format Format the normalization result will be encoded as
36
     *
37
     * @return mixed
38
     */
39
    public function normalize($object, $format = null, array $context = [])
40
    {
41
        return $object;
42
    }
43
44
    /**
45
     * @param mixed  $data   Data to restore
46
     * @param string $type   The expected class to instantiate
47
     * @param string $format Format the given data was extracted from
48
     *
49
     * @return array|object
50
     */
51
    public function denormalize($data, $type, $format = null, array $context = [])
52
    {
53
        return $data;
54
    }
55
56
    /**
57
     * Check if encryption component is installed.
58
     */
59
    private function componentInstalled(): bool
60
    {
61
        return class_exists(JWESerializerManager::class);
62
    }
63
}
64