Skip to content
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

Migrate to Doctrine CS 10 on 3.0.x #9886

Closed
wants to merge 1 commit into from

Conversation

derrabus
Copy link
Member

@derrabus derrabus commented Jul 8, 2022

This is #9866 on 3.0.x. I'd like to keep track of what the new CS standard would do to our precious codebase. 😬

@derrabus
Copy link
Member Author

derrabus commented Jul 8, 2022

@simPod Apparently, the introduction of the SlevomatCodingStandard.Functions.RequireTrailingCommaInCall.MissingTrailingComma sniff causes some trouble for us. If I run PHPCBF, it fails to fix someof the reported errors. Do you have time to investigate that?

PHPCBF RESULT SUMMARY
--------------------------------------------------------------------------------------------------
FILE                                                                              FIXED  REMAINING
--------------------------------------------------------------------------------------------------
lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php               FAILED TO FIX
lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php               FAILED TO FIX
lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryRegionCommand.php          FAILED TO FIX
lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php               FAILED TO FIX
lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php                 FAILED TO FIX
lib/Doctrine/ORM/Tools/Console/Command/InfoCommand.php                            FAILED TO FIX
lib/Doctrine/ORM/Tools/Console/Command/ClearCache/CollectionRegionCommand.php     FAILED TO FIX
lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php                 FAILED TO FIX
lib/Doctrine/ORM/Tools/Console/Command/ClearCache/MetadataCommand.php             FAILED TO FIX
lib/Doctrine/ORM/Tools/Console/Command/ClearCache/EntityRegionCommand.php         FAILED TO FIX
--------------------------------------------------------------------------------------------------
A TOTAL OF 19 ERRORS WERE FIXED IN 10 FILES
--------------------------------------------------------------------------------------------------
PHPCBF FAILED TO FIX 10 FILES
--------------------------------------------------------------------------------------------------

@simPod
Copy link
Contributor

simPod commented Jul 8, 2022

@derrabus I think I've already did. Try disabling Generic.Functions.FunctionCallArgumentSpacing.NoSpaceAfterComma. It causes conflict for the fixer.

@derrabus
Copy link
Member Author

derrabus commented Jul 8, 2022

Indeed, that did the trick, thanks. Is this a bug we need to report to PHPCS or would we rather deactivate that rule in the Doctrine CS?

@simPod
Copy link
Contributor

simPod commented Jul 8, 2022

I plan to investigate the conflict and then will see what to do about it. Either report origin lib or/and send PR to Doctrine CS.

Comment on lines -405 to -403
/**
* @var Train
* @OneToOne(targetEntity="Train", fetch="EAGER")
*/
public $train
Copy link
Member Author

Choose a reason for hiding this comment

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

This change is a bit unfortunate. SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint is triggered here although it's not just a parameter type that is being added here, but also a property type.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

No, these changes have been produced with version 8.2.0 already.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm looking at this again and I don't think I understand what the issue is 🤔.

The @var seems redundant so it's added as a native TH.

@simPod
Copy link
Contributor

simPod commented Jul 8, 2022

@derrabus the issue has been there for a long time so I don't think it's relevant for our CS v10.

squizlabs/PHP_CodeSniffer#3477

There are two squizlabs sniffs conflicting because they have never understood trailing commas.

@derrabus
Copy link
Member Author

derrabus commented Jul 8, 2022

Okay, but by introducing more trailing comma rules, we create a footgun if we don't deactivate that conflicting rule in Doctrine CS, don't we?

@simPod
Copy link
Contributor

simPod commented Jul 8, 2022

@derrabus both sniffs are useful I think, it will require a fix in squizlabs/PHP_CodeSniffer

@@ -88,7 +88,7 @@ abstract class AbstractQuery
/**
* The user-specified ResultSetMapping to use.
*/
protected ?ResultSetMapping $_resultSetMapping = null;
protected ResultSetMapping|null $_resultSetMapping = null;
Copy link
Member

Choose a reason for hiding this comment

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

What's the rationale behind enforcing the usage of union types instead of nullable types?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

@morozov morozov Jul 9, 2022

Choose a reason for hiding this comment

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

Personally, I believe arbitrary union types (e.g. getValue(sting $key): int|string|false) often reflect poor API design while nullable types are fine (e.g. findUser(int $id): ?User).

I think that enforcing a feature introduced primarily to support the existing poor design of the PHP's own API and the type system as a one-size-fits-all solution is not the right move.

Copy link
Contributor

Choose a reason for hiding this comment

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

Union types are fine. I must disagree that union types often reflect poor API design. I think the premise is too simplified.

Copy link
Member Author

Choose a reason for hiding this comment

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

We have two ways of expressing the same thing: a union of a type and null. Normalizing that is reasonable imho. Whether we use the old nullable syntax or the new union syntax does not matter that much to me, as long as we agree on a single way to do it.

And I don't follow that "poor API design" argument either.

Copy link
Member Author

Choose a reason for hiding this comment

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

All right, so how do you suggest to proceed here?

Copy link
Member

Choose a reason for hiding this comment

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

We do not forbid nullable types in the coding standard: doctrine/coding-standard#266 (comment).

Copy link
Member Author

Choose a reason for hiding this comment

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

We do not forbid nullable types in the coding standard

That means, we would allow both ways of expressing nullable types? Or would we let the fixer change Foo|null to ?Foo?

Do you want to open a PR on the coding-standards repo that makes the necessary config adjustments? I think, this change should be discussed there.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think different topic is discussed here. The sniff is not about whether or not it is ok to design API with unions. It's not about API at all.

The sniff is about consistent usage of union types. If there are no unions, the sniff does not apply.

If there's union of Type and null, it should be written as union: Type|null. The archaic ?Type was introduced because of absence of union types in the language. Since there's unions support now, there's no reason to use ? because it's inconsistent. We already have null value and will have null standalone type in 8.2.

Copy link
Member

Choose a reason for hiding this comment

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

That means, we would allow both ways of expressing nullable types? Or would we let the fixer change Foo|null to ?Foo?

If the latter is possible, I would prefer that. Otherwise, the former is fine.

Do you want to open a PR on the coding-standards repo that makes the necessary config adjustments?

No.

@derrabus
Copy link
Member Author

Replaced by #10011

@derrabus derrabus closed this Aug 30, 2022
@derrabus derrabus deleted the bump/doctrine-cs-on-3.0.x branch August 30, 2022 11:40
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.

None yet

3 participants