Completed
Pull Request — master (#2227)
by
unknown
09:01 queued 07:35
created

JMSHandlerRegistryV2::getHandler()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 16

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 5.024

Importance

Changes 0
Metric Value
dl 16
loc 16
ccs 6
cts 10
cp 0.6
rs 9.7333
c 0
b 0
f 0
cc 4
nc 3
nop 3
crap 5.024
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
 * @deprecated since FOSRestBundle 3.1, use the option `fos_rest.serializer.disable_custom_jms_registry` to avoid relying on it.
25
 */
26 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...
27
{
28
    private $registry;
29
30 8
    public function __construct(HandlerRegistryInterface $registry)
31
    {
32 8
        $this->registry = $registry;
33 8
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function registerSubscribingHandler(SubscribingHandlerInterface $handler): void
39
    {
40
        $this->registry->registerSubscribingHandler($handler);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function registerHandler(int $direction, string $typeName, string $format, $handler): void
47
    {
48
        $this->registry->registerHandler($direction, $typeName, $format, $handler);
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 6
    public function getHandler(int $direction, string $typeName, string $format)
55
    {
56 6
        $first = true;
57
        do {
58 6
            $handler = $this->registry->getHandler($direction, $typeName, $format);
59 6
            if (null !== $handler) {
60 6
                if (!$first) {
61
                    @trigger_error(sprintf('Relying on the custom registry %s to inherit the JMS handler of type `%s` is deprecated since FOSRestBundle 3.1. It will be removed in version 4.0. Use the option `fos_rest.serializer.disable_custom_jms_registry` to disable it.', __CLASS__, $typeName), E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
62
                }
63
64 6
                return $handler;
65
            }
66
67
            $first = false;
68
        } while ($typeName = get_parent_class($typeName));
69
    }
70
}
71