SymfonyFullyQualifiedClassNameConverter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 32
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A normalize() 0 11 2
A denormalize() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Kreta\Notifier\Infrastructure\Serialization;
16
17
use Kreta\SharedKernel\Domain\Model\InvalidArgumentException;
18
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
19
20
final class SymfonyFullyQualifiedClassNameConverter implements NameConverterInterface
21
{
22
    private $nameConverter;
23
24
    public function __construct(NameConverterInterface $nameConverter)
25
    {
26
        $this->nameConverter = $nameConverter;
27
    }
28
29
    public function normalize($propertyName) : string
30
    {
31
        if (false === class_exists($propertyName)) {
32
            throw new InvalidArgumentException('The given parameter is not a valid fully qualified class name');
33
        }
34
35
        $reflectionClass = new \ReflectionClass($propertyName);
36
        $className = $reflectionClass->getShortName();
37
38
        return $this->nameConverter->normalize($className);
39
    }
40
41
    public function denormalize($propertyName) : string
42
    {
43
        $className = $this->nameConverter->denormalize($propertyName);
44
45
        if (false !== mb_strpos($className, 'Notification')) {
46
            $className = 'Notification\\' . $className;
47
        }
48
49
        return 'Kreta\\Notifier\\Domain\\Model\\Inbox\\' . $className;
50
    }
51
}
52