Completed
Pull Request — master (#1358)
by Guilh
07:06
created

JMSHandlerRegistry   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 61.53%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 38
ccs 8
cts 13
cp 0.6153
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A registerSubscribingHandler() 0 4 1
A registerHandler() 0 4 1
A getHandler() 0 9 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
class JMSHandlerRegistry implements HandlerRegistryInterface
25
{
26
    private $registry;
27
28 4
    public function __construct(HandlerRegistryInterface $registry)
29
    {
30 4
        $this->registry = $registry;
31 4
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function registerSubscribingHandler(SubscribingHandlerInterface $handler)
37
    {
38
        return $this->registry->registerSubscribingHandler($handler);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function registerHandler($direction, $typeName, $format, $handler)
45
    {
46
        return $this->registry->registerHandler($direction, $typeName, $format, $handler);
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 4
    public function getHandler($direction, $typeName, $format)
53
    {
54
        do {
55 4
            $handler = $this->registry->getHandler($direction, $typeName, $format);
56 4
            if (null !== $handler) {
57 4
                return $handler;
58
            }
59 2
        } while ($typeName = get_parent_class($typeName));
60
    }
61
}
62