Giter Site home page Giter Site logo

phpstan-shim's Introduction

PHPStan - PHP Static Analysis Tool

PHPStan

Build Status Latest Stable Version Total Downloads License PHPStan Enabled


PHPStan focuses on finding errors in your code without actually running it. It catches whole classes of bugs even before you write tests for the code. It moves PHP closer to compiled languages in the sense that the correctness of each line of the code can be checked before you run the actual line.

Read more about PHPStan »

Try out PHPStan on the on-line playground! »

Sponsors

TheCodingMachine     Private Packagist
CDN77     Blackfire.io
iO     Amezmo
ShipMonk     Togetter
RightCapital     ContentKing
ZOL     Psyonix
Shopware     Craft CMS
Worksome     campoint AG
Crisp.nl     Inviqa
GetResponse     EdgeNext
Fame Helsinki

You can now sponsor my open-source work on PHPStan through GitHub Sponsors.

Does GitHub already have your 💳? Do you use PHPStan to find 🐛 before they reach production? Send a couple of 💸 a month my way too. Thank you!

One-time donations through PayPal are also accepted. To request an invoice, contact me through e-mail.

Documentation

All the documentation lives on the phpstan.org website:

PHPStan Pro

PHPStan Pro is a paid add-on on top of open-source PHPStan Static Analysis Tool with these premium features:

  • Web UI for browsing found errors, you can click and open your editor of choice on the offending line.
  • Continuous analysis (watch mode): scans changed files in the background, refreshes the UI automatically.

Try it on PHPStan 0.12.45 or later by running it with the --pro option. You can create an account either by following the on-screen instructions, or by visiting account.phpstan.com.

After 30-day free trial period it costs 7 EUR for individuals monthly, 70 EUR for teams (up to 25 members). By paying for PHPStan Pro, you're supporting the development of open-source PHPStan.

You can read more about it on PHPStan's website.

Code of Conduct

This project adheres to a Contributor Code of Conduct. By participating in this project and its community, you are expected to uphold this code.

Contributing

Any contributions are welcome. PHPStan's source code open to pull requests lives at phpstan/phpstan-src.

phpstan-shim's People

Contributors

fprochazka avatar jantvrdik avatar lookyman avatar ondrejmirtes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

phpstan-shim's Issues

Problem with nikic/php-parser replaced dependency

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:

  • without phpstan-shim = all fine (both dev and no-dev)
  • with phpstan-shim in dev = all fine
  • with phpstan-shim in dev (with --no-dev) = installs without warning but does not install nikic/php-parser

However, I wonder why nikic/php-parser is referenced at all?

Cannot uninstall in projects depending on nikic/php-parser

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.

bootstrap.php prevents autoloading of certain files from shared dependencies with project

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.

What happens

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.

Cause

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.

Conflict with php-di

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.

Sign phar file in separate file

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.

%rootDir% users phar:// prefix

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'

Create bin that calls the phar

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.

Global install is not working

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

rootDir is not working in exclusion_analyse

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).

This package should not replace nikic/php-parser

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

On windows: "'bash' is not recognized as an internal or external command,"

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...

Use PHP-Scoper

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 :)

Bad perf impact for the bootstrap.php file

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.

Installing along with extensions installs phpstan/phpstan as well

What is the problem

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)

What seems to be the cause

Looking at the docs, provide section talks about virtual packages, which would explain why there is one called phpstan/phpstan on packagist:

snimek obrazovky 2017-05-15 v 16 07 19

However, Composer seems to install the real package of the same name.

What could be the solution

Maybe replace would do the trick instead of provide?

Bug in relative path for phar file

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.

Level in configuration file is not taken into account

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 ?

Extensions cannot be included, in a portable way, when using global install

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?

PHPstan conf directory

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.

nikic/php-parser dependency

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.