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 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 Psr\Cache\CacheException; |
||
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 | const CACHE_KEY_PREFIX = 'route_name_'; |
||
27 | |||
28 | private $cacheItemPool; |
||
29 | private $decorated; |
||
30 | |||
31 | public function __construct(CacheItemPoolInterface $cacheItemPool, RouteNameResolverInterface $decorated) |
||
32 | { |
||
33 | $this->cacheItemPool = $cacheItemPool; |
||
34 | $this->decorated = $decorated; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * {@inheritdoc} |
||
39 | */ |
||
40 | public function getRouteName(string $resourceClass, $operationType /**, array $context = []**/): string |
||
0 ignored issues
–
show
|
|||
41 | { |
||
42 | $cacheKey = self::CACHE_KEY_PREFIX.md5(serialize([$resourceClass, $operationType])); |
||
43 | |||
44 | try { |
||
45 | $cacheItem = $this->cacheItemPool->getItem($cacheKey); |
||
46 | |||
47 | if ($cacheItem->isHit()) { |
||
48 | return $cacheItem->get(); |
||
49 | } |
||
50 | } catch (CacheException $e) { |
||
51 | // do nothing |
||
52 | } |
||
53 | |||
54 | if (func_num_args() > 2) { |
||
55 | $context = func_get_arg(2); |
||
56 | } else { |
||
57 | $context = []; |
||
58 | } |
||
59 | |||
60 | $routeName = $this->decorated->getRouteName($resourceClass, $operationType, $context); |
||
0 ignored issues
–
show
The call to
RouteNameResolverInterface::getRouteName() has too many arguments starting with $context .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
61 | |||
62 | if (!isset($cacheItem)) { |
||
63 | return $routeName; |
||
64 | } |
||
65 | |||
66 | try { |
||
67 | $cacheItem->set($routeName); |
||
68 | $this->cacheItemPool->save($cacheItem); |
||
69 | } catch (CacheException $e) { |
||
70 | // do nothing |
||
71 | } |
||
72 | |||
73 | return $routeName; |
||
74 | } |
||
75 | } |
||
76 |
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.