phpstan / phpstan-shim Goto Github PK
View Code? Open in Web Editor NEW[DEPRECATED] This repository provides easy way to install PHPStan without the risk of conflicting dependencies.
License: MIT License
[DEPRECATED] This repository provides easy way to install PHPStan without the risk of conflicting dependencies.
License: MIT License
Hi there,
I just installed the 0.9.2
version of phpstan/phpstan-shim.
I'm using the following configuration :
parameters:
level: 1
autoload_file: %currentWorkingDirectory%/vendor/autoload.php
I'm launching phpstan itself the following way :
$ vendor/bin/phpstan analyse --configuration module/Feedback/phpstan.neon module/Feedback
I get the following result :
No rules detected
You have the following choices:
* while running the analyse option, use the --level option to adjust your rule level - the higher the stricter
* create your own custom ruleset by selecting which rules you want to check by copying the service definitions from the built-in config level files in phar:///home/leonard/Projects/Mailjet/front/Code/mailjet-zend/vendor/phpstan/phpstan-sh
im/phpstan.phar/conf.
* in this case, don't forget to define parameter customRulesetUsed in your config file.
If I use the PHPStan Docker image like this :
$ docker run --rm -v "${PWD}":/app phpstan/phpstan analyse --configuration /app/module/Feedback/phpstan.neon /app/module/Feedback
๐ it works
Any idea on what I'm doing wrong ?
Not sure if problem is in this package or phpstan actually but I get error when runing
vendor\bin\phpstan.bat
'bash' is not recognized as an internal or external command,
operable program or batch file.
edit:
works when calling vendor\bin\phpstan.phar.bat, but not really sure why upper isn't... I believe it's still a bug...
Once I require phpstan/phpstan-shim in my project, I can not require nikic/php-parser since it declares it replaces it.
phpstan-shim should not replace nikic/php-parser.
I'm using phpstan-shim to avoid conflicts with my project dependencies, isn't it supposed to be used in this case?
I've read the README file about this
For technical reasons, if your project depends on nikic/php-parser package, make sure you have the PHAR PHP extension enabled, otherwise the composer autoloader will not work as expected.
here's my configuration:
php --ri phar
Phar
Phar: PHP Archive support => enabled
Phar EXT version => 2.0.2
Phar API version => 1.1.1
SVN revision => $Id: f1155e62742ca367e521a3e412667d8ee34eead9 $
Phar-based phar archives => enabled
Tar-based phar archives => enabled
ZIP-based phar archives => enabled
gzip compression => enabled
bzip2 compression => enabled
Native OpenSSL support => enabled
Phar based on pear/PHP_Archive, original concept by Davey Shafik.
Phar fully realized by Gregory Beaver and Marcus Boerger.
Portions of tar implementation Copyright (c) 2003-2009 Tim Kientzle.
Directive => Local Value => Master Value
phar.readonly => On => On
phar.require_hash => On => On
phar.cache_list => no value => no value
Although, version 0.8 is tagged in this repository, there is no such version on packagist:
https://packagist.org/packages/phpstan/phpstan-shim
In projects depending on nikic/php-parser, phpstan/phpstan-shim cannot be uninstalled.
For example, this issue affect all Symfony projects using symfony/maker-bundle.
Simple way to reproduce:
$ composer req --dev phpstan/phpstan-shim nikic/php-parser
$ composer remove phpstan/phpstan-shim
$ tree vendor
vendor
โโโ autoload.php
โโโ bin
โย ย โโโ phpstan -> ../phpstan/phpstan-shim/phpstan
โย ย โโโ phpstan.phar -> ../phpstan/phpstan-shim/phpstan.phar
โโโ composer
โโโ phpstan
โโโ phpstan-shim
โโโ LICENSE
โโโ README.md
โโโ bootstrap.php
โโโ composer.json
โโโ phpstan
โโโ phpstan.phar
4 directories, 18 files
Probably related to #29.
Hi.
I'm trying to setup phpstan-shim
with the doctrine and symfony extensions. My global composer.json
file is:
{
"require": {
"asm89/twig-lint": "@stable",
"squizlabs/php_codesniffer": "~3.4",
"dealerdirect/phpcodesniffer-composer-installer": "~0.5",
"sirbrillig/phpcs-variable-analysis": "~2.4",
"slevomat/coding-standard": "~4.8",
"phpstan/phpstan-shim": "~0.11",
"phpstan/phpstan-symfony": "~0.11",
"phpstan/phpstan-doctrine": "~0.11",
"phploc/phploc": "~4.0"
}
}
In the (Symfony 4) project, my phpstan.neon
file looks like this:
includes:
- vendor/phpstan/phpstan-symfony/extension.neon
- vendor/phpstan/phpstan-doctrine/extension.neon
parameters:
autoload_files:
- %currentWorkingDirectory%/vendor/autoload.php
symfony:
container_xml_path: %currentWorkingDirectory%/var/cache/dev/srcApp_KernelDevDebugContainer.xml
level: 2
paths:
- src
When I try to run phpstan
, it complains that it cannot find /path/to/my/project/vendor/phpstan/phpstan-symfony/extension.neon
. Using %rootDir%
in the includes:
section doesn't work ---i.e., it doesn't expand to the actual path.
The only thing that seems to work is using an absolute path (e.g., /home/myuser/.config/composer/vendor/phpstan/phpstan-symfony/extension.neon
, which is not portable).
Once using the absolute path for the extensions, I get namespace-related errors. ---and using %rootDir%
for the global autoload.php
doesn't work because there's a phar:
prefix.
Any ideas on how to solve the issues? Any workarounds?
Do you have a plan how to include conf/bleedingEdge.neon from the phar file?
Thanks.
Could conf directory from phptan/phpstan be part of phpstan/phpstan-shim package? I would like to include these configs when using phpstan/phpstan-shim.
provide
doesn't work as expected. Consider this:
$ composer require --dev phpstan/phpstan-shim phpstan/phpstan-nette
It installs both phpstan-shim
and phpstan
. As a result, the bundled code only loads the
application's autoloader from cwd, which, obviously, fails to load the prefixed classes.
$ composer why phpstan/phpstan
phpstan/phpstan-nette 0.7 requires phpstan/phpstan (^0.7)
Looking at the docs, provide
section talks about virtual packages, which would explain why there is one called phpstan/phpstan
on packagist:
However, Composer seems to install the real package of the same name.
Maybe replace
would do the trick instead of provide
?
Providing the .phar
as composer bin directly is bad, because the phar appears in project two times and PhpStorm is confused from it, and claims duplicated classes.
There should be a phpstan
binary (that actually calls the phar), that can be safely symlinked.
PHP-DI has a CompiledContainer cache and depends on nikic/php-parser
, but as this package has replace on nikic/php-parser, that package is never installed when phpstan-shim is installed as a development dependency and having run composer install --no-dev
. Composer autoloader fails when loading my app with:
PHP Fatal error: Class 'PhpParser\NodeVisitorAbstract' not found in /srv/app/vendor/jeremeamia/SuperClosure/src/Analyzer/Visitor/ClosureLocatorVisitor.php on line 17
Fatal error: Class 'PhpParser\NodeVisitorAbstract' not found in /srv/app/vendor/jeremeamia/SuperClosure/src/Analyzer/Visitor/ClosureLocatorVisitor.php on line 17
/srv/app (master โ)โน แ
composer why nikic/php-parser
jeremeamia/SuperClosure 2.4.0 requires nikic/php-parser (^1.2|^2.0|^3.0|^4.0)
php-di/php-di 6.0.2 requires nikic/php-parser (^2.0|^3.0|^4.0)
phpstan/phpstan-shim 0.10.1 replaces nikic/php-parser (^4.0.2)
psy/psysh v0.9.6 requires nikic/php-parser (~1.3|~2.0|~3.0|~4.0)
/srv/app (master โ)โน แ
composer why jeremeamia/superclosure
php-di/php-di 6.0.2 requires jeremeamia/superclosure (^2.0)
I have tried to both 0.10.1
and master
branch. For me, this package is unusable in my application.
Please consider adding a detached signature to the phpstan.phar releases, so the validity of the release phar can also be verified. This would also allow installing phpstan via phive.
In 0.9 version I used this config:
parameters:
autoload_directories:
- %rootDir%/../../../../app
Now in 0.10 it's not possible since the path is prefixed with the phar:// protocol prefix. phar://D:\storage\webs\signaly.cz\app'
I was wondering if there will be a new release since phpstan/phpstan is now at 0.8.5.
Even though this package should make it easier to use side-by-side with application dependencies, there is problem with way Composer autoincludes files autoloaded via autoload.files
.
The file, that makes problems, is vendor/nette/di/compatibility.php
.
When Composer includes bootstrap.php, it includes files from all dependencies, that are mentioned in autoload
with type files
. Composer then saves file identifiers of those files to $GLOBALS
($GLOBALS['__composer_autoload_files'][$fileIdentifier] = true
) "Same" files used by project are then skipped. Note that this is may or may not work depending on order of packages calculated by Composer.
This is regression caused by e7dd0a0.
phpstan/phpstan-shim autoloader probably should not pollute application autoloading if it's not running in context of phpstan analysis.
Hi, what's the difference between this package and https://github.com/sensiolabs-de/deptrac-shim? Thanks.
Since #16, when running a project that has phpstan/phpstan-shim in its dependencies, the bootstrap.php is called and loads the shim dependencies.
I'm not sure this is expected.
More over, loading over a phar is quite slow and has a significative performance impact (between 10ms and 25ms on an SymfonyCloud server).
Why did you do that? Is there a way to fix this perf issue?
NB : Yes, I know it's a dev dependency, however I would like to be able to run my project with dev dependencies installed without a perf impact - at least not a such big impact.
Just after a fresh install with composer global require
, I have this:
phpstan analyse -c phpstan.neon -l 3 src tests
Fatal error: Uncaught Error: Class 'PHPStanVendor\Jean85\PrettyVersions' not found in phar:///home/developer/.composer/vendor/phpstan/phpstan-shim/phpstan.phar/bin/phpstan:23
Stack trace:
#0 /home/developer/.composer/vendor/phpstan/phpstan-shim/phpstan.phar(4): require()
#1 {main}
thrown in phar:///home/developer/.composer/vendor/phpstan/phpstan-shim/phpstan.phar/bin/phpstan on line 23
The file (directory) exclusion by excludes_analyse
is not working in PHAR-ed version of PHPStan (0.7).
The files in excluded directories are still scanned and reported.
While this works fine in normal version (0.7) because PHPStan resides in <project>/vendor/phpstan/phpstan/bin/phpstan
:
parameters:
excludes_analyse:
- %rootDir%/../../../src/Component/Foo/tests/*
Than I'd expect that %rootDir%/../src/Component/Foo/tests/*
would work for PHAR-ed version because it resides in <project>/bin/phpstan.phar
(because of my config.bin-dir
in composer.json
).
If my understanding is correct, does the package, providing a standalone phar executable, need to reference the nikic/php-parser
as a replacement dependency?
If so, would it be possible to soften it to ^3 || ^4
?
Currently, it's conflicting with SilverStripe framework admin module's requirement of version 3.
I see that you are using phpstan-compiler to prefix a code. But maybe instead of going for a in-house solution, PHP-Scoper could be used for it? The idea is basically the same, but it tries to do it in a more generic way.
Let me know if you're interested, otherwise feel free to close that issue :)
This package cannot replace future 4.x version of nikic-parser. That does not make sense. and it might break project if something depends on a newer version of nikic-/php-parser than what is in the phar, as composer will happily think that this newer version is provided.
Before recent changes, this phpstan.neon file inside /tests folder was valid:
parameters:
autoload_files:
- tests/bootstrap.php
There is also a tests/bootstrap.php file
This is running here:
php phpstan.phar analyse -c tests/phpstan.neon -l 1 src/
This was all working for months.
But now on travis this errors with:
Script returned with error code 1
Autoload file /home/travis/build/.../tests/tests/bootstrap.php does not exist.
It also still is working locally, with exactly the same downloaded file.
So it must be some weird issue on the PHP version on travis (php5.6) together with the phar file.
It should not duplicate the tests folder, but instead use the defined file above relative from the cwd.
Hi,
how to use %rootDir% when running phpstan.phar? When I pass %rootDir% to an extension class i get a path like this: "phar:///home/xxx/yyy/vendor/phpstan/phpstan-shim/phpstan.phar". If I want to pass a directory for example to symfony extension (https://github.com/lookyman/phpstan-symfony#configuration) i can't really do that.
I have a production dependency which in turn depends on nikic/php-parser. Without installing phpstan-shim this works fine when I run composer install --no-dev
to exclude dev dependencies. However when I add phpstan-shim to my dev dependencies and run composer install --no-dev
, the nikic/php-parser
dependency is not installed.
This might be a bug in composer as phpstan-shim is a dev dependency and thus its replace rule should never be loaded when installing without dev dependencies.
To sum it up:
--no-dev
) = installs without warning but does not install nikic/php-parserHowever, I wonder why nikic/php-parser is referenced at all?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.