Skip to content
Open
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
5 changes: 4 additions & 1 deletion src/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand Down
4 changes: 4 additions & 0 deletions src/Factories/ObjectDescriptionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions tests/ObjectDescriptionFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

use Pest\Arch\Factories\ObjectDescriptionFactory;

it('does not keep the syntax tree of a described object', function () {
$object = ObjectDescriptionFactory::make(__DIR__.'/Fixtures/Misc/HasNativeFunctions.php');

expect($object->name)->toBe('Tests\Fixtures\Misc\HasNativeFunctions')
->and($object->uses)->not->toBeEmpty()
->and($object->stmts)->toBe([]);
});
Loading