Conditions | 7 |
Paths | 6 |
Total Lines | 16 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
29 | public function getRouteName(string $resourceClass, bool $collection) : string |
||
30 | { |
||
31 | $operationType = $collection ? 'collection' : 'item'; |
||
32 | |||
33 | foreach ($this->router->getRouteCollection()->all() as $routeName => $route) { |
||
34 | $currentResourceClass = $route->getDefault('_api_resource_class'); |
||
35 | $operation = $route->getDefault(sprintf('_api_%s_operation_name', $operationType)); |
||
36 | $methods = $route->getMethods(); |
||
37 | |||
38 | if ($resourceClass === $currentResourceClass && null !== $operation && (empty($methods) || in_array('GET', $methods))) { |
||
39 | return $routeName; |
||
40 | } |
||
41 | } |
||
42 | |||
43 | throw new InvalidArgumentException(sprintf('No %s route associated with the type "%s".', $operationType, $resourceClass)); |
||
44 | } |
||
45 | } |
||
46 |