Closed FeBe95 closed 21 hours ago
Could you try "didn't understand product"
?
BTW This seems to be a PHPStan parser bug.
Okay, I did some further testing by
clear-result-cache
analyse -v
againClearing the cache every time was necessary, since phpstan would show the cached results, even though the migration file had changed!
'didn\'t understand product'
❌'didn"t understand product'
✅"didn't understand product"
❌"didn\"t understand product"
✅For testing:
"didnt understand product"
✅'didnt understand product'
✅P.S.: I also ran phpstan analyse
without including the extension.neon
of larastan, and no error appeared (since migrations are not used by vanialla phpstan of course). That's why I posted the issue here.
@ondrejmirtes Could you help us?
The problem is obvious. ModelPropertyHelper is trying to parse 'didn\'t understand product'
as if it was a PHPDoc type, and fails, because it's not a PHPDoc type.
ModelPropertyHelper should handle such situation but doesn't.
This is not a PHPStan nor a phpdoc-parser bug.
Please open a GitHub discussion on PHPStan's side while fully describing the problem, I can't have my eyes everywhere.
@FeBe95 What if you edit Larastan's source and swap if and elseif here https://github.com/larastan/larastan/blob/91c3e56a9d08418e7bd4cb2284563cb69c0f8212/src/Properties/ModelPropertyHelper.php#L121-L135
This line doesn't make sense to me: https://github.com/larastan/larastan/blob/91c3e56a9d08418e7bd4cb2284563cb69c0f8212/src/Properties/ModelPropertyHelper.php#L134
You already have the strings in your hand, there's no reason to go through the phpdoc-parser. You can just create a union of ConstantStringType instances from them.
@szepeviktor
What if you edit Larastan's source and swap if and elseif here
Same issue, different error:
C:\xampp\htdocs\<redacted> git:[BD-6066-larastan]
vendor\bin\phpstan analyse -v
Note: Using configuration file C:\xampp\htdocs\<redacted>\phpstan.neon.
1/1 [============================] 100% 2 secs
-- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Error
-- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Internal error: Larastan\Larastan\Properties\ModelCastHelper::getReadableType(): Argument #1 ($cast) must be of type string, null given, called in C:\xampp\htdocs\<redacted>\vendor\larastan\larastan\src\Properties\ModelPropertyHelper.php on line 113 while analysing file
C:\xampp\htdocs\<redacted>\app\Http\Controllers\HubSpotController.php
Post the following stack trace to https://github.com/phpstan/phpstan/issues/new?template=Bug_report.yaml:
## C:\xampp\htdocs\<redacted>\vendor\larastan\larastan\src\Properties\ModelCastHelper.php(67)
#0 C:\xampp\htdocs\<redacted>\vendor\larastan\larastan\src\Properties\ModelPropertyHelper.php(113): Larastan\Larastan\Properties\ModelCastHelper->getReadableType(NULL, Object(PHPStan\Type\ObjectType))
#1 C:\xampp\htdocs\<redacted>\vendor\larastan\larastan\src\Properties\ModelPropertyExtension.php(30): Larastan\Larastan\Properties\ModelPropertyHelper->getDatabaseProperty(Object(PHPStan\Reflection\ClassReflection), 'cancellation_re...')
#2 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ClassReflection.php(638): Larastan\Larastan\Properties\ModelPropertyExtension->getProperty(Object(PHPStan\Reflection\ClassReflection), 'cancellation_re...')
#3 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Type/ObjectType.php(189): PHPStan\Reflection\ClassReflection->getProperty('cancellation_re...', Object(PHPStan\Analyser\MutatingScope))
#4 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Type/ObjectType.php(152): PHPStan\Type\ObjectType->getUnresolvedPropertyPrototype('cancellation_re...', Object(PHPStan\Analyser\MutatingScope))
#5 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(3827): PHPStan\Type\ObjectType->getProperty('cancellation_re...', Object(PHPStan\Analyser\MutatingScope))
#6 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(3834): PHPStan\Analyser\MutatingScope->getPropertyReflection(Object(PHPStan\Type\ObjectType), 'cancellation_re...')
#7 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1558): PHPStan\Analyser\MutatingScope->propertyFetchType(Object(PHPStan\Type\ObjectType), 'cancellation_re...', Object(PhpParser\Node\Expr\PropertyFetch))
#8 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1564): PHPStan\Analyser\MutatingScope->PHPStan\Analyser\{closure}()
#9 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(594): PHPStan\Analyser\MutatingScope->resolveType('$reason->cancel...', Object(PhpParser\Node\Expr\PropertyFetch))
#10 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(814): PHPStan\Analyser\MutatingScope->getType(Object(PhpParser\Node\Expr\PropertyFetch))
#11 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/InitializerExprTypeResolver.php(385): PHPStan\Analyser\MutatingScope->PHPStan\Analyser\{closure}(Object(PhpParser\Node\Expr\PropertyFetch))
#12 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(813): PHPStan\Reflection\InitializerExprTypeResolver->getConcatType(Object(PhpParser\Node\Expr\Variable), Object(PhpParser\Node\Expr\PropertyFetch), Object(Closure))
#13 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(594): PHPStan\Analyser\MutatingScope->resolveType('$closedReason ....', Object(PhpParser\Node\Expr\AssignOp\Concat))
#14 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1738): PHPStan\Analyser\MutatingScope->getType(Object(PhpParser\Node\Expr\AssignOp\Concat))
#15 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(694): PHPStan\Analyser\NodeScopeResolver->findEarlyTerminatingExpr(Object(PhpParser\Node\Expr\AssignOp\Concat), Object(PHPStan\Analyser\MutatingScope))
#16 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(446): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Expression), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#17 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(890): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Foreach_), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#18 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(446): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Foreach_), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#19 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(807): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\If_), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#20 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(446): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\If_), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#21 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(807): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\If_), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#22 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(446): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\If_), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#23 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(622): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\ClassMethod), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#24 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(446): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\ClassMethod), Object(PHPStan\Analyser\MutatingScope), Object(PHPStan\Node\ClassStatementsGatherer),
Object(PHPStan\Analyser\StatementContext))
#25 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(759): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Class_), Array, Object(PHPStan\Analyser\MutatingScope), Object(PHPStan\Node\ClassStatementsGatherer),
Object(PHPStan\Analyser\StatementContext))
#26 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(446): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Class_), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#27 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(729): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Namespace_), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#28 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(414): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Namespace_), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
#29 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(179): PHPStan\Analyser\NodeScopeResolver->processNodes(Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure))
#30 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(139): PHPStan\Analyser\FileAnalyser->analyseFile('C:\\xampp\\htdocs...', Array, Object(PHPStan\Rules\LazyRegistry), Object(PHPStan\Collectors\Registry), NULL)
#31 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/EventEmitterTrait.php(111): PHPStan\Command\WorkerCommand::PHPStan\Command\{closure}(Array)
#32 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/vendor/clue/ndjson-react/src/Decoder.php(117): _PHPStan_579402b64\Evenement\EventEmitter->emit('data', Array)
#33 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/EventEmitterTrait.php(111): _PHPStan_579402b64\Clue\React\NDJson\Decoder->handleData(Array)
#34 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/Util.php(62): _PHPStan_579402b64\Evenement\EventEmitter->emit('data', Array)
#35 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/EventEmitterTrait.php(111): _PHPStan_579402b64\React\Stream\Util::_PHPStan_579402b64\React\Stream\{closure}('{"action":"anal...')
#36 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/DuplexResourceStream.php(168): _PHPStan_579402b64\Evenement\EventEmitter->emit('data', Array)
#37 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(201): _PHPStan_579402b64\React\Stream\DuplexResourceStream->handleData(Resource id #6732)
#38 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(173): _PHPStan_579402b64\React\EventLoop\StreamSelectLoop->waitForStreamActivity(NULL)
#39 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(99): _PHPStan_579402b64\React\EventLoop\StreamSelectLoop->run()
#40 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259): PHPStan\Command\WorkerCommand->execute(Object(_PHPStan_579402b64\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_579402b64\Symfony\Component\Console\Output\ConsoleOutput))
#41 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(870): _PHPStan_579402b64\Symfony\Component\Console\Command\Command->run(Object(_PHPStan_579402b64\Symfony\Component\Console\Input\ArgvInput),
Object(_PHPStan_579402b64\Symfony\Component\Console\Output\ConsoleOutput))
#42 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(261): _PHPStan_579402b64\Symfony\Component\Console\Application->doRunCommand(Object(PHPStan\Command\WorkerCommand), Object(_PHPStan_579402b64\Symfony\Component\Console\Input\ArgvInput),
Object(_PHPStan_579402b64\Symfony\Component\Console\Output\ConsoleOutput))
#43 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157): _PHPStan_579402b64\Symfony\Component\Console\Application->doRun(Object(_PHPStan_579402b64\Symfony\Component\Console\Input\ArgvInput),
Object(_PHPStan_579402b64\Symfony\Component\Console\Output\ConsoleOutput))
#44 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(124): _PHPStan_579402b64\Symfony\Component\Console\Application->run()
#45 phar://C:/xampp/htdocs/<redacted>/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(125): _PHPStan_579402b64\{closure}()
#46 C:\xampp\htdocs\<redacted>\vendor\phpstan\phpstan\phpstan(8): require('phar://C:/xampp...')
#47 C:\xampp\htdocs\<redacted>\vendor\bin\phpstan(119): include('C:\\xampp\\htdocs...')
#48 {main}
-- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[ERROR] Found 1 error
⚠️ Result is incomplete because of severe errors. ⚠️
Fix these errors first and then re-run PHPStan
to get all reported errors.
Used memory: 136 MB
@ondrejmirtes, thanks for taking a look---that was the issue.
Description
When using this package for the first time, I ran into the following error:
Laravel code where the issue was found
I followed the stack trace and found the cause of this error:
If I replace
didn't
withdidnt
, the analysis finishes without any errors.I suspect that something with escaping single (and double?) quotes in strings does not work here.