|
84 | 84 |
|
85 | 85 | $appIsCore = false; |
86 | 86 | $appID = (string)$xml->id; |
87 | | - if ($xml->namespace) { |
88 | | - $readableAppID = (string)$xml->namespace; |
89 | | - } else { |
90 | | - $readableAppID = Helpers::generateReadableAppID($appID); |
91 | | - } |
| 87 | + $readableAppID = $xml->namespace ? (string)$xml->namespace : Helpers::generateReadableAppID($appID); |
92 | 88 | $appSummary = (string)$xml->summary; |
93 | 89 | $appVersion = (string)$xml->version; |
94 | 90 | $appLicence = (string)$xml->licence; |
|
182 | 178 | * @var Class_ $node |
183 | 179 | */ |
184 | 180 | foreach ($nodeFinder->findInstanceOf($astParser->parse(file_get_contents($path)), Class_::class) as $node) { |
185 | | - $implementsCapability = count(array_filter($node->implements, fn (Name $name): bool => $name->getLast() == 'ICapability')) > 0; |
186 | | - $implementsPublicCapability = count(array_filter($node->implements, fn (Name $name): bool => $name->getLast() == 'IPublicCapability')) > 0; |
| 181 | + $implementsCapability = array_filter($node->implements, fn (Name $name): bool => $name->getLast() === 'ICapability') !== []; |
| 182 | + $implementsPublicCapability = array_filter($node->implements, fn (Name $name): bool => $name->getLast() === 'IPublicCapability') !== []; |
187 | 183 | if (!$implementsCapability && !$implementsPublicCapability) { |
188 | 184 | continue; |
189 | 185 | } |
|
327 | 323 | } |
328 | 324 | } |
329 | 325 |
|
330 | | -if (count($parsedRoutes) === 0) { |
| 326 | +if ($parsedRoutes === []) { |
331 | 327 | Logger::warning('Routes', 'No routes were loaded'); |
332 | 328 | } |
333 | 329 |
|
|
343 | 339 | foreach ($value as $route) { |
344 | 340 | $routeName = $route['name']; |
345 | 341 |
|
346 | | - $postfix = array_key_exists('postfix', $route) ? $route['postfix'] : null; |
| 342 | + $postfix = $route['postfix'] ?? null; |
347 | 343 | $verb = array_key_exists('verb', $route) ? $route['verb'] : 'GET'; |
348 | 344 | $requirements = array_key_exists('requirements', $route) ? $route['requirements'] : []; |
349 | 345 | $defaults = array_key_exists('defaults', $route) ? $route['defaults'] : []; |
|
358 | 354 | $url = $pathPrefix . $root . $url; |
359 | 355 |
|
360 | 356 | $methodName = lcfirst(str_replace('_', '', ucwords(explode('#', (string)$routeName)[1], '_'))); |
361 | | - if ($methodName == 'preflightedCors') { |
| 357 | + if ($methodName === 'preflightedCors') { |
362 | 358 | continue; |
363 | 359 | } |
364 | 360 |
|
|
390 | 386 |
|
391 | 387 | $controllerScopes = Helpers::getOpenAPIAttributeScopes($controllerClass, $routeName); |
392 | 388 | if (Helpers::classMethodHasAnnotationOrAttribute($controllerClass, 'IgnoreOpenAPI')) { |
393 | | - if (count($controllerScopes) === 0 || (in_array('ignore', $controllerScopes, true) && count($controllerScopes) === 1)) { |
| 389 | + if ($controllerScopes === [] || (in_array('ignore', $controllerScopes, true) && count($controllerScopes) === 1)) { |
394 | 390 | Logger::debug($routeName, "Controller '" . $controllerName . "' ignored because of IgnoreOpenAPI attribute"); |
395 | 391 | continue; |
396 | 392 | } |
|
409 | 405 |
|
410 | 406 | $tagName = implode('_', array_map(fn (string $s) => strtolower($s), Helpers::splitOnUppercaseFollowedByNonUppercase($controllerName))); |
411 | 407 | $doc = $controllerClass->getDocComment()?->getText(); |
412 | | - if ($doc != null && count(array_filter($tags, fn (array $tag): bool => $tag['name'] == $tagName)) == 0) { |
| 408 | + if ($doc != null && count(array_filter($tags, fn (array $tag): bool => $tag['name'] === $tagName)) == 0) { |
413 | 409 | $classDescription = []; |
414 | 410 |
|
415 | 411 | $docNodes = $phpDocParser->parse(new TokenIterator($lexer->tokenize($doc)))->children; |
416 | 412 | foreach ($docNodes as $docNode) { |
417 | 413 | if ($docNode instanceof PhpDocTextNode) { |
418 | 414 | $block = Helpers::cleanDocComment($docNode->text); |
419 | | - if ($block == '') { |
| 415 | + if ($block === '') { |
420 | 416 | continue; |
421 | 417 | } |
422 | 418 | $classDescription[] = $block; |
423 | 419 | } |
424 | 420 | } |
425 | 421 |
|
426 | | - if (count($classDescription) > 0) { |
| 422 | + if ($classDescription !== []) { |
427 | 423 | $tags[] = [ |
428 | 424 | 'name' => $tagName, |
429 | | - 'description' => join("\n", $classDescription), |
| 425 | + 'description' => implode("\n", $classDescription), |
430 | 426 | ]; |
431 | 427 | } |
432 | 428 | } |
|
454 | 450 | $scopes = Helpers::getOpenAPIAttributeScopes($classMethod, $routeName); |
455 | 451 |
|
456 | 452 | if ($isIgnored) { |
457 | | - if (count($scopes) === 0 || (in_array('ignore', $scopes, true) && count($scopes) === 1)) { |
| 453 | + if ($scopes === [] || (in_array('ignore', $scopes, true) && count($scopes) === 1)) { |
458 | 454 | Logger::debug($routeName, 'Route ignored because of IgnoreOpenAPI attribute'); |
459 | 455 | continue; |
460 | 456 | } |
|
503 | 499 | } |
504 | 500 |
|
505 | 501 | $classMethodInfo = ControllerMethod::parse($routeName, $definitions, $methodFunction, $isAdmin, $isDeprecated, $isPasswordConfirmation); |
506 | | - if (count($classMethodInfo->returns) > 0) { |
| 502 | + if ($classMethodInfo->returns !== []) { |
507 | 503 | Logger::error($routeName, 'Returns an invalid response'); |
508 | 504 | continue; |
509 | 505 | } |
|
527 | 523 | $docStatusCodes = array_map(fn (ControllerMethodResponse $response): int => $response->statusCode, array_filter($classMethodInfo->responses, fn (?ControllerMethodResponse $response): bool => $response != null)); |
528 | 524 | $missingDocStatusCodes = array_unique(array_filter(array_diff($codeStatusCodes, $docStatusCodes), fn (int $code): bool => $code < 500)); |
529 | 525 |
|
530 | | - if (count($missingDocStatusCodes) > 0) { |
| 526 | + if ($missingDocStatusCodes !== []) { |
531 | 527 | Logger::error($routeName, 'Returns undocumented status codes: ' . implode(', ', $missingDocStatusCodes)); |
532 | 528 | continue; |
533 | 529 | } |
|
593 | 589 |
|
594 | 590 | foreach ($urlParameters as $urlParameter) { |
595 | 591 | $matchingParameters = array_filter($route->controllerMethod->parameters, fn (ControllerMethodParameter $param): bool => $param->name == $urlParameter); |
596 | | - $requirement = array_key_exists($urlParameter, $route->requirements) ? $route->requirements[$urlParameter] : null; |
| 592 | + $requirement = $route->requirements[$urlParameter] ?? null; |
597 | 593 | if (count($matchingParameters) == 1) { |
598 | 594 | $parameter = $matchingParameters[array_keys($matchingParameters)[0]]; |
599 | 595 | if ($parameter?->methodParameter == null && ($route->requirements == null || !array_key_exists($urlParameter, $route->requirements))) { |
|
615 | 611 | $requirement = '^' . $requirement; |
616 | 612 | } |
617 | 613 | if (!str_ends_with((string)$requirement, '$')) { |
618 | | - $requirement = $requirement . '$'; |
| 614 | + $requirement .= '$'; |
619 | 615 | } |
620 | 616 | } |
621 | 617 |
|
|
677 | 673 |
|
678 | 674 | $mergedResponses = []; |
679 | 675 | foreach (array_unique(array_map(fn (ControllerMethodResponse $response): int => $response->statusCode, array_filter($route->controllerMethod->responses, fn (?ControllerMethodResponse $response): bool => $response != null))) as $statusCode) { |
680 | | - if ($firstStatusCode && count($mergedResponses) > 0) { |
| 676 | + if ($firstStatusCode && $mergedResponses !== []) { |
681 | 677 | break; |
682 | 678 | } |
683 | 679 |
|
|
691 | 687 |
|
692 | 688 | $mergedContentTypeResponses = []; |
693 | 689 | foreach (array_unique(array_map(fn (ControllerMethodResponse $response): ?string => $response->contentType, array_filter($statusCodeResponses, fn (ControllerMethodResponse $response): bool => $response->contentType != null))) as $contentType) { |
694 | | - if ($firstContentType && count($mergedContentTypeResponses) > 0) { |
| 690 | + if ($firstContentType && $mergedContentTypeResponses !== []) { |
695 | 691 | break; |
696 | 692 | } |
697 | 693 |
|
698 | 694 | /** @var ControllerMethodResponse[] $contentTypeResponses */ |
699 | 695 | $contentTypeResponses = array_values(array_filter($statusCodeResponses, fn (ControllerMethodResponse $response): bool => $response->contentType == $contentType)); |
700 | 696 |
|
701 | | - $hasEmpty = count(array_filter($contentTypeResponses, fn (ControllerMethodResponse $response): bool => $response->type == null)) > 0; |
| 697 | + $hasEmpty = array_filter($contentTypeResponses, fn (ControllerMethodResponse $response): bool => $response->type == null) !== []; |
702 | 698 | $uniqueResponses = array_values(array_intersect_key($contentTypeResponses, array_unique(array_map(fn (ControllerMethodResponse $response): array|\stdClass => $response->type->toArray(), array_filter($contentTypeResponses, fn (ControllerMethodResponse $response): bool => $response->type != null)), SORT_REGULAR))); |
703 | 699 | if (count($uniqueResponses) == 1) { |
704 | 700 | if ($hasEmpty) { |
|
722 | 718 | $response = [ |
723 | 719 | 'description' => array_key_exists($statusCode, $route->controllerMethod->responseDescription) ? $route->controllerMethod->responseDescription[$statusCode] : '', |
724 | 720 | ]; |
725 | | - if (count($headers) > 0) { |
| 721 | + if ($headers !== []) { |
726 | 722 | $response['headers'] = array_combine( |
727 | 723 | array_keys($headers), |
728 | 724 | array_map( |
|
733 | 729 | ), |
734 | 730 | ); |
735 | 731 | } |
736 | | - if (count($mergedContentTypeResponses) > 0) { |
| 732 | + if ($mergedContentTypeResponses !== []) { |
737 | 733 | $response['content'] = $mergedContentTypeResponses; |
738 | 734 | } |
739 | 735 | $mergedResponses[$statusCode] = $response; |
|
757 | 753 | if ($route->controllerMethod->summary !== null) { |
758 | 754 | $operation['summary'] = $route->controllerMethod->summary; |
759 | 755 | } |
760 | | - if (count($route->controllerMethod->description) > 0) { |
| 756 | + if ($route->controllerMethod->description !== []) { |
761 | 757 | $operation['description'] = implode("\n", $route->controllerMethod->description); |
762 | 758 | } |
763 | 759 | if ($route->controllerMethod->isDeprecated) { |
|
768 | 764 | } |
769 | 765 | $operation['security'] = $security; |
770 | 766 |
|
771 | | - if (count($bodyParameters) > 0) { |
| 767 | + if ($bodyParameters !== []) { |
772 | 768 | $requiredBodyParameters = []; |
773 | 769 |
|
774 | 770 | foreach ($bodyParameters as $bodyParameter) { |
|
778 | 774 | } |
779 | 775 | } |
780 | 776 |
|
781 | | - $required = count($requiredBodyParameters) > 0; |
| 777 | + $required = $requiredBodyParameters !== []; |
782 | 778 |
|
783 | 779 | $schema = [ |
784 | 780 | 'type' => 'object', |
|
829 | 825 | ], |
830 | 826 | ]; |
831 | 827 | } |
832 | | - if (count($parameters) > 0) { |
| 828 | + if ($parameters !== []) { |
833 | 829 | $operation['parameters'] = $parameters; |
834 | 830 | } |
835 | 831 |
|
|
925 | 921 |
|
926 | 922 | if (!$hasSingleScope) { |
927 | 923 | $scopePaths['full'] = []; |
928 | | -} elseif (count($scopePaths) === 0) { |
| 924 | +} elseif ($scopePaths === []) { |
929 | 925 | if (isset($schemas['Capabilities']) || isset($schemas['PublicCapabilities'])) { |
930 | 926 | Logger::debug('app', 'Generating default scope without routes to populate capabilities'); |
931 | 927 | $scopePaths['default'] = []; |
|
994 | 990 | $scopedSchemas['PublicCapabilities'] = $schemas['PublicCapabilities']; |
995 | 991 | } |
996 | 992 |
|
997 | | - if (count($scopedSchemas) === 0) { |
| 993 | + if ($scopedSchemas === []) { |
998 | 994 | $scopedSchemas = new stdClass(); |
999 | 995 | } else { |
1000 | 996 | ksort($scopedSchemas); |
|
0 commit comments