Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and improvement code style #1545

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/Annotations/Components.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
26 changes: 14 additions & 12 deletions src/Loggers/ConsoleLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/Loggers/DefaultLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 2 additions & 4 deletions src/Processors/AugmentParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/Processors/AugmentSchemas.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,11 @@
} 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);

Check failure on line 108 in src/Processors/AugmentSchemas.php

View workflow job for this annotation

GitHub Actions / static-analysis

Parameter #1 $component of static method OpenApi\Annotations\Components::ref() expects OpenApi\Annotations\AbstractAnnotation|string, true given.
$schema->type = Generator::UNDEFINED;
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/Processors/CleanUnusedComponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
Loading