Skip to content
Merged
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
14 changes: 7 additions & 7 deletions src/Analysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct(array $annotations = [], ?Context $context = null)

public function addAnnotation(object $annotation, Context $context): void
{
if ($this->annotations->contains($annotation)) {
if ($this->annotations->offsetExists($annotation)) {
return;
}

Expand All @@ -72,7 +72,7 @@ public function addAnnotation(object $annotation, Context $context): void
$context->annotations[] = $annotation;
}
}
$this->annotations->attach($annotation, $context);
$this->annotations->offsetSet($annotation, $context);
$blacklist = property_exists($annotation, '_blacklist') ? $annotation::$_blacklist : [];
foreach ($annotation as $property => $value) {
if (in_array($property, $blacklist)) {
Expand Down Expand Up @@ -297,8 +297,8 @@ public function getAnnotationsOfType($classes, bool $strict = false): array
foreach ((array) $classes as $class) {
/** @var OA\AbstractAnnotation $annotation */
foreach ($this->annotations as $annotation) {
if ($annotation instanceof $class && (!$strict || ($annotation->isRoot($class) && !$unique->contains($annotation)))) {
$unique->attach($annotation);
if ($annotation instanceof $class && (!$strict || ($annotation->isRoot($class) && !$unique->offsetExists($annotation)))) {
$unique->offsetSet($annotation);
$annotations[] = $annotation;
}
}
Expand Down Expand Up @@ -349,7 +349,7 @@ public function getContext(object $annotation): ?Context
if ($annotation instanceof OA\AbstractAnnotation) {
return $annotation->_context;
}
if ($this->annotations->contains($annotation) === false) {
if ($this->annotations->offsetExists($annotation) === false) {
throw new OpenApiException('Annotation not found');
}
$context = $this->annotations[$annotation];
Expand Down Expand Up @@ -396,8 +396,8 @@ public function split(): \stdClass
$result->merged = $this->merged();
$result->unmerged = new Analysis([], $this->context);
foreach ($this->annotations as $annotation) {
if ($result->merged->annotations->contains($annotation) === false) {
$result->unmerged->annotations->attach($annotation, $this->annotations[$annotation]);
if ($result->merged->annotations->offsetExists($annotation) === false) {
$result->unmerged->annotations->offsetSet($annotation, $this->annotations[$annotation]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Processors/AugmentRefs.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected function removeDuplicateRefs(Analysis $analysis): void
if (!Generator::isDefault($allOfSchema->ref)) {
if (in_array($allOfSchema->ref, $refs)) {
$dupes[] = $allOfSchema->ref;
$analysis->annotations->detach($allOfSchema);
$analysis->annotations->offsetUnset($allOfSchema);
unset($schema->allOf[$ii]);
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Processors/AugmentTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private function removeUnusedTags(array $usedTagNames, array $declaredTags, Anal
foreach ($declaredTags as $tag) {
if (!in_array($tag->name, $tagsToKeep)) {
if (false !== $index = array_search($tag, $analysis->openapi->tags, true)) {
$analysis->annotations->detach($tag);
$analysis->annotations->offsetUnset($tag);
unset($analysis->openapi->tags[$index]);
$analysis->openapi->tags = array_values($analysis->openapi->tags);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Processors/BuildPaths.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __invoke(Analysis $analysis): void
$annotation->_context->logger->warning($annotation->identity() . ' is missing required property "path" in ' . $annotation->_context);
} elseif (isset($paths[$annotation->path])) {
$paths[$annotation->path]->mergeProperties($annotation);
$analysis->annotations->detach($annotation);
$analysis->annotations->offsetUnset($annotation);
} else {
$paths[$annotation->path] = $annotation;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Processors/CleanUnmerged.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __invoke(Analysis $analysis): void
foreach ($analysis->annotations as $annotation) {
if (property_exists($annotation, '_unmerged')) {
foreach ($annotation->_unmerged as $ii => $item) {
if ($merged->contains($item)) {
if ($merged->offsetExists($item)) {
unset($annotation->_unmerged[$ii]); // Property was merged
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Processors/Concerns/AnnotationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public function collectAnnotations($root): \SplObjectStorage
{
$storage = new \SplObjectStorage();

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

Expand All @@ -34,10 +34,10 @@ public function collectAnnotations($root): \SplObjectStorage
public function removeAnnotation(iterable $root, OA\AbstractAnnotation $annotation, bool $recurse = true): void
{
$remove = $this->collectAnnotations($annotation);
$this->traverseAnnotations($root, function ($item) use ($remove): void {
$this->traverseAnnotations($root, static function ($item) use ($remove): void {
if ($item instanceof \SplObjectStorage) {
foreach ($remove as $annotation) {
$item->detach($annotation);
$item->offsetUnset($annotation);
}
}
}, $recurse);
Expand Down
2 changes: 1 addition & 1 deletion src/Processors/MergeIntoOpenApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function __invoke(Analysis $analysis): void
}
}

$analysis->annotations->detach($components);
$analysis->annotations->offsetUnset($components);
}

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