-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
Enhancement: Implement Files\DeclareStrictTypesRule #79
Conversation
Thank you for your contribution!
Unless I am mistaken, this could be implemented for other tokens as well, take a look, for example, at
You could circumvent this by applying the following patch: diff --git a/.php_cs.fixture b/.php_cs.fixture
index 492256b..e4f85cf 100644
--- a/.php_cs.fixture
+++ b/.php_cs.fixture
@@ -5,6 +5,7 @@ declare(strict_types=1);
use Localheinz\PhpCsFixer\Config;
$config = Config\Factory::fromRuleSet(new Config\RuleSet\Php71(''), [
+ 'declare_strict_types' => false,
'lowercase_constants' => false,
'magic_method_casing' => false,
'static_lambda' => false, Now, before you jump in into making these changes, I'm not entirely sure whether these rules would be very useful. That is, while I agree that it makes sense to point out the lack of a strict types statement, this issue could be automatically fixed by enabling the What do you think? |
I find it hard at times to cut the line between static analyzers like phpstan and coding standard checkers. And I think the In a legacy project I work on 95% of the code does not have the declaration (as it was coded before php 7). While we define it in every new file, we cannot change it in the old code though as it would break things. So in this project this is definitively "code". That being said, I'd totally understand if you'd like to not have this rule in here, so don't worry to deny it. :-) |
I think that this is a much better job for: https://github.com/slevomat/coding-standard#slevomatcodingstandardtypehintsdeclarestricttypes- This rule as it's currently implemented has some downsides: * Will not report missing strict_types for files without classes
Right now, there would have to be some hardcoded virtual node for this in PHPStan (something like |
I hope you don't mind that I'm closing this - for reasoning see above comments. Regardless, thanks a lot for your contribution! |
You might like phpstan/phpstan@ed81c3a! |
Also see phpstan/phpstan-strict-rules#59. |
Let's wait for the next release of |
What do you think about my amendments? I turned this into a |
Codecov Report
@@ Coverage Diff @@
## master #79 +/- ##
===========================================
- Coverage 83.89% 83.59% -0.3%
- Complexity 82 91 +9
===========================================
Files 13 14 +1
Lines 298 317 +19
===========================================
+ Hits 250 265 +15
- Misses 48 52 +4
Continue to review full report at Codecov.
|
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.
👍
Thank you for your patience, @dmecke!
Nice, thanks for your effort! |
This PR
Files\DeclareStrictTypesRule
, which reports an error when a non-empty file does not contain adeclare(strict_types=1);
declaration