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