JMSHandlerRegistryV2::getHandler()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.3332

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 4
cts 6
cp 0.6667
rs 9.9666
c 0
b 0
f 0
cc 3
nc 2
nop 3
crap 3.3332
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
final class JMSHandlerRegistryV2 implements HandlerRegistryInterface
25
{
26
    private $registry;
27
28 7
    public function __construct(HandlerRegistryInterface $registry)
29
    {
30 7
        $this->registry = $registry;
31 7
    }
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 6
    public function getHandler(int $direction, string $typeName, string $format)
53
    {
54
        do {
55 6
            $handler = $this->registry->getHandler($direction, $typeName, $format);
56 6
            if (null !== $handler) {
57 6
                return $handler;
58
            }
59
        } while ($typeName = get_parent_class($typeName));
60
    }
61
}
62