how do I run nette/type-fixer?

petr.pavel
Member | 535
+
0
-

Hi, can anyone help me with how to run nette/type-fixer?

I installed it locally into a sub-directory of my project with:

composer create-project nette/type-fixer

My project base dir is /var/www/app with sub-folders:

  • app
  • tmp
  • type-fixer
  • vendor
  • www
  • … and a few others

I run type-fixer by starting bash in my Docker container and then

cd /var/www/app
php -d memory_limit=1024M type-fixer/typefixer app/

I get a bunch of errors like

ERROR: unable to complete class App\LatteFilters: Class Nette\SmartObject was not found by locator

App\LatteFilters is a part of my project.

SmartObject exists both in project's vendor directory (/var/www/app/vendor) and in type-fixer's vendor (/var/www/app/type-fixer/vendor).

I tried placing type-fixer one level higher, as a sibling to the project directory but it didn't help:

/var/www/app/type-fixer
/var/www/app/projekt/  app tmp vendor www ...

With the sibling setup I also tried running it not only with app subdir but with the project root, to include vendor.

cd /var/www/app
php -d memory_limit=1024M type-fixer/typefixer projekt

However, it dumps a bunch of Nette/Latte related errors from vendor and dies with InvalidArgumentException.
Setting memory_limit directly in php.ini didn't help. Dies even when called like:

type-fixer/typefixer projekt/
Nette Type Fixer v0.1
---------------------
WARNING: duplicate class Test found in /var/www/app/projekt/vendor/tracy/tracy/examples/dump-snapshot.php and /var/www/app/projekt/vendor/tracy/tracy/examples/dump.php
ERROR: unable to complete class Nette\Bridges\ApplicationLatte\SnippetBridge: Class Latte\Runtime\ISnippetBridge was not found by locator
ERROR: unable to complete class Nette\Bridges\CacheLatte\CacheMacro: Class Latte\IMacro was not found by locator
ERROR: unable to complete class Tracy\Bridges\Psr\TracyToPsrLoggerAdapter: Class Psr\Log\AbstractLogger was not found by locator
ERROR: Nette\Utils\DateTime::createFromFormat() type of parameter $timezone is not compatible with DateTime::createFromFormat()
Error: Class Psr\Log\LogLevel was not found by locator
InvalidArgumentException: Class Psr\Log\LogLevel was not found by locator in /var/www/app/type-fixer/src/ReflectionContext.php:40
Stack trace:
#0 /var/www/app/type-fixer/vendor/dg/parser-reflection/src/ReflectionContext.php(152): Nette\TypeFixer\ReflectionContext->locateClassFile('Psr\\Log\\LogLeve...')
#1 /var/www/app/type-fixer/vendor/dg/parser-reflection/src/ReflectionClass.php(46): Go\ParserReflection\ReflectionContext->parseClass('Psr\\Log\\LogLeve...')
#2 /var/www/app/type-fixer/src/ReflectionContext.php(32): Go\ParserReflection\ReflectionClass->__construct('Psr\\Log\\LogLeve...', NULL, Object(Nette\TypeFixer\ReflectionContext))
#3 /var/www/app/type-fixer/vendor/dg/parser-reflection/src/ValueResolver/NodeExpressionResolver.php(477): Nette\TypeFixer\ReflectionContext->getClassReflection('Psr\\Log\\LogLeve...')
#4 /var/www/app/type-fixer/vendor/dg/parser-reflection/src/ValueResolver/NodeExpressionResolver.php(278): Go\ParserReflection\ValueResolver\NodeExpressionResolver->fetchReflectionClass(Object(PhpParser\Node\Name\FullyQualified))
#5 /var/www/app/type-fixer/vendor/dg/parser-reflection/src/ValueResolver/NodeExpressionResolver.php(124): Go\ParserReflection\ValueResolver\NodeExpressionResolver->resolveExprClassConstFetch(Object(PhpParser\Node\Expr\ClassConstFetch))
#6 /var/www/app/type-fixer/vendor/dg/parser-reflection/src/ValueResolver/NodeExpressionResolver.php(296): Go\ParserReflection\ValueResolver\NodeExpressionResolver->resolve(Object(PhpParser\Node\Expr\ClassConstFetch))
#7 /var/www/app/type-fixer/vendor/dg/parser-reflection/src/ValueResolver/NodeExpressionResolver.php(124): Go\ParserReflection\ValueResolver\NodeExpressionResolver->resolveExprArray(Object(PhpParser\Node\Expr\Array_))
#8 /var/www/app/type-fixer/vendor/dg/parser-reflection/src/ValueResolver/NodeExpressionResolver.php(106): Go\ParserReflection\ValueResolver\NodeExpressionResolver->resolve(Object(PhpParser\Node\Expr\Array_))
#9 /var/www/app/type-fixer/vendor/dg/parser-reflection/src/Traits/ReflectionClassLikeTrait.php(957): Go\ParserReflection\ValueResolver\NodeExpressionResolver->process(Object(PhpParser\Node\Expr\Array_))
#10 /var/www/app/type-fixer/vendor/dg/parser-reflection/src/Traits/ReflectionClassLikeTrait.php(220): Go\ParserReflection\ReflectionClass->collectSelfConstants()
#11 /var/www/app/type-fixer/vendor/dg/parser-reflection/src/Traits/ReflectionClassLikeTrait.php(594): Go\ParserReflection\ReflectionClass->getConstants()
#12 /var/www/app/type-fixer/vendor/dg/parser-reflection/src/Traits/ReflectionClassLikeTrait.php(204): Go\ParserReflection\ReflectionClass->hasConstant('INFO')
#13 /var/www/app/type-fixer/vendor/dg/parser-reflection/src/ValueResolver/NodeExpressionResolver.php(289): Go\ParserReflection\ReflectionClass->getConstant('INFO')
#14 /var/www/app/type-fixer/vendor/dg/parser-reflection/src/ValueResolver/NodeExpressionResolver.php(124): Go\ParserReflection\ValueResolver\NodeExpressionResolver->resolveExprClassConstFetch(Object(PhpParser\Node\Expr\ClassConstFetch))
#15 /var/www/app/type-fixer/vendor/dg/parser-reflection/src/ValueResolver/NodeExpressionResolver.php(106): Go\ParserReflection\ValueResolver\NodeExpressionResolver->resolve(Object(PhpParser\Node\Expr\ClassConstFetch))
#16 /var/www/app/type-fixer/vendor/dg/parser-reflection/src/ReflectionParameter.php(108): Go\ParserReflection\ValueResolver\NodeExpressionResolver->process(Object(PhpParser\Node\Expr\ClassConstFetch))
#17 /var/www/app/type-fixer/vendor/dg/parser-reflection/src/Traits/ReflectionFunctionLikeTrait.php(170): Go\ParserReflection\ReflectionParameter->__construct('log', 'level', Object(PhpParser\Node\Param), 1, Object(Go\ParserReflection\ReflectionMethod), Object(Nette\TypeFixer\ReflectionContext))
#18 /var/www/app/type-fixer/vendor/dg/parser-reflection/src/Traits/ReflectionFunctionLikeTrait.php(146): Go\ParserReflection\ReflectionMethod->getParameters()
#19 /var/www/app/type-fixer/src/Analyzer.php(109): Go\ParserReflection\ReflectionMethod->getNumberOfRequiredParameters()
#20 /var/www/app/type-fixer/src/Analyzer.php(65): Nette\TypeFixer\Analyzer->compare(Object(Go\ParserReflection\ReflectionMethod), Object(Go\ParserReflection\ReflectionMethod))
#21 /var/www/app/type-fixer/src/Analyzer.php(41): Nette\TypeFixer\Analyzer->analyzeMethod(Object(Go\ParserReflection\ReflectionMethod))
#22 /var/www/app/type-fixer/src/bootstrap.php(79): Nette\TypeFixer\Analyzer->analyze(Array, true)
#23 /var/www/app/type-fixer/typefixer(4): require('/var/www/app/ty...')

Last edited by petr.pavel (2020-11-02 18:52)

David Grudl
Nette Core | 8228
+
0
-

Looks like type fixed can't handle class aliases. It does not have a simple solution.

dkorpar
Member | 136
+
0
-

Maybe try rector it has some nette 3.0 sets, should help a lot…

https://github.com/…r/config/set

But don't expect from any of those tools one run and you're done :)

Last edited by dkorpar (2020-11-03 09:48)

petr.pavel
Member | 535
+
0
-

@dkorpar: You're right! @TomášVotruba confirmed that the Nette Type-Fixer's changes are mirrored in Rector's
nette-30-param-types and nette-30-return-types.

@DavidGrudl: Sorry, I don't understand how class aliases are related to the errors I'm getting (because I don't understand the errors). Is it the last one about “Psr\Log\LogLevel”? Is there something I can do to work around the issue?

I'm puzzled about the Nette and Tracy related errors, is this something I messed up? I don't doubt this tools works with Nette/Tracy's own classes :-)

David Grudl
Nette Core | 8228
+
0
-

Unfortunately, it doesn't work with the current Nette anymore, as it turned out. Because it does not find classes that are created using class_alias. And I don't have time to fix it now.

petr.pavel
Member | 535
+
0
-

I see, thanks for the explanation David.

wikaaaxxx
Member | 1
+
0
-

I had a lot of trouble starting it too