Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File/File.php calls activeSniff before it is set #350

Closed
jrmadsen67 opened this issue Feb 2, 2020 · 6 comments
Closed

File/File.php calls activeSniff before it is set #350

jrmadsen67 opened this issue Feb 2, 2020 · 6 comments
Labels
bug Something isn't working

Comments

@jrmadsen67
Copy link

jrmadsen67 commented Feb 2, 2020

Q A
Bug report? yes
Feature request? no
Library version ^1.7

Tracing this, the problem seems to be:

  • Domain/File.php -> parse() is called at the top of -> process()
  • in my case, it is choking on the line ending check, which calls ->addWarningOnLine(), which in turn calls -> addMessage() BUT...
  • -> addMessage() is overwritten in Domain/File.php which uses ->activeSniff ... which isn't set until after the ->parse() from above

I'll poke around a little more for a quick workaround & confirm that is the issue; I'm new to Insights (today) so may need a little time to track it all down

Here is the dump:

[2020-02-02 16:40:12] local.ERROR: Call to a member function addDetails() on null {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Call to a member function addDetails() on null at /home/vagrant/Code/Madera/vendor/nunomaduro/phpinsights/src/Domain/File.php:139)
[stacktrace]
#0 /home/vagrant/Code/Madera/vendor/squizlabs/php_codesniffer/src/Files/File.php(752): NunoMaduro\\PhpInsights\\Domain\\File->addMessage(false, 'File has mixed ...', 1, 1, 'Internal.LineEn...', Array, 0, false)
#1 /home/vagrant/Code/Madera/vendor/squizlabs/php_codesniffer/src/Files/File.php(591): PHP_CodeSniffer\\Files\\File->addWarningOnLine('File has mixed ...', 1, 'Internal.LineEn...')
#2 /home/vagrant/Code/Madera/vendor/nunomaduro/phpinsights/src/Domain/File.php(54): PHP_CodeSniffer\\Files\\File->parse()
#3 /home/vagrant/Code/Madera/vendor/nunomaduro/phpinsights/src/Domain/File.php(111): NunoMaduro\\PhpInsights\\Domain\\File->process()
#4 /home/vagrant/Code/Madera/vendor/nunomaduro/phpinsights/src/Domain/FileProcessors/SniffFileProcessor.php(61): NunoMaduro\\PhpInsights\\Domain\\File->processWithTokenListenersAndFileInfo(Array, Object(Symfony\\Component\\Finder\\SplFileInfo))
#5 /home/vagrant/Code/Madera/vendor/nunomaduro/phpinsights/src/Domain/Runner.php(97): NunoMaduro\\PhpInsights\\Domain\\FileProcessors\\SniffFileProcessor->processFile(Object(Symfony\\Component\\Finder\\SplFileInfo))
#6 /home/vagrant/Code/Madera/vendor/nunomaduro/phpinsights/src/Domain/Runner.php(83): NunoMaduro\\PhpInsights\\Domain\\Runner->processFile(Object(Symfony\\Component\\Finder\\SplFileInfo))
#7 /home/vagrant/Code/Madera/vendor/nunomaduro/phpinsights/src/Domain/Insights/InsightFactory.php(110): NunoMaduro\\PhpInsights\\Domain\\Runner->run()
#8 /home/vagrant/Code/Madera/vendor/nunomaduro/phpinsights/src/Domain/Insights/InsightFactory.php(78): NunoMaduro\\PhpInsights\\Domain\\Insights\\InsightFactory->runInsightCollector(Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#9 /home/vagrant/Code/Madera/vendor/nunomaduro/phpinsights/src/Domain/Insights/InsightCollectionFactory.php(85): NunoMaduro\\PhpInsights\\Domain\\Insights\\InsightFactory->makeFrom('ObjectCalisthen...', Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#10 [internal function]: NunoMaduro\\PhpInsights\\Domain\\Insights\\InsightCollectionFactory->NunoMaduro\\PhpInsights\\Domain\\Insights\\{closure}('ObjectCalisthen...')
#11 /home/vagrant/Code/Madera/vendor/nunomaduro/phpinsights/src/Domain/Insights/InsightCollectionFactory.php(91): array_map(Object(Closure), Array)
#12 /home/vagrant/Code/Madera/vendor/nunomaduro/phpinsights/src/Application/Console/Analyser.php(58): NunoMaduro\\PhpInsights\\Domain\\Insights\\InsightCollectionFactory->get(Array, Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#13 /home/vagrant/Code/Madera/vendor/nunomaduro/phpinsights/src/Application/Console/Commands/AnalyseCommand.php(60): NunoMaduro\\PhpInsights\\Application\\Console\\Analyser->analyse(Object(NunoMaduro\\PhpInsights\\Application\\Console\\Formatters\\Console), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#14 /home/vagrant/Code/Madera/vendor/nunomaduro/phpinsights/src/Application/Adapters/Laravel/Commands/InsightsCommand.php(51): NunoMaduro\\PhpInsights\\Application\\Console\\Commands\\AnalyseCommand->__invoke(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#15 [internal function]: NunoMaduro\\PhpInsights\\Application\\Adapters\\Laravel\\Commands\\InsightsCommand->handle()
#16 /home/vagrant/Code/Madera/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array)
#17 /home/vagrant/Code/Madera/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#18 /home/vagrant/Code/Madera/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#19 /home/vagrant/Code/Madera/vendor/laravel/framework/src/Illuminate/Container/Container.php(576): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#20 /home/vagrant/Code/Madera/vendor/laravel/framework/src/Illuminate/Console/Command.php(183): Illuminate\\Container\\Container->call(Array)
#21 /home/vagrant/Code/Madera/vendor/symfony/console/Command/Command.php(255): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#22 /home/vagrant/Code/Madera/vendor/laravel/framework/src/Illuminate/Console/Command.php(170): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#23 /home/vagrant/Code/Madera/vendor/symfony/console/Application.php(1012): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#24 /home/vagrant/Code/Madera/vendor/symfony/console/Application.php(272): Symfony\\Component\\Console\\Application->doRunCommand(Object(NunoMaduro\\PhpInsights\\Application\\Adapters\\Laravel\\Commands\\InsightsCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#25 /home/vagrant/Code/Madera/vendor/symfony/console/Application.php(148): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#26 /home/vagrant/Code/Madera/vendor/laravel/framework/src/Illuminate/Console/Application.php(90): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#27 /home/vagrant/Code/Madera/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(133): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#28 /home/vagrant/Code/Madera/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#29 {main}
"}

<!--
Love PHP Insights? Please consider supporting us via Patreon or OpenCollective:
👉  https://www.patreon.com/nunomaduro
👉  https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L
--
@olivernybroe olivernybroe added the bug Something isn't working label Feb 6, 2020
@olivernybroe
Copy link
Collaborator

I have not been able to reproduce this.
Is this still happening for you?

@jrmadsen67
Copy link
Author

Hi Oliver!

To trigger this error you will need to have a file with mixed line endings, to trigger this warning in code_sniffer/ Files/File.php

image

One that is triggered, I think it is easier to make sense of my notes above - you'll see that the way Insights has overridden addMessage(), it is trying to use ->activeSniff before that is set

Thanks!

@jiasilu
Copy link

jiasilu commented May 20, 2020

I've encountered the same error as well. @jrmadsen67 Were you able to find a workaround? Thanks!

@jrmadsen67
Copy link
Author

jrmadsen67 commented May 20, 2020 via email

@jiasilu
Copy link

jiasilu commented May 20, 2020

@jrmadsen67 Appreciate it, thx!

@JustSteveKing
Copy link
Collaborator

Gone stale, closing for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants