-
Notifications
You must be signed in to change notification settings - Fork 94
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 setup & level1 fixes #276
Conversation
@acoulton one motivation for adding PHPStan is that during the recent title change, I realised that there is a big discrepancy in types. For example: class SomeRecord
{
/** @var string */
private $keyword; // 1️⃣
/** @var int */
private $line; // 1️⃣
/**
* @param string $keyword
* @param int $line
*/
public function __construct($keyword, $line) { // 2️⃣
$this->keyword = $keyword;
$this->line = $line;
}
/** @return string */ // 3️⃣
public function getKeyword(){ return $this->keyword; } // 4️⃣
/** @return int */ // 3️⃣
public function getLine(){ return $this->line; } // 4️⃣
}
class SomeRecordTest extends TestCase
{
public function testSomething(): void
{
$r = new SomeRecord('word', null); // 5️⃣
...
}
} The main problem: I would like to fix that and declare types in a backword compatible way:
Alternatively, we could avoid the BC headache and define all the types correctly for the next major release. What do you think? |
57a92b2
to
d83e4a7
Compare
@uuf6429 I haven't looked at this or your PHP-CS pulls in detail as I realised they're marked draft and overlap a bit with the PHPUnit / docs PR so I assume we should review & merge those first. On the type-safety, I think (if we're certain it is only tests that are passing nulls):
|
Regarding this draft pull request: In the main Behat repository we use Psalm, while this PR introduces PHPStan in this one. I believe that it would be better if we unified this and used a single static analysis tool. Otherwise this can be confusing when you are working in one code base or the other and you need to follow different processes depending on which repo you are on. So I believe that we have two options:
Also, I am not a big fan of baseline files. They have a number of drawbacks:
|
@carlos-granados as you know, this is just a draft, so I wouldn't focus too much on it yet. But to answer your points:
The next point would be if we merge this PR and the fixes PR into one (to avoid polluting github) or if we keep them separate (and e.g. the baseline would be stored somewhere in the git history). This can be discussed later though. PS: A small comment on one of your points: if a baselined error becomes obsolete, PHPStan will fail automatically (unless disabled by a specific setting). Just an FYI. |
I'd agree with just using PHPStan - I noticed the doctrine project have just decided to drop psalm and use PHPStan-only in future. Also agree with @carlos-granados that my preference would be to introduce it at the lowest-compatible level (without a baseline) and then gradually increase the level in parallel with fixing the issues. This also means it's easy to see from the config which level we have actually achieved. |
d83e4a7
to
402b751
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this @uuf6429 - I spotted a couple of things / questions.
ac537e1
to
5fae544
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks @uuf6429
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, thanks @uuf6429 , just a small comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good now, thanks @uuf6429
Based on #277.This PR sets up PHPStan and applies fixes until level 1.
The plan is to fix the problems separately later on.