Skip to content

Commit a1ade3d

Browse files
authored
Fix jsonSerialize using $this where it shouldn't (zircote#1745)
1 parent e026794 commit a1ade3d

File tree

2 files changed

+5
-24
lines changed

2 files changed

+5
-24
lines changed

phpstan-baseline.neon

-12
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,6 @@ parameters:
2424
count: 1
2525
path: src/Analysers/ReflectionAnalyser.php
2626

27-
-
28-
message: '#^Access to an undefined property OpenApi\\Annotations\\AbstractAnnotation\:\:\$description\.$#'
29-
identifier: property.notFound
30-
count: 1
31-
path: src/Annotations/AbstractAnnotation.php
32-
33-
-
34-
message: '#^Access to an undefined property OpenApi\\Annotations\\AbstractAnnotation\:\:\$summary\.$#'
35-
identifier: property.notFound
36-
count: 1
37-
path: src/Annotations/AbstractAnnotation.php
38-
3927
-
4028
message: '#^Call to function property_exists\(\) with OpenApi\\Annotations\\AbstractAnnotation and ''_context'' will always evaluate to true\.$#'
4129
identifier: function.alreadyNarrowedType

src/Annotations/AbstractAnnotation.php

+5-12
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,8 @@ public function jsonSerialize()
354354
$ref = ['$ref' => $data->ref];
355355
if ($this->_context->isVersion(OpenApi::VERSION_3_1_0)) {
356356
foreach (['summary', 'description'] as $prop) {
357-
if (property_exists($this, $prop)) {
358-
if (!Generator::isDefault($this->{$prop})) {
359-
$ref[$prop] = $data->{$prop};
360-
}
357+
if (property_exists($data, $prop)) {
358+
$ref[$prop] = $data->{$prop};
361359
}
362360
}
363361
}
@@ -368,16 +366,11 @@ public function jsonSerialize()
368366
} else {
369367
$ref['nullable'] = $data->nullable;
370368
}
371-
unset($data->nullable);
369+
unset($data->ref, $data->nullable);
372370

373371
// preserve other properties
374-
foreach (get_object_vars($this) as $property => $value) {
375-
if ('_' === $property[0] || in_array($property, ['ref', 'nullable'])) {
376-
continue;
377-
}
378-
if (!Generator::isDefault($value)) {
379-
$ref[$property] = $value;
380-
}
372+
foreach (get_object_vars($data) as $property => $value) {
373+
$ref[$property] = $value;
381374
}
382375
}
383376
$data = (object) $ref;

0 commit comments

Comments
 (0)