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

PHPStan configuration #285

Open
ezzatron opened this issue Nov 16, 2017 · 7 comments
Open

PHPStan configuration #285

ezzatron opened this issue Nov 16, 2017 · 7 comments

Comments

@ezzatron
Copy link
Contributor

It would be nice to have a drop-in config for Kahlan for PHPStan. Currently, when run over a Kahlan project, PHPStan warns about:

  • The DSL functions not existing.
  • The $this keyword used in kahlan-config.php outside of a class context.

Here's my current config for handling the first point:

parameters:
  ignoreErrors:
    - /^Function context not found.$/
    - /^Function describe not found.$/
    - /^Function expect not found.$/
    - /^Function it not found.$/

But there's probably a better way to fix the problem that doesn't involve "ignoring" these errors. If PHPStan can be configured to understand the functions it could actually pick up on real errors when using them. Are the DSL functions dynamically defined? That would explain why PHPStan complains.

PHPStan uses Neon config files which allow you to include a definition from a vendor, which means that if you created a kahlan/phpstan-kahlan repo, users could require it, then add something like this to their PHPStan configuration:

includes:
  - vendor/kahlan/phpstan-kahlan/kahlan.neon

I just wrote a PHPStan integration for Phony, which is probably more complex than what's needed for Kahlan, but you can check it out here anyway.

@jails
Copy link
Contributor

jails commented Nov 17, 2017

Would definitely be a must have 👍
Since the DSL functions can't be loaded through the composer files entry (to avoid collision), they are dynamically created right there and unfortunately there's nothing we can do about that.

@ezzatron
Copy link
Contributor Author

@ondrejmirtes Do you have any advice for handling conditionally defined DSL functions in PHPStan? It's a pretty common scenario for describe/it style test runners and matcher libraries like Hamcrest.

@ondrejmirtes
Copy link

@ezzatron Hi, you can take advantage of the fact that PHPStan environment should match the environment of your application - including definitions of class aliases, constants, autoloaders and defined functions 😊 So you can use the bootstrap key in phpstan.neon to provide a file that will load everything necessary for you. Looks like it should be safe to require_once this Kahlan.php file in the bootstrap.

@jails
Copy link
Contributor

jails commented Mar 10, 2018

Hello @ezzatron, were you able to find some compatible configuration with Kahlan on this topic ?

@ezzatron
Copy link
Contributor Author

Hi @jails, no, I'm sorry, but I haven't had the time to do much of anything PHP-related lately. From the sounds of it though, the bootstrap option mentioned above might solve at least the issue that PHPStan has with Kahlan's DSL functions.

@samsonasik
Copy link
Collaborator

How about run phpstan to src folder for start ?

@ezzatron
Copy link
Contributor Author

@samsonasik This issue is about creating a shared config for projects that use Kahlan, not about running PHPStan over Kahlan's own codebase.

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

No branches or pull requests

4 participants