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

IBX-8138: [Rector] Applied rules from Symfony 5 Rector set lists #385

Merged
merged 17 commits into from
Aug 28, 2024

Conversation

alongosz
Copy link
Member

@alongosz alongosz commented Jun 14, 2024

Caution

  • Requires dependencies updating core extension point usage to be merged together
🎫 Issue IBX-8138

Related PRs:

  1. Follow-ups to ibexa/core:

  2. IBX-8138 rector changes for the other packages:

Description:

Applied rules from the Symfony 5 Rector set lists.

This is just one milestone on the way towards Symfony 6. Some Rectors address code quality. Not all deprecations are covered by the Symfony-provided Rectors. Additionally, not all deprecations are related to PHP code, which is out of scope for Rector. Moreover, some deprecations can be resolved via Symfony 6 Rectors, but only some can be applied without upgrading to Symfony 6.

This PR also includes necessary fixes to align changes with the PHPStan baseline and to address return type bugs.

The applied Rectors are as follows:

  • SF 5.0 AddParamTypeDeclarationRector adding parameter types for chosen set of Symfony methods, if used by 1st party,

  • SF 5.1 CommandConstantReturnCodeRector - e.g.: return self::SUCCESS instead of a literal int,

  • SF 5.2 RenameMethodRector renaming calls to \Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken::getProviderKey to getFirewallName (however there's no rector for e.g. deprecated getCredentials method of the same class),

  • SF 5.3 RenameMethodRector:

    • RequestStack::getMasterRequest() -> RequestStack::getMainRequest(),
  • SF 5.3 RenameClassConstFetchRector:

    • HttpKernelInterface::MASTER_REQUEST -> HttpKernelInterface::MAIN_REQUEST,
  • SF 5.3 RenameClassRector:

    • Symfony\Component\Security\Core\Exception\UsernameNotFoundException -> Symfony\Component\Security\Core\Exception\UserNotFoundException,
  • SF 5.4 AddReturnTypeDeclarationRector - adding return type ?\Symfony\Component\DependencyInjection\Extension\ExtensionInterface for classes implementing \Symfony\Component\HttpKernel\Bundle\BundleInterface::getContainerExtension() method

  • SF 6.0 AddReturnTypeDeclarationRector - adding return types added by Symfony in 6. It was mostly possible to do this on SF 5 for our extension points as those type didn't change, they were just hinted in PHPDoc. Still, required some manual fixes afterwards (see also a few points below - the ReturnTypeFrom*Rector remarks,

  • general code quality rector sets:

    • MakeCommandLazyRector - replacing setName() and setDescription() with $defaultName and $defaultDescription properties in Commands. Note that this rule however is deprecated, to be replaced with attributes in SF 6.1. For now this is just a "dead middle step" as Symfony itself states in the deprecation message,
    • LiteralGetToRequestClassConstantRector replacing 'GET' with Request::GET constant,
    • ResponseStatusCodeRector replacing e.g. 302 with Response::HTTP_FOUND constant in relavant places,
    • ReturnTypeFrom*Rector and AddReturnTypeDeclarationBasedOnParentClassMethodRector - a set of rectors applying return types based on either inferred method body or parent declaration, if feasible - this one has been proved to be quite risky as the returned type didn't always strictly follow what it should return.

CI Status

I've spent quite some time trying to rectify code duplication issues. Sadly this is not doable fully in a reasonable time as the entire codebase contains copy-pasted code since 2012. Since the Rector touched many places, all of them pop up now as new code, which makes quality gate fail. I have a set of changes fixing some of those WET code parts, however the scope of this PR is too big. I'll make follow ups.

For QA:

No QA needed. Regression tests should be enough.

Regression run: ibexa/commerce#930

Documentation:

This is code refactoring without behavior change. No documentation changes needed.

@alongosz alongosz force-pushed the ibx-8400-fix-redundant-repository-factory branch from e3e913f to 139b872 Compare June 18, 2024 12:52
Base automatically changed from ibx-8400-fix-redundant-repository-factory to main June 18, 2024 14:27
@alongosz alongosz force-pushed the ibx-8138-symfony-5-rule-sets branch from 876de38 to f6c613d Compare June 18, 2024 14:34
@alongosz alongosz marked this pull request as draft June 18, 2024 14:34
@alongosz alongosz force-pushed the ibx-8138-symfony-5-rule-sets branch 2 times, most recently from fb6aea3 to 2cd6d9b Compare June 21, 2024 12:36
@alongosz alongosz force-pushed the ibx-8138-symfony-5-rule-sets branch 5 times, most recently from 62ca525 to 9c0b13c Compare July 4, 2024 15:56
@alongosz alongosz force-pushed the ibx-8138-symfony-5-rule-sets branch 2 times, most recently from e347340 to 16e0239 Compare July 11, 2024 12:14
@alongosz alongosz force-pushed the ibx-8138-symfony-5-rule-sets branch 2 times, most recently from a7f52b2 to bb3fa84 Compare July 15, 2024 10:31
@alongosz alongosz marked this pull request as ready for review July 15, 2024 10:41
@alongosz alongosz force-pushed the ibx-8138-symfony-5-rule-sets branch from bb3fa84 to b42a789 Compare July 15, 2024 13:18
@alongosz alongosz force-pushed the ibx-8138-symfony-5-rule-sets branch from b42a789 to bcdc124 Compare July 15, 2024 13:24
@alongosz alongosz requested a review from a team July 16, 2024 14:51
Copy link
Member

@adamwojs adamwojs left a comment

Choose a reason for hiding this comment

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

Well done! 🚀

@adamwojs adamwojs requested a review from a team July 17, 2024 05:42
@konradoboza konradoboza requested a review from a team July 17, 2024 06:26
@alongosz alongosz force-pushed the ibx-8138-symfony-5-rule-sets branch from e2a12d6 to 0584976 Compare August 28, 2024 13:47
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
3.1% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@alongosz alongosz merged commit 7e4312d into main Aug 28, 2024
14 of 15 checks passed
@alongosz alongosz deleted the ibx-8138-symfony-5-rule-sets branch August 28, 2024 19:45
barw4 pushed a commit that referenced this pull request Oct 17, 2024
For more details see https://issues.ibexa.co/browse/IBX-8138 and #385

Key changes:

* [Rector] Applied Symfony 5.1 CommandConstantReturnCodeRector

* [Rector] Applied Symfony 5.2 RenameMethodRector

* [Rector] Applied Symfony 5.3 Rector sets

* [Rector] Applied Symfony code quality Rector sets

  Applied rules:
    * LiteralGetToRequestClassConstantRector
    * ResponseStatusCodeRector
    * MakeCommandLazyRector

* [Rector] Applied Return type rectors

  Applied rules:
    * ReturnTypeFromStrictNativeCallRector
    * ReturnTypeFromStrictScalarReturnExprRector

* [Rector] Applied Symfony 6.0 AddReturnTypeDeclarationRector

* [Rector] Added Symfony Bundle::getContainerExtension return type

* Added strict types for InstallPlatformCommand consts

* Made XML serialization exception more verbose in Author and DateTime converters

* Implemented `\Ibexa\Core\MVC\Symfony\Security\User::getUserIdentifier`

---------

Co-Authored-By: Paweł Niedzielski <[email protected]>
Co-Authored-By: Konrad Oboza <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants