Passed
Push — master ( 8bd912...d93388 )
by Alan
06:58 queued 02:20
created

Bridge/Symfony/Routing/CachedRouteNameResolver.php (1 issue)

1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
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
declare(strict_types=1);
13
14
namespace ApiPlatform\Core\Bridge\Symfony\Routing;
15
16
use ApiPlatform\Core\Cache\CachedTrait;
17
use Psr\Cache\CacheItemPoolInterface;
18
19
/**
20
 * {@inheritdoc}
21
 *
22
 * @author Teoh Han Hui <[email protected]>
23
 */
24
final class CachedRouteNameResolver implements RouteNameResolverInterface
25
{
26
    use CachedTrait;
27
28
    public const CACHE_KEY_PREFIX = 'route_name_';
29
30
    private $decorated;
31
32
    public function __construct(CacheItemPoolInterface $cacheItemPool, RouteNameResolverInterface $decorated)
33
    {
34
        $this->cacheItemPool = $cacheItemPool;
35
        $this->decorated = $decorated;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getRouteName(string $resourceClass, $operationType /*, array $context = []*/): string
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
42
    {
43
        $context = \func_num_args() > 2 ? func_get_arg(2) : [];
44
        $cacheKey = self::CACHE_KEY_PREFIX.md5(serialize([$resourceClass, $operationType, $context['subresource_resources'] ?? null]));
45
46
        return $this->getCached($cacheKey, function () use ($resourceClass, $operationType, $context) {
47
            return $this->decorated->getRouteName($resourceClass, $operationType, $context);
48
        });
49
    }
50
}
51