-
-
Notifications
You must be signed in to change notification settings - Fork 500
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
[4.x] Add PHPStan analysis to the build #197
Conversation
@@ -25,6 +25,7 @@ before_script: | |||
|
|||
script: | |||
- ./vendor/bin/parallel-lint src tests | |||
- composer run phpstan |
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.
By calling the Composer script, it runs the same configuration as you would run locally.
@@ -37,6 +37,8 @@ | |||
"mockery/mockery": "^1.0", | |||
"moontoast/math": "^1.1", | |||
"php-mock/php-mock-phpunit": "^2.0", | |||
"phpstan/phpstan-phpunit": "0.9.2", | |||
"phpstan/phpstan-shim": "0.9.1", |
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.
this is the actual tool, but wrapped in a phar so it does not install any other dependencies
"test": [ | ||
"@lint", | ||
"@phpstan", |
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.
it should be ran before tests, because it can discover issues that would make tests fail anyway
@@ -67,8 +69,13 @@ | |||
"lint": "parallel-lint src tests", | |||
"phpunit": "phpunit --verbose --colors=always", | |||
"phpcs": "phpcs src tests --standard=psr2 -sp --colors", | |||
"phpstan": [ | |||
"@php vendor/phpstan/phpstan-shim/phpstan.phar analyse -c phpstan.neon src --level 2 --no-progress", |
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.
by splitting analysis of src
and tests
separate config file can be provided (e.g. with different ignored erros)
@@ -58,7 +58,7 @@ public function calculateTime($seconds, $microSeconds) | |||
*/ | |||
public function convertTime($timestamp) | |||
{ | |||
if (!$timestamp instanceof GMP) { | |||
if (!$timestamp instanceof \GMP) { |
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.
Please check if this is correct
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.
I’d like to understand more about what this does. Very little code has changed, but it looks like a lot of comments have been added. Does phpstan require these comments?
Most of the changes are for both PHPStorm and PHPStan (and anything that tries to analyze the code)
eg. in the following code, the public function testGetClockSeqLow()
{
+ /** @var Uuid $uuid */
$uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');
$this->assertEquals(33, $uuid->getClockSeqLow());
}
|
$this->assertInstanceOf( | ||
SodiumRandomGenerator::class, | ||
$uuid->getFactory()->getRandomGenerator() | ||
$actualUuidFactory->getRandomGenerator() |
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.
I'm not sure about this change, but originally it was calling the static method non-statically.
PHPStan works by analyzing the types in the code and in the phpdocs and then it uses it to report potentially incorrect code. (It knows, that if the method accepts some type, you cannot pass other type there.) The analysis is possible by having proper types in the code (which also helps the PHPStorm and other IDEs). If there is anything else I can explain, you can comment directly at the specific line of the diff. |
After considering this some more, I've decided to accept it. Thanks for all your hard work! |
✅ SemVer Sentry ResultThis PR will not change anything and can be merged freely without breaking backwards compatibility. If you decide to create a release after merging this PR, you should know that the changes in this PR warrants at least a PATCH version release. SemVer Sentry is in beta, take it's recommendations with a grain of salt and if in doubt, double check. If you want to get in touch with us, use the contact form on our homepage. See here for more information on semantic versioning (semver). |
PHPStan is a PHP Static Analysis Tool.
I've fixed the errors it can find up to level 2 (it has 7 levels of checks), but this PR is already big enough, so I will create another one later on.