Skip to content

Conversation

gharlan
Copy link
Member

@gharlan gharlan commented Aug 24, 2025

No description provided.

@coveralls
Copy link

coveralls commented Aug 24, 2025

Coverage Status

coverage: 94.743% (-0.01%) from 94.753%
when pulling 76275ef on gharlan:non-empty-list
into 7797011 on PHP-CS-Fixer:master.

@@ -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}
Copy link
Member

@keradus keradus Aug 24, 2025

Choose a reason for hiding this comment

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

Suggested change
* @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}

Copy link
Member Author

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}
Copy link
Member

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>>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @var array<string, non-empty-list<Token>>
* @var null|array<string, non-empty-list<Token>>

Copy link
Member Author

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.

Copy link
Member

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|

Copy link
Member Author

@gharlan gharlan Aug 24, 2025

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.

Copy link
Member

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)

Copy link
Member Author

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.

Comment on lines +50 to 52
* @var null|non-empty-list<int>
*/
private ?array $tokenKinds = null;
Copy link
Member

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

Copy link
Member

@keradus keradus left a 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

@gharlan
Copy link
Member Author

gharlan commented Aug 25, 2025

I merge it as-is to not mix it with other changes.

@gharlan gharlan merged commit 117a5b3 into PHP-CS-Fixer:master Aug 25, 2025
31 checks passed
@gharlan gharlan deleted the non-empty-list branch August 25, 2025 07:59
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.

3 participants