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

Running php-cs-fixer fix removes traits from class #3

Closed
kg-bot opened this issue Mar 1, 2022 · 5 comments
Closed

Running php-cs-fixer fix removes traits from class #3

kg-bot opened this issue Mar 1, 2022 · 5 comments

Comments

@kg-bot
Copy link

kg-bot commented Mar 1, 2022

Describe the bug
Running php-cs-fixer fix command removes all traits from class

To Reproduce
Steps to reproduce the behavior:

  1. Go to any class
  2. Add some trait to class use SomeTrait
  3. Run php-cs-fixer fix
  4. Trait gets removed from class

Expected behavior
Running php-cs-fixer fix should not remove traits as this might introduce a lot of issues, especially if lots of files are changed and/or there are no test coverage

Additional context
I used trait in PHP8.1 Enumerations but I suspect this would be the case in any class and not only in enums

@Jubeki
Copy link
Owner

Jubeki commented Mar 1, 2022

I can't seem to reproduce this:
https://github.com/Jubeki/laravel-code-style-issue-3

Steps to run:

git clone git@github.com:Jubeki/laravel-code-style-issue-3.git
cd laravel-code-style-issue-3
composer update
vendor/bin/php-cs-fixer fix

The Files are:
app/Traits/EnumTrait and app/Enums/Status

Which version of PHP-CS-Fixer and Laravel-Code-Style are you using?
Can you provide me with a minimal example where it is not working as expected?

@Jubeki Jubeki added the needs more info Further information is requested label Mar 1, 2022
@kg-bot
Copy link
Author

kg-bot commented Mar 1, 2022

jubeki/laravel-code-style:1.0.0 and friendsofphp/php-cs-fixer:3.4.0

Example of code

<?php

namespace App\Enums;

use App\Models\Role;
use ArchTech\Enums\InvokableCases;

/**
 * @method int ASSIGNED_ONLY()
 * @method int OPEN()
 * @method int ALL()
 */
enum OrderAccessPermissionsEnum:int implements RolePermissionInterface
{
    case ASSIGNED_ONLY = 1;
    case OPEN = 2;
    case ALL = 3;

    use InvokableCases;

Trait is from this package archtechx/enums

@Jubeki
Copy link
Owner

Jubeki commented Mar 1, 2022

Please try to upgrade PHP-CS-Fixer. This seems to have been fixed in 3.5.0

EDIT:
Pull Request: PHP-CS-Fixer/PHP-CS-Fixer#6181
Issue: PHP-CS-Fixer/PHP-CS-Fixer#6178
Release: https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/tag/v3.5.0

@kg-bot
Copy link
Author

kg-bot commented Mar 1, 2022

Shouldn't that be changed in this package too?

@Jubeki
Copy link
Owner

Jubeki commented Mar 1, 2022

I don't really see a reason to change that in the composer.json:

  1. Take https://github.com/laravel/laravel/releases for example. They also only bump the version if necessary
  2. Every Time PHP-CS-Fixer is doing a release I would also need to do the same.
  3. composer update should still be able to update the underlying PHP-CS-Fixer Version. Because of the ^3.4.0 restraint.

So if you want a higher Requirement I recommend that you add a restraint to your own composer.json:

composer require friendsofphp/php-cs-fixer:^3.6.0 --dev

@Jubeki Jubeki closed this as completed Mar 1, 2022
@Jubeki Jubeki removed the needs more info Further information is requested label Mar 1, 2022
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

No branches or pull requests

2 participants