Add unknown type when we can't figure it out

parent 1795ed43
......@@ -17,9 +17,11 @@ declare(strict_types=1);
namespace Hgraca\AppMapper\Infrastructure\Parser\NikicPhpParser\Visitor\Strategy;
use Hgraca\AppMapper\Core\Port\Logger\StaticLoggerFacade;
use Hgraca\AppMapper\Infrastructure\Parser\NikicPhpParser\Exception\UnknownVariableException;
use Hgraca\AppMapper\Infrastructure\Parser\NikicPhpParser\NodeTypeManagerTrait;
use Hgraca\AppMapper\Infrastructure\Parser\NikicPhpParser\Visitor\ResolverCollection;
use Hgraca\AppMapper\Infrastructure\Parser\NikicPhpParser\Visitor\Type;
use Hgraca\AppMapper\Infrastructure\Parser\NikicPhpParser\Visitor\TypeCollection;
use Hgraca\AppMapper\Infrastructure\Parser\NikicPhpParser\Visitor\TypeResolverCollector;
use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
......@@ -70,12 +72,11 @@ final class PropertyFetchNodeStrategy extends AbstractStrategy
$this->propertyCollector->getCollectedResolverCollection($this->getPropertyName($propertyFetch))
);
} catch (UnknownVariableException $e) {
StaticLoggerFacade::warning(
"Silently ignoring a UnknownVariableException.\n"
. "The property is not in the collector, so we can't add it to the PropertyFetch.\n"
. $e->getMessage(),
[__METHOD__]
);
$resolver = function () use ($propertyFetch) {
return new TypeCollection(Type::constructUnknownFromNode($propertyFetch));
};
self::addTypeResolverCollection($propertyFetch, new ResolverCollection($resolver));
$this->propertyCollector->collectResolver($this->getPropertyName($propertyFetch), $resolver);
}
}
}
......@@ -19,7 +19,7 @@ namespace Hgraca\AppMapper\Test\StubProjectSrc\Core\Component\X\Domain;
use DateTime;
final class AaaEntity
final class AaaEntity extends AaaEntityParent
{
use AaaTrait;
......@@ -68,4 +68,9 @@ final class AaaEntity
return BbbEntity::namedConstructor();
}
public function testUnknownProperties(): void
{
$a = $this->unknownProperty;
}
}
......@@ -19,6 +19,7 @@ namespace Hgraca\AppMapper\Test\TestCase\Infrastructure\Parser\NikicPhpParser;
use DateTime;
use Hgraca\AppMapper\Infrastructure\Parser\NikicPhpParser\NodeCollection;
use Hgraca\AppMapper\Infrastructure\Parser\NikicPhpParser\Visitor\Type;
use Hgraca\AppMapper\Test\Framework\AbstractIntegrationTest;
use Hgraca\AppMapper\Test\StubProjectSrc\Core\Component\X\Application\Service\XxxAaaService;
use Hgraca\AppMapper\Test\StubProjectSrc\Core\Component\X\Application\Service\XxxBbbService;
......@@ -630,6 +631,24 @@ final class NodeCollectionIntegrationTest extends AbstractIntegrationTest
);
}
/**
* @test
*
* @throws \ReflectionException
*/
public function unknown_property_fetch_should_have_type_unknown(): void
{
$methodNode = $this->getMethod('testUnknownProperties', AaaEntity::class);
self::assertArrayHasKey(
Type::UNKNOWN,
ReflectionHelper::getNestedProperty('stmts.0.expr.expr.attributes.TypeCollection.itemList', $methodNode)
);
self::assertArrayHasKey(
Type::UNKNOWN,
ReflectionHelper::getNestedProperty('stmts.0.expr.var.attributes.TypeCollection.itemList', $methodNode)
);
}
private function getProperty(string $propertyName, string $classFqcn): Property
{
/** @var Class_ $classNode */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment