Completed
Push — master ( 29b346...1faa7f )
by Amrouche
19s
created

Symfony/Routing/RouterOperationPathResolver.php (1 issue)

Severity

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 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\Api\OperationType;
17
use ApiPlatform\Core\Api\OperationTypeDeprecationHelper;
18
use ApiPlatform\Core\Exception\InvalidArgumentException;
19
use ApiPlatform\Core\PathResolver\OperationPathResolverInterface;
20
use Symfony\Component\Routing\RouterInterface;
21
22
/**
23
 * Resolves the operations path using a Symfony route.
24
 *
25
 * @author Guilhem N. <[email protected]>
26
 */
27
final class RouterOperationPathResolver implements OperationPathResolverInterface
28
{
29
    private $router;
30
    private $deferred;
31
32
    public function __construct(RouterInterface $router, OperationPathResolverInterface $deferred)
33
    {
34
        $this->router = $router;
35
        $this->deferred = $deferred;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     *
41
     * @throws InvalidArgumentException
42
     */
43
    public function resolveOperationPath(string $resourceShortName, array $operation, $operationType/*, string $operationName = null*/): string
44
    {
45 View Code Duplication
        if (func_num_args() >= 4) {
46
            $operationName = func_get_arg(3);
47
        } else {
48
            @trigger_error(sprintf('Method %s() will have a 4th `string $operationName` argument in version 3.0. Not defining it is deprecated since 2.1.', __METHOD__), E_USER_DEPRECATED);
49
50
            $operationName = null;
51
        }
52
53
        if (isset($operation['route_name'])) {
54
            $routeName = $operation['route_name'];
55
        } elseif (OperationType::SUBRESOURCE === $operationType) {
56
            throw new InvalidArgumentException('Subresource operations are not supported by the RouterOperationPathResolver without a route name.');
57
        } elseif (null === $operationName) {
58
            return $this->deferred->resolveOperationPath($resourceShortName, $operation, OperationTypeDeprecationHelper::getOperationType($operationType), $operationName);
0 ignored issues
show
The call to OperationPathResolverInt...:resolveOperationPath() has too many arguments starting with $operationName.

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 @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
59
        } else {
60
            $routeName = RouteNameGenerator::generate($operationName, $resourceShortName, $operationType);
61
        }
62
63
        if (!$route = $this->router->getRouteCollection()->get($routeName)) {
64
            throw new InvalidArgumentException(sprintf('The route "%s" of the resource "%s" was not found.', $routeName, $resourceShortName));
65
        }
66
67
        return $route->getPath();
68
    }
69
}
70