diff --git a/src/Blueprint.php b/src/Blueprint.php index 5f2db2b..2d334e9 100644 --- a/src/Blueprint.php +++ b/src/Blueprint.php @@ -261,8 +261,11 @@ private function getUsagePathAndLines(Layer $layer, string $objectName, string $ return null; } + // Object descriptions don't keep their syntax tree, so the file is parsed again to locate the violation... + $stmts = ServiceContainer::$parser->parse((string) file_get_contents($dependOnObject->path)) ?? []; + $nodes = ServiceContainer::$nodeFinder->findInstanceOf( - $dependOnObject->stmts, + ServiceContainer::$nodeTraverser->traverse($stmts), $class, ); diff --git a/src/Factories/ObjectDescriptionFactory.php b/src/Factories/ObjectDescriptionFactory.php index bdb901e..4bdd427 100644 --- a/src/Factories/ObjectDescriptionFactory.php +++ b/src/Factories/ObjectDescriptionFactory.php @@ -54,6 +54,10 @@ public static function make(string $filename, bool $onlyUserDefinedUses = true): static fn (string $use): bool => (! $onlyUserDefinedUses || self::isUserDefined($use)) && ! self::isSameLayer($object, $use), ) )); + + // The syntax tree is no longer needed once the object is described, and keeping it for every + // parsed file would hold most of the memory of an arch run... + $object->stmts = []; } return $object; diff --git a/tests/ObjectDescriptionFactory.php b/tests/ObjectDescriptionFactory.php new file mode 100644 index 0000000..0c19987 --- /dev/null +++ b/tests/ObjectDescriptionFactory.php @@ -0,0 +1,11 @@ +name)->toBe('Tests\Fixtures\Misc\HasNativeFunctions') + ->and($object->uses)->not->toBeEmpty() + ->and($object->stmts)->toBe([]); +});