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