php-cs-fixer-ga icon indicating copy to clipboard operation
php-cs-fixer-ga copied to clipboard

Location of .php_cs

Open rognales opened this issue 4 years ago • 9 comments

Where should we put the config file?

I'm getting this error

/usr/bin/docker run --name oskarstarkphpcsfixerga_bd9dca --label c27d31 --workdir /github/workspace --rm -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/seedien/seedien":"/github/workspace" oskarstark/php-cs-fixer-ga
PHP CS Fixer 2.16.3 Yellow Bird by Fabien Potencier and Dariusz Ruminski (83baf82)
Loaded config default from "/github/workspace/.php_cs".

In MultiplePcreFilterIterator.php line 86:
                                                              
  preg_match() expects parameter 2 to be string, array given  

rognales avatar May 08 '20 20:05 rognales

Hi, please have a look at the second example in the README file. If this fixes your issue please don’t forget to come back an close this issue. Thanks.

OskarStark avatar May 09 '20 09:05 OskarStark

I have update the workflow to refer my config, as shown below:-

PHP CS Fixer 2.16.3 Yellow Bird by Fabien Potencier and Dariusz Ruminski (83baf82)
Loaded config default from ".php_cs".

But the error message remains:-

In MultiplePcreFilterIterator.php line 86:
                                                              
  preg_match() expects parameter 2 to be string, array given  

rognales avatar May 10 '20 16:05 rognales

Can you please post your config of PHP-CS-Fixer ?

OskarStark avatar May 10 '20 18:05 OskarStark

Here's mine.


<?php

use PhpCsFixer\Finder;
use PhpCsFixer\Config;

// Directories to exclude when fixing files.
$exclude = [
    'bootstrap/cache',
    'vendor',
    'storage',
    'node_modules',
    'nbproject',
];

// Filename patterns to exclude when fixing files.
$notName = [
    '*.md',
    '*.yml',
    '*.xml',
    '_ide_helper.php',
    '_ide_helper_models.php',
    '.phpstorm.meta.php'
];

// Default rules set to use when fixing files.
// See : https://gistlog.co/sixlive/2862a2185c76988838acaa45687a575c
$rules = [
    '@PSR2' => true,
    'array_indentation' => true,
    'array_syntax' => [
        'syntax' => 'short',
    ],
    'no_blank_lines_after_phpdoc' => true,
    'no_extra_blank_lines' => [
        'tokens' => ['curly_brace_block', 'extra', 'parenthesis_brace_block', 'square_brace_block', 'throw', 'use'],
    ],
    'no_multiline_whitespace_before_semicolons' => true,
    'no_short_echo_tag' => true,
    'no_unused_imports' => true,
    'no_useless_else' => true,
    'not_operator_with_successor_space' => true,
    'ordered_imports' => [
        'sortAlgorithm' => 'length',
    ],
    'phpdoc_add_missing_param_annotation' => true,
    'phpdoc_indent' => true,
    'phpdoc_no_package' => true,
    'phpdoc_order' => true,
    'phpdoc_separation' => true,
    'phpdoc_single_line_var_spacing' => true,
    'phpdoc_to_comment' => true,
    'phpdoc_trim' => true,
    'phpdoc_var_without_name' => true,
    'single_quote' => true,
    'ternary_operator_spaces' => true,
    'trailing_comma_in_multiline_array' => true,
    'trim_array_spaces' => true,
];

// Instantiate finder.
$finder = Finder::create()
    ->in(getcwd())
    ->exclude($exclude)
    ->name('*.php')
    ->notName($notName)
    ->ignoreDotFiles(true)
    ->ignoreVCS(true);

// Instantiate & return config.
return Config::create()
    ->setFinder($finder)
    ->setRules($rules);

rognales avatar May 12 '20 06:05 rognales

@OskarStark @rognales I have the same problem and the same configuration. Any ideas/updates on this?

emha avatar Sep 18 '20 19:09 emha

The problem seems to be the notName() function.

emha avatar Sep 18 '20 19:09 emha

I'm having the same problem. Running php-cs-fixer locally works as a charm (php 7.4) but in this container it fails with the preg_match error. You can reproduce this by cloning this repository: https://github.com/roy-bongers/certbot-transip-dns-01-validator and then running docker run --rm -it -w=/app -v ${PWD}:/app oskarstark/php-cs-fixer-ga:latest

The problem disappears when I comment out ->name(['auth-hook', 'cleanup-hook', '*.php'])

This is my config:

<?php

$finder = Symfony\Component\Finder\Finder::create()
    ->in(__DIR__)
    ->exclude(['config', 'docs', 'logs', 'vendor'])
    ->name(['auth-hook', 'cleanup-hook', '*.php'])
    ->ignoreDotFiles(true)
    ->ignoreVCS(true);

return PhpCsFixer\Config::create()
    ->setRules(
        [
            '@Symfony'                          => true,
            'array_syntax'                      => ['syntax' => 'short'],
            'no_unused_imports'                 => true,
            'trailing_comma_in_multiline_array' => true,
            'increment_style'                   => ['style' => 'post'],
            'concat_space'                      => ['spacing' => 'one'],
            'single_line_throw'                 => false,
        ]
    )->setFinder($finder);

Edit: I've fixed it by not using an array syntax for ->name() but calling ->name multiple times. I don't understand why but it fixes my problem. Array's should be supported though: https://symfony.com/doc/current/components/finder.html

Solution:

$finder = Finder::create()
    ->in(__DIR__)
    ->exclude(['config', 'docs', 'logs', 'vendor'])
    ->name('auth-hook')
    ->name('cleanup-hook')
    ->name('*.php')
    ->ignoreDotFiles(true)
    ->ignoreVCS(true);

roy-bongers avatar Dec 16 '20 22:12 roy-bongers

Hi, thanks for coming back, I am really not sure if this should be supported to PHP-Cs-Fixer team 🤔

@localheinz, do you have any clue?

OskarStark avatar Dec 17 '20 06:12 OskarStark

@OskarStark

No idea at the moment!

localheinz avatar Dec 17 '20 08:12 localheinz