Php-cs-fixer: Just one PHP file can't be fixed - every other file works fine

Created on 18 May 2018  路  3Comments  路  Source: FriendsOfPHP/PHP-CS-Fixer

Every PHP file in my project can be fixed, except the one below and I can't figure out why.

C:\Users\Sennewood\AppData\Roaming\Composer\vendor\bin>php-cs-fixer.bat fix --path-mode=intersection C:\Dev\XAMPP\htdocs\project\file.php --verbose --config=C:\Dev\XAMPP\htdocs\project\.php_cs
Loaded config default from "C:\Dev\XAMPP\htdocs\project\.php_cs".
Using cache file ".php_cs.cache".
F
Legend: ?-unknown, I-invalid file syntax, file ignored, S-Skipped, .-no changes, F-fixed, E-error
   1) C:\Dev\XAMPP\htdocs\project\file.php (no_trailing_whitespace, braces)

Fixed all files in 0.250 seconds, 8.000 MB memory used

The PHP version you are using ($ php -v):

=> 7.1.6 (via XAMPP, 32-bit)

PHP CS Fixer version you are using ($ php-cs-fixer -V):

=> PHP CS Fixer 2.11.1 Grey Devil

The command you use to run PHP CS Fixer:

=> php-cs-fixer.bat fix --path-mode=intersection C:Dev\XAMPP\htdocs\project\file.php --verbose --config=C:Dev\XAMPP\htdocs\project.php_cs

The configuration file you are using, if any:

return PhpCsFixer\Config::create()
    ->setLineEnding("\r\n")
    ->setRules([
        '@Symfony' => true,
        'array_indentation' => true,
        'array_syntax' => true,
        'braces' => ['position_after_functions_and_oop_constructs' => 'same'],
        'class_definition' => ['multiLineExtendsEachSingleLine' => false, 'singleItemSingleLine' => true, 'singleLine' => true],
        'combine_consecutive_issets' => true,
        'combine_consecutive_unsets' => true,
        'concat_space' => ['spacing' => 'none'],
        'declare_equal_normalize' => ['space' => 'single'],
        'increment_style' => false,
        'linebreak_after_opening_tag' => true,
        'method_argument_space' => ['ensure_fully_multiline' => true, 'keep_multiple_spaces_after_comma' => false],
        'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'],
        'no_alternative_syntax' => true,
        'no_blank_lines_after_class_opening' => false,
        'no_null_property_initialization' => true,
        'no_short_echo_tag' => true,
        'ordered_class_elements' => ['sortAlgorithm' => 'alpha'],
        'ordered_imports' => ['importsOrder' => null],
    ])
    ->setFinder(PhpCsFixer\Finder::create()
        ->exclude('vendor')
        ->in(__DIR__)
    )
;

If applicable, please provide minimum samples of PHP code (as plain text, not screenshots):

  • before running PHP CS Fixer (no changes):
<?php
class NavigationDropdown extends Navigation {

    private $elements;


        public function __construct($position, $text, $acl, $disabled) {
            $this->position = $position;
            $this->acl      = $acl;
            $this->disabled = $disabled;

            $this->text = $this->setText($text);
            $this->elements = array();
        }


    public function addElement($text, $acl, $module, $action) {
        $this->elements[$text] = array(
                                        "name" => $text,
                                        "text" => $this->setText($text),
                                        "acl" => $acl,
                                        "url" => $this->makeURL($module, $action),
                                        "module" => $module,
                                        "action" => $action);
    }

    public function getAllElements() {
        return $this->elements;
    }

    public function getElementName($element) {
        return $this->elements[$element]['name'];
    }

    public function getElementURL($element) {
        return $this->elements[$element]['url'];
    }

    public function getElementText($element) {
        return $this->elements[$element]['text'];
    }

    public function getElementACL($element) {
        return $this->elements[$element]['acl']
    }
}
kinquestion

All 3 comments

Hi and thanks for stopping by :)

In your sample:

    public function getElementACL($element) {
        return $this->elements[$element]['acl']
    }

there is a ; missing for the return statement. This makes the linter fail and as such the fixer will not attempted to fix it.
Let me know if this solves your issue.

picard_facepalm

That was the reason; thank you :)

you're welcome, happy to hear it is resolved :)
and happy to see Jean-Luc :D

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Bilge picture Bilge  路  3Comments

grachevko picture grachevko  路  3Comments

fisharebest picture fisharebest  路  3Comments

BackEndTea picture BackEndTea  路  3Comments

OskarStark picture OskarStark  路  3Comments