From d6ee90c0a705afd5e03573d597a7cc06caa734c2 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 16 Sep 2024 18:08:42 +0200 Subject: [PATCH] Reduce memory consumption of collectors --- src/Collector/ImplementedInterfaceCollector.php | 6 +++++- src/Collector/InterfaceOfAbstractClassCollector.php | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Collector/ImplementedInterfaceCollector.php b/src/Collector/ImplementedInterfaceCollector.php index 21bfe0f0..727361c2 100644 --- a/src/Collector/ImplementedInterfaceCollector.php +++ b/src/Collector/ImplementedInterfaceCollector.php @@ -18,7 +18,7 @@ public function getNodeType(): string /** * @param Class_ $node - * @return string[]|null + * @return non-empty-array|null */ public function processNode(Node $node, Scope $scope): ?array { @@ -33,6 +33,10 @@ public function processNode(Node $node, Scope $scope): ?array $implementedInterfaceNames[] = $implement->toString(); } + if ($implementedInterfaceNames === []) { + return null; + } + return $implementedInterfaceNames; } } diff --git a/src/Collector/InterfaceOfAbstractClassCollector.php b/src/Collector/InterfaceOfAbstractClassCollector.php index 7601fc82..17c1fa76 100644 --- a/src/Collector/InterfaceOfAbstractClassCollector.php +++ b/src/Collector/InterfaceOfAbstractClassCollector.php @@ -18,7 +18,7 @@ public function getNodeType(): string /** * @param Class_ $node - * @return string[]|null + * @return non-empty-array|null */ public function processNode(Node $node, Scope $scope): ?array { @@ -32,6 +32,10 @@ public function processNode(Node $node, Scope $scope): ?array $interfaceNames[] = $implement->toString(); } + if ($interfaceNames === []) { + return null; + } + return $interfaceNames; } }