Completed
Pull Request — 2.x (#2227)
by
unknown
08:36
created

Serializer/JMSHandlerRegistryV2.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
use Symfony\Component\ErrorHandler\Exception\FlattenException;
17
18
/**
19
 * Search in the class parents to find an adapted handler.
20
 *
21
 * @author Ener-Getick <[email protected]>
22
 *
23
 * @internal do not depend on this class directly
24
 *
25
 * @deprecated since FOSRestBundle 3.1, use the option `fos_rest.serializer.disable_custom_jms_registry` to avoid relying on it.
26
 */
27 View Code Duplication
final class JMSHandlerRegistryV2 implements HandlerRegistryInterface
28 10
{
29
    private $registry;
30 10
31 10
    public function __construct(HandlerRegistryInterface $registry)
32
    {
33
        $this->registry = $registry;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function registerSubscribingHandler(SubscribingHandlerInterface $handler): void
40
    {
41
        $this->registry->registerSubscribingHandler($handler);
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function registerHandler(int $direction, string $typeName, string $format, $handler): void
48
    {
49
        $this->registry->registerHandler($direction, $typeName, $format, $handler);
50
    }
51
52 9
    /**
53
     * {@inheritdoc}
54
     */
55 9
    public function getHandler(int $direction, string $typeName, string $format)
56 9
    {
57 9
        $first = true;
58
        do {
59 3
            $handler = $this->registry->getHandler($direction, $typeName, $format);
60
            if (null !== $handler) {
61
                if (!$first) {
62
                    @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...
63
                }
64
65
                return $handler;
66
            }
67
68
            $first = false;
69
        } while ($typeName = get_parent_class($typeName));
70
    }
71
}
72