Skip to content

Commit b9df0ca

Browse files
committed
TASK: Make $parentScope in ModuleScope constructor mandatory
1 parent 55f5dc3 commit b9df0ca

2 files changed

Lines changed: 5 additions & 10 deletions

File tree

src/TypeSystem/Scope/ModuleScope/ModuleScope.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ final class ModuleScope implements ScopeInterface
3333
public function __construct(
3434
private readonly LoaderInterface $loader,
3535
private readonly ModuleNode $moduleNode,
36-
private readonly ?ScopeInterface $parentScope
36+
private readonly ScopeInterface $parentScope
3737
) {
3838
}
3939

4040
public function lookupTypeFor(string $name): ?TypeInterface
4141
{
42-
return $this->parentScope?->lookupTypeFor($name) ?? null;
42+
return $this->parentScope->lookupTypeFor($name);
4343
}
4444

4545
public function resolveTypeReference(TypeReferenceNode $typeReferenceNode): TypeInterface
@@ -48,10 +48,6 @@ public function resolveTypeReference(TypeReferenceNode $typeReferenceNode): Type
4848
return $this->loader->resolveTypeOfImport($importNode);
4949
}
5050

51-
if ($this->parentScope) {
52-
return $this->parentScope->resolveTypeReference($typeReferenceNode);
53-
}
54-
55-
throw new \Exception('@TODO: Unknown Type ' . $typeReferenceNode->name);
51+
return $this->parentScope->resolveTypeReference($typeReferenceNode);
5652
}
5753
}

test/Unit/TypeSystem/Scope/ModuleScope/ModuleScopeTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use PackageFactory\ComponentEngine\Test\Unit\Module\Loader\Fixtures\DummyLoader;
2828
use PackageFactory\ComponentEngine\Test\Unit\TypeSystem\Scope\Fixtures\DummyScope;
2929
use PackageFactory\ComponentEngine\TypeSystem\Scope\ModuleScope\ModuleScope;
30-
use PackageFactory\ComponentEngine\TypeSystem\Scope\GlobalScope\GlobalScope;
3130
use PackageFactory\ComponentEngine\TypeSystem\TypeInterface;
3231
use PHPUnit\Framework\TestCase;
3332

@@ -55,7 +54,7 @@ public function resolvesTypeReferencesForModuleImports(): void
5554
],
5655
]),
5756
moduleNode: $moduleNode,
58-
parentScope: null
57+
parentScope: new DummyScope()
5958
);
6059

6160
$this->assertSame(
@@ -100,4 +99,4 @@ public function fallsBackToParentScopeWhenProvidingTypesForValues(): void
10099
$moduleScope->lookupTypeFor('foo')
101100
);
102101
}
103-
}
102+
}

0 commit comments

Comments
 (0)