Skip to content

Commit

Permalink
fixed scopes getType returning null (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
romalytvynenko authored Aug 6, 2023
1 parent f6422be commit b3bcbc3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 42 deletions.
6 changes: 3 additions & 3 deletions src/Infer/Scope/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(
) {
}

public function getType(Node $node)
public function getType(Node $node): Type
{
if ($node instanceof Node\Scalar) {
return (new ScalarTypeGetter)($node);
Expand Down Expand Up @@ -113,7 +113,7 @@ public function getType(Node $node)
if ($node instanceof Node\Expr\PropertyFetch) {
// Only string prop names support.
if (! $name = ($node->name->name ?? null)) {
return null;
return new UnknownType('Cannot infer type of property fetch: not supported yet.');
}

$calleeType = $this->getType($node->var);
Expand All @@ -122,7 +122,7 @@ public function getType(Node $node)
// if ($calleeType->is instanceof ObjectType) {
// $calleeType = $calleeType->is;
// }
return $this->setType($node, new UnknownType("Cannot infer type of property [{$name}] call on template type: not supported yet."));
return $this->setType($node, new UnknownType("Cannot infer type of property [{$name}] fetch on template type: not supported yet."));
}

return $this->setType(
Expand Down
26 changes: 0 additions & 26 deletions tests/Generator/ResponseExtensionTest.php

This file was deleted.

13 changes: 0 additions & 13 deletions tests/Infer/InferTest.php

This file was deleted.

13 changes: 13 additions & 0 deletions tests/Infer/Scope/ScopeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

function getStatementTypeForScopeTest(string $statement, array $extensions = [])
{
return analyzeFile('<?php', $extensions)->getExpressionType($statement);
}

it('infers property fetch nodes types', function ($code, $expectedTypeString) {
expect(getStatementTypeForScopeTest($code)->toString())->toBe($expectedTypeString);
})->with([
['$foo->bar', 'unknown'],
['$foo->bar->{"baz"}', 'unknown'],
]);

0 comments on commit b3bcbc3

Please sign in to comment.