|
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 |
|
|
344 | 340 | foreach ($value as $route) { |
345 | 341 | $routeName = $route['name']; |
346 | 342 |
|
347 | | - $postfix = array_key_exists('postfix', $route) ? $route['postfix'] : null; |
| 343 | + $postfix = $route['postfix'] ?? null; |
348 | 344 | $verb = array_key_exists('verb', $route) ? $route['verb'] : 'GET'; |
349 | 345 | $requirements = array_key_exists('requirements', $route) ? $route['requirements'] : []; |
350 | 346 | $defaults = array_key_exists('defaults', $route) ? $route['defaults'] : []; |
|
364 | 360 | } |
365 | 361 |
|
366 | 362 | $methodName = lcfirst(str_replace('_', '', ucwords(explode('#', (string)$routeName)[1], '_'))); |
367 | | - if ($methodName == 'preflightedCors') { |
| 363 | + if ($methodName === 'preflightedCors') { |
368 | 364 | continue; |
369 | 365 | } |
370 | 366 |
|
|
384 | 380 |
|
385 | 381 | $controllerScopes = Helpers::getOpenAPIAttributeScopes($controllerClass, $routeName); |
386 | 382 | if (Helpers::classMethodHasAnnotationOrAttribute($controllerClass, 'IgnoreOpenAPI')) { |
387 | | - if (count($controllerScopes) === 0 || (in_array('ignore', $controllerScopes, true) && count($controllerScopes) === 1)) { |
| 383 | + if ($controllerScopes === [] || (in_array('ignore', $controllerScopes, true) && count($controllerScopes) === 1)) { |
388 | 384 | Logger::debug($routeName, "Controller '" . $controllerName . "' ignored because of IgnoreOpenAPI attribute"); |
389 | 385 | continue; |
390 | 386 | } |
|
403 | 399 |
|
404 | 400 | $tagName = implode('_', array_map(fn (string $s) => strtolower($s), Helpers::splitOnUppercaseFollowedByNonUppercase($controllerName))); |
405 | 401 | $doc = $controllerClass->getDocComment()?->getText(); |
406 | | - if ($doc != null && count(array_filter($tags, fn (array $tag): bool => $tag['name'] == $tagName)) == 0) { |
| 402 | + if ($doc != null && count(array_filter($tags, fn (array $tag): bool => $tag['name'] === $tagName)) == 0) { |
407 | 403 | $classDescription = []; |
408 | 404 |
|
409 | 405 | $docNodes = $phpDocParser->parse(new TokenIterator($lexer->tokenize($doc)))->children; |
410 | 406 | foreach ($docNodes as $docNode) { |
411 | 407 | if ($docNode instanceof PhpDocTextNode) { |
412 | 408 | $block = Helpers::cleanDocComment($docNode->text); |
413 | | - if ($block == '') { |
| 409 | + if ($block === '') { |
414 | 410 | continue; |
415 | 411 | } |
416 | 412 | $classDescription[] = $block; |
417 | 413 | } |
418 | 414 | } |
419 | 415 |
|
420 | | - if (count($classDescription) > 0) { |
| 416 | + if ($classDescription !== []) { |
421 | 417 | $tags[] = [ |
422 | 418 | 'name' => $tagName, |
423 | | - 'description' => join("\n", $classDescription), |
| 419 | + 'description' => implode("\n", $classDescription), |
424 | 420 | ]; |
425 | 421 | } |
426 | 422 | } |
|
448 | 444 | $scopes = Helpers::getOpenAPIAttributeScopes($classMethod, $routeName); |
449 | 445 |
|
450 | 446 | if ($isIgnored) { |
451 | | - if (count($scopes) === 0 || (in_array('ignore', $scopes, true) && count($scopes) === 1)) { |
| 447 | + if ($scopes === [] || (in_array('ignore', $scopes, true) && count($scopes) === 1)) { |
452 | 448 | Logger::debug($routeName, 'Route ignored because of IgnoreOpenAPI attribute'); |
453 | 449 | continue; |
454 | 450 | } |
|
497 | 493 | } |
498 | 494 |
|
499 | 495 | $classMethodInfo = ControllerMethod::parse($routeName, $definitions, $methodFunction, $isAdmin, $isDeprecated, $isPasswordConfirmation); |
500 | | - if (count($classMethodInfo->returns) > 0) { |
| 496 | + if ($classMethodInfo->returns !== []) { |
501 | 497 | Logger::error($routeName, 'Returns an invalid response'); |
502 | 498 | continue; |
503 | 499 | } |
|
521 | 517 | $docStatusCodes = array_map(fn (ControllerMethodResponse $response): int => $response->statusCode, array_filter($classMethodInfo->responses, fn (?ControllerMethodResponse $response): bool => $response != null)); |
522 | 518 | $missingDocStatusCodes = array_unique(array_filter(array_diff($codeStatusCodes, $docStatusCodes), fn (int $code): bool => $code < 500)); |
523 | 519 |
|
524 | | - if (count($missingDocStatusCodes) > 0) { |
| 520 | + if ($missingDocStatusCodes !== []) { |
525 | 521 | Logger::error($routeName, 'Returns undocumented status codes: ' . implode(', ', $missingDocStatusCodes)); |
526 | 522 | continue; |
527 | 523 | } |
|
587 | 583 |
|
588 | 584 | foreach ($urlParameters as $urlParameter) { |
589 | 585 | $matchingParameters = array_filter($route->controllerMethod->parameters, fn (ControllerMethodParameter $param): bool => $param->name == $urlParameter); |
590 | | - $requirement = array_key_exists($urlParameter, $route->requirements) ? $route->requirements[$urlParameter] : null; |
| 586 | + $requirement = $route->requirements[$urlParameter] ?? null; |
591 | 587 | if (count($matchingParameters) == 1) { |
592 | 588 | $parameter = $matchingParameters[array_keys($matchingParameters)[0]]; |
593 | 589 | if ($parameter?->methodParameter == null && ($route->requirements == null || !array_key_exists($urlParameter, $route->requirements))) { |
|
609 | 605 | $requirement = '^' . $requirement; |
610 | 606 | } |
611 | 607 | if (!str_ends_with((string)$requirement, '$')) { |
612 | | - $requirement = $requirement . '$'; |
| 608 | + $requirement .= '$'; |
613 | 609 | } |
614 | 610 | } |
615 | 611 |
|
|
671 | 667 |
|
672 | 668 | $mergedResponses = []; |
673 | 669 | foreach (array_unique(array_map(fn (ControllerMethodResponse $response): int => $response->statusCode, array_filter($route->controllerMethod->responses, fn (?ControllerMethodResponse $response): bool => $response != null))) as $statusCode) { |
674 | | - if ($firstStatusCode && count($mergedResponses) > 0) { |
| 670 | + if ($firstStatusCode && $mergedResponses !== []) { |
675 | 671 | break; |
676 | 672 | } |
677 | 673 |
|
|
685 | 681 |
|
686 | 682 | $mergedContentTypeResponses = []; |
687 | 683 | foreach (array_unique(array_map(fn (ControllerMethodResponse $response): ?string => $response->contentType, array_filter($statusCodeResponses, fn (ControllerMethodResponse $response): bool => $response->contentType != null))) as $contentType) { |
688 | | - if ($firstContentType && count($mergedContentTypeResponses) > 0) { |
| 684 | + if ($firstContentType && $mergedContentTypeResponses !== []) { |
689 | 685 | break; |
690 | 686 | } |
691 | 687 |
|
692 | 688 | /** @var ControllerMethodResponse[] $contentTypeResponses */ |
693 | 689 | $contentTypeResponses = array_values(array_filter($statusCodeResponses, fn (ControllerMethodResponse $response): bool => $response->contentType == $contentType)); |
694 | 690 |
|
695 | | - $hasEmpty = count(array_filter($contentTypeResponses, fn (ControllerMethodResponse $response): bool => $response->type == null)) > 0; |
| 691 | + $hasEmpty = array_filter($contentTypeResponses, fn (ControllerMethodResponse $response): bool => $response->type == null) !== []; |
696 | 692 | $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))); |
697 | 693 | if (count($uniqueResponses) == 1) { |
698 | 694 | if ($hasEmpty) { |
|
716 | 712 | $response = [ |
717 | 713 | 'description' => array_key_exists($statusCode, $route->controllerMethod->responseDescription) ? $route->controllerMethod->responseDescription[$statusCode] : '', |
718 | 714 | ]; |
719 | | - if (count($headers) > 0) { |
| 715 | + if ($headers !== []) { |
720 | 716 | $response['headers'] = array_combine( |
721 | 717 | array_keys($headers), |
722 | 718 | array_map( |
|
727 | 723 | ), |
728 | 724 | ); |
729 | 725 | } |
730 | | - if (count($mergedContentTypeResponses) > 0) { |
| 726 | + if ($mergedContentTypeResponses !== []) { |
731 | 727 | $response['content'] = $mergedContentTypeResponses; |
732 | 728 | } |
733 | 729 | $mergedResponses[$statusCode] = $response; |
|
751 | 747 | if ($route->controllerMethod->summary !== null) { |
752 | 748 | $operation['summary'] = $route->controllerMethod->summary; |
753 | 749 | } |
754 | | - if (count($route->controllerMethod->description) > 0) { |
| 750 | + if ($route->controllerMethod->description !== []) { |
755 | 751 | $operation['description'] = implode("\n", $route->controllerMethod->description); |
756 | 752 | } |
757 | 753 | if ($route->controllerMethod->isDeprecated) { |
|
762 | 758 | } |
763 | 759 | $operation['security'] = $security; |
764 | 760 |
|
765 | | - if (count($bodyParameters) > 0) { |
| 761 | + if ($bodyParameters !== []) { |
766 | 762 | $requiredBodyParameters = []; |
767 | 763 |
|
768 | 764 | foreach ($bodyParameters as $bodyParameter) { |
|
772 | 768 | } |
773 | 769 | } |
774 | 770 |
|
775 | | - $required = count($requiredBodyParameters) > 0; |
| 771 | + $required = $requiredBodyParameters !== []; |
776 | 772 |
|
777 | 773 | $schema = [ |
778 | 774 | 'type' => 'object', |
|
823 | 819 | ], |
824 | 820 | ]; |
825 | 821 | } |
826 | | - if (count($parameters) > 0) { |
| 822 | + if ($parameters !== []) { |
827 | 823 | $operation['parameters'] = $parameters; |
828 | 824 | } |
829 | 825 |
|
|
919 | 915 |
|
920 | 916 | if (!$hasSingleScope) { |
921 | 917 | $scopePaths['full'] = []; |
922 | | -} elseif (count($scopePaths) === 0) { |
| 918 | +} elseif ($scopePaths === []) { |
923 | 919 | if (isset($schemas['Capabilities']) || isset($schemas['PublicCapabilities'])) { |
924 | 920 | Logger::debug('app', 'Generating default scope without routes to populate capabilities'); |
925 | 921 | $scopePaths['default'] = []; |
|
988 | 984 | $scopedSchemas['PublicCapabilities'] = $schemas['PublicCapabilities']; |
989 | 985 | } |
990 | 986 |
|
991 | | - if (count($scopedSchemas) === 0) { |
| 987 | + if ($scopedSchemas === []) { |
992 | 988 | $scopedSchemas = new stdClass(); |
993 | 989 | } else { |
994 | 990 | ksort($scopedSchemas); |
|
0 commit comments