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

Upgrading to 0.7 breaks PHPStan #179

Closed
flangofas opened this issue May 8, 2020 · 21 comments · Fixed by #182
Closed

Upgrading to 0.7 breaks PHPStan #179

flangofas opened this issue May 8, 2020 · 21 comments · Fixed by #182

Comments

@flangofas
Copy link

Hey guys,

The following setup breaks PHPStan while the previous release (0.6.2) worked just fine.

PHP: 7.4
PHPStan: 0.12.23
PHPStan-Prophecy: 0.7
Relates to: slimphp/Slim-Skeleton#163

Expected:
[OK] No errors

Output:
In StubPhpDocProvider.php line 150:

[PHPStan\ShouldNotHappenException]
Internal error.

Exception trace:

  at phar:///Users/user/Development/open-source/Slim-Skeleton/vendor/phpstan/phpstan/phpstan/src/PhpDoc/StubPhpDocProvider.php:150
 PHPStan\PhpDoc\StubPhpDocProvider->initializeKnownElements() at phar:///Users/user/Development/open-source/Slim-Skeleton/vendor/phpstan/phpstan/phpstan/src/PhpDoc/StubPhpDocProvider.php:133
 PHPStan\PhpDoc\StubPhpDocProvider->isKnownClass() at phar:///Users/user/Development/open-source/Slim-Skeleton/vendor/phpstan/phpstan/phpstan/src/PhpDoc/StubPhpDocProvider.php:56
 PHPStan\PhpDoc\StubPhpDocProvider->findClassPhpDoc() at phar:///Users/user/Development/open-source/Slim-Skeleton/vendor/phpstan/phpstan/phpstan/src/Reflection/BetterReflection/BetterReflectionProvider.php:113
 PHPStan\Reflection\BetterReflection\BetterReflectionProvider->getClass() at phar:///Users/user/Development/open-source/Slim-Skeleton/vendor/phpstan/phpstan/phpstan/src/Analyser/NodeScopeResolver.php:349
 PHPStan\Analyser\NodeScopeResolver->processStmtNode() at phar:///Users/user/Development/open-source/Slim-Skeleton/vendor/phpstan/phpstan/phpstan/src/Analyser/NodeScopeResolver.php:168
 PHPStan\Analyser\NodeScopeResolver->processNodes() at phar:///Users/user/Development/open-source/Slim-Skeleton/vendor/phpstan/phpstan/phpstan/src/Analyser/FileAnalyser.php:136
 PHPStan\Analyser\FileAnalyser->analyseFile() at phar:///Users/user/Development/open-source/Slim-Skeleton/vendor/phpstan/phpstan/phpstan/src/PhpDoc/StubValidator.php:78
 PHPStan\PhpDoc\StubValidator->validate() at phar:///Users/user/Development/open-source/Slim-Skeleton/vendor/phpstan/phpstan/phpstan/src/Command/AnalyseApplication.php:57
 PHPStan\Command\AnalyseApplication->analyse() at phar:///Users/user/Development/open-source/Slim-Skeleton/vendor/phpstan/phpstan/phpstan/src/Command/AnalyseCommand.php:126
 PHPStan\Command\AnalyseCommand->execute() at phar:///Users/user/Development/open-source/Slim-Skeleton/vendor/phpstan/phpstan/phpstan/vendor/symfony/console/Command/Command.php:228
 _HumbugBoxe8a38a0636f4\Symfony\Component\Console\Command\Command->run() at phar:///Users/user/Development/open-source/Slim-Skeleton/vendor/phpstan/phpstan/phpstan/vendor/symfony/console/Application.php:849
 _HumbugBoxe8a38a0636f4\Symfony\Component\Console\Application->doRunCommand() at phar:///Users/user/Development/open-source/Slim-Skeleton/vendor/phpstan/phpstan/phpstan/vendor/symfony/console/Application.php:235
 _HumbugBoxe8a38a0636f4\Symfony\Component\Console\Application->doRun() at phar:///Users/user/Development/open-source/Slim-Skeleton/vendor/phpstan/phpstan/phpstan/vendor/symfony/console/Application.php:136
 _HumbugBoxe8a38a0636f4\Symfony\Component\Console\Application->run() at phar:///Users/user/Development/open-source/Slim-Skeleton/vendor/phpstan/phpstan/phpstan/bin/phpstan:72
 _HumbugBoxe8a38a0636f4\{closure}() at phar:///Users/user/Development/open-source/Slim-Skeleton/vendor/phpstan/phpstan/phpstan/bin/phpstan:73
 require() at /Users/user/Development/open-source/Slim-Skeleton/vendor/phpstan/phpstan/phpstan:6```
@bendavies
Copy link

Confirmed here too

@ondrejmirtes
Copy link
Contributor

The stubs here are really simple, not sure what causes this. I'm gonna investigate.

@ondrejmirtes
Copy link
Contributor

ondrejmirtes commented May 11, 2020

Unfortunately I'm not able to reproduce this. It runs fine. Running vendor/bin/phpstan analyse -c phpstan-with-extension.neon in this repo works so I'm not sure what else should I try. If you could pinpoint how the analysed source code where PHPStan crashes looks like, it'd be great.

@l0gicgate
Copy link

l0gicgate commented May 11, 2020

+1

@ondrejmirtes
Copy link
Contributor

This doesn't help me reproduce it. I need some minimal code on which it crashes like this. Thanks.

@l0gicgate
Copy link

l0gicgate commented May 11, 2020

@ondrejmirtes I liked the issue in our repo for you to look. You can easily clone that branch to reproduce.

slimphp/Slim-Skeleton#165

@bendavies
Copy link

bendavies commented May 12, 2020

@ondrejmirtes i haven't tracked this down yet but i'm getting there. the phpstan container is being build incorrectly?

	public function createServiceStubPhpDocProvider(): PHPStan\PhpDoc\StubPhpDocProvider
	{
		return new PHPStan\PhpDoc\StubPhpDocProvider(
			$this->getService('043'),
			$this->getService('083'),
			[
				'/Users/ben/Code/phpstan/phpstan-src/stubs/ReflectionClass.stub',
				'/Users/ben/Code/phpstan/phpstan-src/stubs/iterable.stub',
				'/Users/ben/Code/phpstan/phpstan-src/stubs/ArrayObject.stub',
				'/Users/ben/Code/phpstan/phpstan-src/stubs/WeakReference.stub',
				'/Users/ben/Code/phpstan/phpstan-src/stubs/ext-ds.stub',
				'/Users/ben/Code/phpstan/phpstan-src/stubs/PDOStatement.stub',
				'/Users/ben/Code/abacus-webapp/vendor/jangregor/phpstan-prophecy/src/stubs/ObjectProphecy.phpstub',
				'/Users/ben/Code/abacus-webapp/vendor/jangregor/phpstan-prophecy/src/stubs/ProphecyInterface.phpstub',
			]
		);
	}

/Users/ben/Code/abacus-webapp/vendor/jangregor/phpstan-prophecy/src/stubs/ObjectProphecy.phpstub
should be
/Users/ben/Code/abacus-webapp/vendor/jangregor/phpstan-prophecy/stubs/ObjectProphecy.phpstub

@bendavies
Copy link

bendavies commented May 12, 2020

got it. Relative paths in the stubFiles key are resolved based on the directory of the config file is in.

This repo contains https://github.com/Jan0707/phpstan-prophecy/blob/master/extension.neon and then a symlink https://github.com/Jan0707/phpstan-prophecy/blob/master/src/extension.neon for BC with 0.6.2.

If you load the symlink, i.e.

includes:
    - %currentWorkingDirectory%/vendor/jangregor/phpstan-prophecy/src/extension.neon

the relative path resolution to the stubs doesn't work.

Either phpstan could resolve symlinks or...??

@ondrejmirtes
Copy link
Contributor

If you’re running phpstan-src and not phpstan/phpstan distribution then nothing is guaranteed to work (phpstan-src is just for PHPStan development itself) but I still don’t see how this could break.

@ondrejmirtes
Copy link
Contributor

It’d be great if someone created a small reproducing repo (with phpstan/phpstan as Composer dependency) so I can debug it.

@bendavies
Copy link

@ondrejmirtes did you see my comment?

@localheinz
Copy link
Contributor

@bendavies @ondrejmirtes

I will remove the symbolic link in the next release, if that helps!

@bendavies
Copy link

@localheinz
Copy link
Contributor

@bendavies @flangofas @ondrejmirtes

I have removed the symbolic link in #182. This will break installations for people who do not use phpstan/extension-installer, but I think it's best moving forward this way:

  • I can get rid of the symbolic link
  • people might be encouraged to use phpstan/extension-installer

@ondrejmirtes

Not sure if there are other projects using symbolic links, but I believe we are good in regard to this project now, what do you think?

@ondrejmirtes
Copy link
Contributor

@localheinz Thank you, symbolic links are generally problematic, IIRC they don't translate well on Windows. (I've wanted the phpstan file in https://github.com/phpstan/phpstan to be just a symlink to phpstan.phar but it didn't work.)

People are encouraged to use extension-installer but they can't always do that. For example if they only want to use some of the rules from phpstan-strict-rules, they can't use extension-installer. Since the package is just a convenient way to save a few lines from the configuration file, it's fine.

Anyway, 👍 on the fix, using symlinks in this context is discouraged.

@ondrejmirtes
Copy link
Contributor

@bendavies Sorry, haven't seen your comment before replying.

@localheinz
Copy link
Contributor

Thank you, @ondrejmirtes!

@localheinz
Copy link
Contributor

Fixed with #182.

@bendavies
Copy link

thanks all

@flangofas
Copy link
Author

thanks for your prompt answers and the quick fix.

@localheinz
Copy link
Contributor

You are welcome, @bendavies and @flangofas!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants