Completed
Push — master ( 39fc21...35ccb7 )
by
unknown
06:49
created

JMSHandlerRegistryV2::getHandler()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.9666
c 0
b 0
f 0
cc 3
nc 2
nop 3
1
<?php
2
3
/*
4
 * This file is part of the FOSRestBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
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 FOS\RestBundle\Serializer;
13
14
use JMS\Serializer\Handler\SubscribingHandlerInterface;
15
use JMS\Serializer\Handler\HandlerRegistryInterface;
16
17
/**
18
 * Search in the class parents to find an adapted handler.
19
 *
20
 * @author Ener-Getick <[email protected]>
21
 *
22
 * @internal do not depend on this class directly
23
 */
24 View Code Duplication
final class JMSHandlerRegistryV2 implements HandlerRegistryInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
{
26
    private $registry;
27
28
    public function __construct(HandlerRegistryInterface $registry)
29
    {
30
        $this->registry = $registry;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function registerSubscribingHandler(SubscribingHandlerInterface $handler): void
37
    {
38
        $this->registry->registerSubscribingHandler($handler);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function registerHandler(int $direction, string $typeName, string $format, $handler): void
45
    {
46
        $this->registry->registerHandler($direction, $typeName, $format, $handler);
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function getHandler(int $direction, string $typeName, string $format)
53
    {
54
        do {
55
            $handler = $this->registry->getHandler($direction, $typeName, $format);
56
            if (null !== $handler) {
57
                return $handler;
58
            }
59
        } while ($typeName = get_parent_class($typeName));
60
    }
61
}
62