diff --git a/src/Annotations/Components.php b/src/Annotations/Components.php index e09a3d497..d6841add7 100644 --- a/src/Annotations/Components.php +++ b/src/Annotations/Components.php @@ -128,12 +128,10 @@ public static function ref($component, bool $encode = true): string if ($component instanceof AbstractAnnotation) { foreach (Components::$_nested as $type => $nested) { // exclude attachables - if (2 == count($nested)) { - if ($component instanceof $type) { - $type = $nested[0]; - $name = $component->{$nested[1]}; - break; - } + if ((2 == count($nested)) && $component instanceof $type) { + $type = $nested[0]; + $name = $component->{$nested[1]}; + break; } } } else { diff --git a/src/Loggers/ConsoleLogger.php b/src/Loggers/ConsoleLogger.php index 3bcd5c6e4..67c325ed0 100644 --- a/src/Loggers/ConsoleLogger.php +++ b/src/Loggers/ConsoleLogger.php @@ -80,18 +80,20 @@ public function log($level, $message, array $context = []): void $logLine = sprintf('%s%s%s%s', $color, $prefix, $message, $stop); error_log($logLine); - if ($this->debug) { - if ($exception) { - error_log($exception->getTraceAsString()); - } elseif (!empty($logLine)) { - $stack = explode(PHP_EOL, (new \Exception())->getTraceAsString()); - // self - array_shift($stack); - // AbstractLogger - array_shift($stack); - foreach ($stack as $line) { - error_log($line); - } + if (!$this->debug) { + return; + } + + if ($exception) { + error_log($exception->getTraceAsString()); + } elseif (!empty($logLine)) { + $stack = explode(PHP_EOL, (new \Exception())->getTraceAsString()); + // self + array_shift($stack); + // AbstractLogger + array_shift($stack); + foreach ($stack as $line) { + error_log($line); } } } diff --git a/src/Loggers/DefaultLogger.php b/src/Loggers/DefaultLogger.php index d4118f0d1..59c82a150 100644 --- a/src/Loggers/DefaultLogger.php +++ b/src/Loggers/DefaultLogger.php @@ -22,11 +22,7 @@ public function log($level, $message, array $context = []): void $message = $message->getMessage(); } - if (in_array($level, [LogLevel::NOTICE, LogLevel::INFO])) { - $error_level = E_USER_NOTICE; - } else { - $error_level = E_USER_WARNING; - } + $error_level = in_array($level, [LogLevel::NOTICE, LogLevel::INFO]) ? E_USER_NOTICE : E_USER_WARNING; trigger_error($message, $error_level); } diff --git a/src/Processors/AugmentParameters.php b/src/Processors/AugmentParameters.php index fc4f510c9..a522ca8ae 100644 --- a/src/Processors/AugmentParameters.php +++ b/src/Processors/AugmentParameters.php @@ -82,10 +82,8 @@ protected function augmentOperationParameters(Analysis $analysis): void if (array_key_exists('param', $tags)) { foreach ($tags['param'] as $name => $details) { foreach ($operation->parameters as $parameter) { - if ($parameter->name == $name) { - if (Generator::isDefault($parameter->description) && $details['description']) { - $parameter->description = $details['description']; - } + if (($parameter->name == $name) && Generator::isDefault($parameter->description) && $details['description']) { + $parameter->description = $details['description']; } } } diff --git a/src/Processors/AugmentSchemas.php b/src/Processors/AugmentSchemas.php index a07b2aa30..9b501320f 100644 --- a/src/Processors/AugmentSchemas.php +++ b/src/Processors/AugmentSchemas.php @@ -102,13 +102,11 @@ protected function augmentType(Analysis $analysis, array $schemas): void } elseif (is_array($schema->propertyNames) && count($schema->propertyNames) > 0) { $schema->type = 'object'; } - } else { - if (is_string($schema->type) && $typeSchema = $analysis->getSchemaForSource($schema->type)) { - if (Generator::isDefault($schema->format)) { - $schema->ref = OA\Components::ref($typeSchema); - $schema->type = Generator::UNDEFINED; - } - } + } else if (is_string($schema->type) && + $typeSchema = ($analysis->getSchemaForSource($schema->type) && Generator::isDefault($schema->format))) { + + $schema->ref = OA\Components::ref($typeSchema); + $schema->type = Generator::UNDEFINED; } } } diff --git a/src/Processors/CleanUnusedComponents.php b/src/Processors/CleanUnusedComponents.php index 4a7303c32..e107893b1 100644 --- a/src/Processors/CleanUnusedComponents.php +++ b/src/Processors/CleanUnusedComponents.php @@ -48,13 +48,11 @@ protected function cleanup(Analysis $analysis): bool } } - if ($annotation instanceof OA\OpenApi || $annotation instanceof OA\Operation) { - if (!Generator::isDefault($annotation->security)) { - foreach ($annotation->security as $security) { - foreach (array_keys($security) as $securityName) { - $ref = OA\Components::COMPONENTS_PREFIX . 'securitySchemes/' . $securityName; - $usedRefs[$ref] = $ref; - } + if (($annotation instanceof OA\OpenApi || $annotation instanceof OA\Operation) && !Generator::isDefault($annotation->security)) { + foreach ($annotation->security as $security) { + foreach (array_keys($security) as $securityName) { + $ref = OA\Components::COMPONENTS_PREFIX . 'securitySchemes/' . $securityName; + $usedRefs[$ref] = $ref; } } }