Skip to content

Add an example of a simple phpstan.neon file in the README#2744

Merged
ondrejmirtes merged 1 commit intophpstan:masterfrom
mnapoli:patch-1
Mar 19, 2020
Merged

Add an example of a simple phpstan.neon file in the README#2744
ondrejmirtes merged 1 commit intophpstan:masterfrom
mnapoli:patch-1

Conversation

@mnapoli
Copy link
Copy Markdown
Contributor

@mnapoli mnapoli commented Dec 17, 2019

I struggled a lot getting started with PHPStan because I couldn't find a simple example of a "default" phpstan.neon.

I added one in the README (in the future I may look in a phpstan init command because I think that would be even better).

@ondrejmirtes
Copy link
Copy Markdown
Member

I struggled a lot getting started with PHPStan

Can you describe your struggles? There's no configuration file needed by default. If you don't need to ignore any errors and you autoload everything via Composer, you don't need any configuration on the lower levels. README sections each describe a specific problem and there's a lot of config file examples already. But I'm not dismissing that you had problems, I just want the feedback :)

@mnapoli
Copy link
Copy Markdown
Contributor Author

mnapoli commented Dec 17, 2019

Sure, the thing is that when you use PHPStan you have to make at least 2 choices: which level, and which directories to analyze.

If I don't hardcode those anywhere, then everyone on the team might be doing something different.

This is why I always create config files: phpcs, php-cs-fixer, etc. The goal is to be able to simply run the tool without argument/option and it just works.

That has also the advantage of being much simpler (but the main reason is consistency).

So I wanted to create a PHPStan config file, but here were the steps:

  • finding the type of the file (here it's neon)
  • finding whether there is a special name so that phpstan picks it up automatically
  • finding how to setup the default level
  • finding how to setup the paths

All of these can be solved with the current README, but each information is separated from the others. Also, most of this information requires reading a full sentence of paragraph each time: I think this could be improved with a single code example. It's fine if advanced options are harder to read (because they require more explanations), but I think that making the default setup more obvious could be helpful to get started.

@mnapoli
Copy link
Copy Markdown
Contributor Author

mnapoli commented Dec 17, 2019

To illustrate what I mean, I've opened #2746

Since you mentioned it, this is exactly something that I missed when I read the README quickly. Then I read it again slowly and picked that up.

Hopefully, with a simpler sentence, it's easier to see at a glance.

I also think this could be improved further by reordering maybe: put the most important information first, then the advanced use cases later. The README is pretty huge, so I think it's hard to expect first-time users to read it all in one shot just to get started.

Anyway, those are just suggestions of course ^^ My experience is not necessarily the same for everyone.

## Configuration

Config file is passed to the `phpstan` executable with `-c` option:
A config file can passed to the `phpstan` executable using the `-c` option:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be - be is missed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still the issue

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to send a PR :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

#3103

@mnapoli
Copy link
Copy Markdown
Contributor Author

mnapoli commented Mar 19, 2020

Maybe I'm stupid, but I really need this PR.

I wanted to setup phpstan.neon. Yet again, finding information in the README was complex. I finally found what I was looking for:

Capture d’écran 2020-03-19 à 14 50 53

So I updated my config:

Capture d’écran 2020-03-19 à 14 50 59

And nope!

Capture d’écran 2020-03-19 à 14 52 45

I really don't want to be annoying with this, but I think making things dead simple is good.

I'm pretty sure I could have avoided this by actually reading more of the README. I didn't though, and I think some other users don't as well.

@dktapps
Copy link
Copy Markdown
Contributor

dktapps commented Mar 19, 2020

I suggest linking this as well. It was particularly useful to me when I needed some of the more arcane config options.

@ondrejmirtes
Copy link
Copy Markdown
Member

Hi, sure, no problem. I'm so used to nette/di that I just automatically know where to put the config options :)

@ondrejmirtes ondrejmirtes merged commit f2f4cd6 into phpstan:master Mar 19, 2020
maks-rafalko added a commit to maks-rafalko/phpstan that referenced this pull request Mar 19, 2020
ondrejmirtes pushed a commit that referenced this pull request Mar 19, 2020
@mnapoli mnapoli deleted the patch-1 branch March 20, 2020 11:32
@ondrejmirtes
Copy link
Copy Markdown
Member

I hope this is sufficient and understandable :) https://phpstan.org/config-reference

@mnapoli
Copy link
Copy Markdown
Contributor Author

mnapoli commented Apr 7, 2020

Ohhh yeahhhh 🔥 that is super useful!

Thank you!

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 this pull request may close these issues.

4 participants