Skip to content

Commit 63adcd0

Browse files
authored
Methods SplObjectStorage::attach(), detach & contains() are deprecated since PHP 8.5. Use offsetSet(), offsetUnset & offsetExists() instead. (#1865)
1 parent f0d65a6 commit 63adcd0

File tree

7 files changed

+15
-15
lines changed

7 files changed

+15
-15
lines changed

src/Analysis.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct(array $annotations = [], ?Context $context = null)
5555

5656
public function addAnnotation(object $annotation, Context $context): void
5757
{
58-
if ($this->annotations->contains($annotation)) {
58+
if ($this->annotations->offsetExists($annotation)) {
5959
return;
6060
}
6161

@@ -72,7 +72,7 @@ public function addAnnotation(object $annotation, Context $context): void
7272
$context->annotations[] = $annotation;
7373
}
7474
}
75-
$this->annotations->attach($annotation, $context);
75+
$this->annotations->offsetSet($annotation, $context);
7676
$blacklist = property_exists($annotation, '_blacklist') ? $annotation::$_blacklist : [];
7777
foreach ($annotation as $property => $value) {
7878
if (in_array($property, $blacklist)) {
@@ -297,8 +297,8 @@ public function getAnnotationsOfType($classes, bool $strict = false): array
297297
foreach ((array) $classes as $class) {
298298
/** @var OA\AbstractAnnotation $annotation */
299299
foreach ($this->annotations as $annotation) {
300-
if ($annotation instanceof $class && (!$strict || ($annotation->isRoot($class) && !$unique->contains($annotation)))) {
301-
$unique->attach($annotation);
300+
if ($annotation instanceof $class && (!$strict || ($annotation->isRoot($class) && !$unique->offsetExists($annotation)))) {
301+
$unique->offsetSet($annotation);
302302
$annotations[] = $annotation;
303303
}
304304
}
@@ -340,7 +340,7 @@ public function getContext(object $annotation): ?Context
340340
if ($annotation instanceof OA\AbstractAnnotation) {
341341
return $annotation->_context;
342342
}
343-
if ($this->annotations->contains($annotation) === false) {
343+
if ($this->annotations->offsetExists($annotation) === false) {
344344
throw new OpenApiException('Annotation not found');
345345
}
346346
$context = $this->annotations[$annotation];
@@ -387,8 +387,8 @@ public function split(): \stdClass
387387
$result->merged = $this->merged();
388388
$result->unmerged = new Analysis([], $this->context);
389389
foreach ($this->annotations as $annotation) {
390-
if ($result->merged->annotations->contains($annotation) === false) {
391-
$result->unmerged->annotations->attach($annotation, $this->annotations[$annotation]);
390+
if ($result->merged->annotations->offsetExists($annotation) === false) {
391+
$result->unmerged->annotations->offsetSet($annotation, $this->annotations[$annotation]);
392392
}
393393
}
394394

src/Processors/AugmentRefs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ protected function removeDuplicateRefs(Analysis $analysis): void
8888
if (!Generator::isDefault($allOfSchema->ref)) {
8989
if (in_array($allOfSchema->ref, $refs)) {
9090
$dupes[] = $allOfSchema->ref;
91-
$analysis->annotations->detach($allOfSchema);
91+
$analysis->annotations->offsetUnset($allOfSchema);
9292
unset($schema->allOf[$ii]);
9393
continue;
9494
}

src/Processors/AugmentTags.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private function removeUnusedTags(array $usedTagNames, array $declaredTags, Anal
9797
foreach ($declaredTags as $tag) {
9898
if (!in_array($tag->name, $tagsToKeep)) {
9999
if (false !== $index = array_search($tag, $analysis->openapi->tags, true)) {
100-
$analysis->annotations->detach($tag);
100+
$analysis->annotations->offsetUnset($tag);
101101
unset($analysis->openapi->tags[$index]);
102102
$analysis->openapi->tags = array_values($analysis->openapi->tags);
103103
}

src/Processors/BuildPaths.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __invoke(Analysis $analysis): void
2626
$annotation->_context->logger->warning($annotation->identity() . ' is missing required property "path" in ' . $annotation->_context);
2727
} elseif (isset($paths[$annotation->path])) {
2828
$paths[$annotation->path]->mergeProperties($annotation);
29-
$analysis->annotations->detach($annotation);
29+
$analysis->annotations->offsetUnset($annotation);
3030
} else {
3131
$paths[$annotation->path] = $annotation;
3232
}

src/Processors/CleanUnmerged.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __invoke(Analysis $analysis): void
2121
foreach ($analysis->annotations as $annotation) {
2222
if (property_exists($annotation, '_unmerged')) {
2323
foreach ($annotation->_unmerged as $ii => $item) {
24-
if ($merged->contains($item)) {
24+
if ($merged->offsetExists($item)) {
2525
unset($annotation->_unmerged[$ii]); // Property was merged
2626
}
2727
}

src/Processors/Concerns/AnnotationTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public function collectAnnotations($root): \SplObjectStorage
2020
$storage = new \SplObjectStorage();
2121

2222
$this->traverseAnnotations($root, static function ($item) use (&$storage): void {
23-
if ($item instanceof OA\AbstractAnnotation && !$storage->contains($item)) {
24-
$storage->attach($item);
23+
if ($item instanceof OA\AbstractAnnotation && !$storage->offsetExists($item)) {
24+
$storage->offsetSet($item);
2525
}
2626
});
2727

@@ -37,7 +37,7 @@ public function removeAnnotation(iterable $root, OA\AbstractAnnotation $annotati
3737
$this->traverseAnnotations($root, static function ($item) use ($remove): void {
3838
if ($item instanceof \SplObjectStorage) {
3939
foreach ($remove as $annotation) {
40-
$item->detach($annotation);
40+
$item->offsetUnset($annotation);
4141
}
4242
}
4343
}, $recurse);

src/Processors/MergeIntoOpenApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function __invoke(Analysis $analysis): void
9898
}
9999
}
100100

101-
$analysis->annotations->detach($components);
101+
$analysis->annotations->offsetUnset($components);
102102
}
103103

104104
$merge = array_filter($merge, static fn (OA\AbstractAnnotation $annotation): bool => !$annotation instanceof OA\Components);

0 commit comments

Comments
 (0)