Skip to content

Commit ad508c5

Browse files
committed
refactor: Use strict boolean comparisons
Signed-off-by: provokateurin <[email protected]>
1 parent c3a7986 commit ad508c5

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

generate-spec.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,8 @@
465465
Logger::panic($routeName, 'Route is marked as ignore but also has other scopes');
466466
}
467467

468-
if (empty($scopes)) {
469-
if (!empty($controllerScopes)) {
468+
if ($scopes === []) {
469+
if ($controllerScopes !== []) {
470470
$scopes = $controllerScopes;
471471
} elseif ($isExApp) {
472472
$scopes = ['ex_app'];
@@ -949,11 +949,11 @@
949949
foreach ($paths as $url => $urlRoutes) {
950950
foreach ($urlRoutes as $httpMethod => $routeData) {
951951
foreach ($routeData['responses'] as $statusCode => $responseData) {
952-
if (!empty($responseData['content'])) {
952+
if (isset($responseData['content']) && $responseData['content'] !== []) {
953953
$usedSchemas[] = Helpers::collectUsedRefs($responseData['content']);
954954
}
955955
}
956-
if (!empty($routeData['requestBody']['content'])) {
956+
if (isset($routeData['requestBody']['content']) && $routeData['requestBody']['content'] !== []) {
957957
$usedSchemas[] = Helpers::collectUsedRefs($routeData['requestBody']['content']);
958958
}
959959
}

rector.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
->withPhpSets()
1111
->withPreparedSets(
1212
typeDeclarations: true,
13+
strictBooleans: true,
1314
);

src/Helpers.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,16 @@ public static function getOpenAPIAttributeTagsByScope(ClassMethod|Class_|Node $n
252252
if ($item?->value instanceof String_) {
253253
$tag = $item->value->value;
254254
$pattern = '/^[0-9a-zA-Z_-]+$/';
255-
if (!preg_match($pattern, $tag)) {
255+
if (in_array(preg_match($pattern, $tag), [0, false], true)) {
256256
Logger::error($routeName, 'Tag "' . $tag . '" has to match pattern "' . $pattern . '"');
257257
}
258258
$foundTags[] = $tag;
259259
}
260260
}
261261
}
262262

263-
if (!empty($foundTags)) {
264-
$tags[$foundScopeName ?: $defaultScope] = $foundTags;
263+
if ($foundTags !== []) {
264+
$tags[$foundScopeName !== null && $foundScopeName !== '' && $foundScopeName !== '0' ? $foundScopeName : $defaultScope] = $foundTags;
265265
}
266266
}
267267
}

src/OpenApiType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ enum: $values,
347347
return $item->type;
348348
}, $items);
349349

350-
if (!empty(array_filter($itemTypes, static fn (?string $type): bool => $type === null)) || count($itemTypes) !== count(array_unique($itemTypes))) {
350+
if (array_filter($itemTypes, static fn (?string $type): bool => $type === null) !== [] || count($itemTypes) !== count(array_unique($itemTypes))) {
351351
return new OpenApiType(
352352
context: $context,
353353
nullable: $nullable,

src/ResponseType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public static function resolve(string $context, TypeNode $obj): array {
267267
if ($statusCode === 204 || $statusCode === 304) {
268268
if ($statusCode === 304) {
269269
$customHeaders = array_filter(array_keys($headers), static fn (string $header): bool => str_starts_with(strtolower($header), 'x-'));
270-
if (!empty($customHeaders)) {
270+
if ($customHeaders !== []) {
271271
Logger::error($context, 'Custom headers are not allowed for responses with status code 304. Found: ' . implode(', ', $customHeaders));
272272
}
273273
}

0 commit comments

Comments
 (0)