-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
chore: use non-empty-list
where appropriate
#8972
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
Conversation
5874b9c
to
d2de099
Compare
@@ -334,7 +334,7 @@ private function collectDisjunctiveNormalFormTypes(string $type): array | |||
} | |||
|
|||
/** | |||
* @return array{0: list<string>, 1: string} | |||
* @return array{0: non-empty-list<string>, 1: string} |
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.
* @return array{0: non-empty-list<string>, 1: string} | |
* @param non-empty-string $type | |
* | |
* @return array{0: non-empty-list<non-empty-string>, 1: string} |
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.
Since the PR is already large, I purposely did not make any other changes than non-empty-list
.
(and the non-empty-list
changes mostly only in trivial cases where it does not add new phpstan errors etc.)
@@ -318,7 +318,7 @@ private function isTypeSortable(TypeAnalysis $type): bool | |||
} | |||
|
|||
/** | |||
* @return array{0: list<list<string>|string>, 1: string} | |||
* @return array{0: non-empty-list<non-empty-list<string>|string>, 1: string} |
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.
possibly same
# Conflicts: # src/AbstractPhpdocTypesFixer.php # src/Doctrine/Annotation/DocLexer.php
*/ | ||
private static ?array $availableFunctions = null; | ||
|
||
/** | ||
* @var array<string, list<Token>> | ||
* @var array<string, non-empty-list<Token>> |
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.
* @var array<string, non-empty-list<Token>> | |
* @var null|array<string, non-empty-list<Token>> |
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 think it is never null
. It is uninitialized or array.
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.
how do you document uninitialized?
in whole repo, i was documenting by putting null|
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.
You do not document it. PHPStan wants that uninitialized properties are initialized in constructor (with checkUninitializedProperties: true
), but you can see here that it also complains that the property never is null: https://phpstan.org/r/b1cf492b-d361-41ef-9748-d92827e40ab2
Property HelloWorld::$a (string|null) is never assigned null so it can be removed from the property type.
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.
you do not document it
it's not the way project follows.
i recommend to follow so far status quo for majority of cases, or change the approach (but apply it fully)
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's not the way project follows.
There are 48 properties using this approach (uninitialized by default, not nullable, and not initialized in constructor).
E.g. 4 of them are here.
Usually I try to avoid this. Unitialized properties should be initialized in constructor.
But in our fixers the configure
method is similar to a constructor, and many properties are initialized there. So I'm not sure if it is the right approach for us to require the initialization in constructor.
And making all these properties nullable would create many new "null value" phpstan errors, especially when using a higher level.
* @var null|non-empty-list<int> | ||
*/ | ||
private ?array $tokenKinds = null; |
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.
kind like kind
(id|string)? then docblock is wrong.
kind like one-of-old-meanings id
? then let's rename the property
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 change looks good, left few comments
I merge it as-is to not mix it with other changes. |
No description provided.