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

Abstract private methods not supported by OrderedClassElements Rule #6207

Closed
Zerdayne opened this issue Dec 23, 2021 · 1 comment · Fixed by #6209
Closed

Abstract private methods not supported by OrderedClassElements Rule #6207

Zerdayne opened this issue Dec 23, 2021 · 1 comment · Fixed by #6209

Comments

@Zerdayne
Copy link

Bug report

Hey, currently I'm starting to use php-cs-fixer. In one of my projects I'm using traits with an abstract private method.
Down below you can see that I'm using the current version of php-cs-fixer and PHP 8.0. Reading from the debug verbose, the array key "method_private_abstract" for the "order" option is not supported. I am not using this key in my config, but it reads the key from my code and doesn't know what to do with it.

I broke down the configuration and code snippet to the bare minimum. The given command output below is from the config I provide.

PHP Version

PHP 8.0.14 (cli) (built: Dec 20 2021 21:22:57) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.14, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.14, Copyright (c), by Zend Technologies

PHP CS Fixer Version

PHP CS Fixer 3.4.0 Si! by Fabien Potencier and Dariusz Ruminski

Output from the command "./vendor/bin/php-cs-fixer fix app/Traits/Test.php -vvv"

PHP CS Fixer 3.4.0 Si! by Fabien Potencier and Dariusz Ruminski
Runtime: PHP 8.0.14
Loaded config default from "/home/maik/PhpstormProjects/gift/.php-cs-fixer.dist.php".
Paths from configuration file have been overridden by paths provided as command arguments.
E                                                                                                                                                                                                                   1 / 1 (100%)
Legend: ?-unknown, I-invalid file syntax (file ignored), S-skipped (cached or empty file), .-no changes, F-fixed, E-error

Fixed all files in 0.002 seconds, 14.000 MB memory used

Files that were not fixed due to errors reported during fixing:
   1) /home/maik/PhpstormProjects/gift/app/Traits/Test.php

                                                       
        [ErrorException]                               
        Undefined array key "method_private_abstract"  
                                                       

      {closure}()
        in /home/maik/PhpstormProjects/gift/vendor/friendsofphp/php-cs-fixer/src/Fixer/ClassNotation/OrderedClassElementsFixer.php at line 484
      PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer->sortElements()
        in /home/maik/PhpstormProjects/gift/vendor/friendsofphp/php-cs-fixer/src/Fixer/ClassNotation/OrderedClassElementsFixer.php at line 247
      PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer->applyFix()
        in /home/maik/PhpstormProjects/gift/vendor/friendsofphp/php-cs-fixer/src/AbstractFixer.php at line 75
      PhpCsFixer\AbstractFixer->fix()
        in /home/maik/PhpstormProjects/gift/vendor/friendsofphp/php-cs-fixer/src/Runner/Runner.php at line 188
      PhpCsFixer\Runner\Runner->fixFile()
        in /home/maik/PhpstormProjects/gift/vendor/friendsofphp/php-cs-fixer/src/Runner/Runner.php at line 132
      PhpCsFixer\Runner\Runner->fix()
        in /home/maik/PhpstormProjects/gift/vendor/friendsofphp/php-cs-fixer/src/Console/Command/FixCommand.php at line 321
      PhpCsFixer\Console\Command\FixCommand->execute()
        in /home/maik/PhpstormProjects/gift/vendor/symfony/console/Command/Command.php at line 298
      [ ... ]

Used config file ".php-cs-fixer.dist.php"

<?php

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

function styles(Finder $finder, array $rules = []): Config
{
    $config = new Config();

    return $config
        ->setFinder($finder)
        ->setRiskyAllowed(true)
        ->setRules($rules);
}

$finder = Finder::create()
    ->in([
        __DIR__ . '/app',
        __DIR__ . '/config',
        __DIR__ . '/database',
        __DIR__ . '/routes',
        __DIR__ . '/tests',
    ]);


$rules = [
    'ordered_class_elements' => [
        'order' => [
            'use_trait',
            'constant_public',
            'constant_protected',
            'constant_private',
            'property_public',
            'property_protected',
            'property_private',
            'construct',
            'destruct',
            'magic',
            'phpunit',
            'method_public',
            'method_protected',
            'method_private',
        ],
        'sort_algorithm' => 'alpha',
    ],
];

return styles($finder, $rules);

Code snippet that reproduces the problem

<?php

namespace App\Traits;

trait Test
{
    abstract private function abstract();
}
@SpacePossum
Copy link
Contributor

Thanks for reporting @Zerdayne , I've made a PR as proposal to fix this issue 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants