Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jul 10 2018 21:39
    @SpacePossum banned @jewome62_gitlab
sacru2red
@sacru2red

hi,I have a question
to config function_declaration option
https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/doc/rules/function_notation/function_declaration.rst

this option allowed values: 'none', 'one'
so try this like

php ./vendor/bin/php-cs-fixer fix ./fileupload/test.php --diff --rules='{"function_declaration":{"closure_function_spacing":"none"}}' -vv --dry-run
php ./vendor/bin/php-cs-fixer fix ./fileupload/test.php --diff --rules='{"function_declaration":{"closure_function_spacing":"one"}}' -vv --dry-run

but same result like
-function someEx ($someParam) {
+function someEx($someParam) {

I want to have a space in function_declaration
how to do that?

bobbrom
@bobbrom
Hey does anyone know how to deal with Swagger Annotation with PHP-CS-Fixer
It seems to always revert it back to a normal phpdoc
16 replies
Alejandro D. Guevara
@AleDavidGueva_twitter

Hi. I have a question.
Is there a rule that allows me to remove the space between not-operator and var?
For example,
|- if (! $var) {}
|+ if (!$var) {}

I found rules for add spacing but not for remove. Its posible create a custom rules?
Thanks.

3 replies
sacru2red
@sacru2red
somebody help me..
2 replies
Ravi Bastola
@ravisharmaa
My tests method names are changed to camelCases, and I was trying to avoid them. I am using this rules set can anybody help me to correct this ruleset to disallow php-cs-fixer to change the case of the method names?
--rules=@Symfony,-@PSR1,-blank_line_before_statement,php_unit_method_casing --verbose fix $FileDir$/$FileName$
1 reply
Lars Willighagen
@larsgw
Hi, we just upgraded to v3 and I am encountering some issues with a <?= ?> part with a multiline function call. The indentation of the code is changed somewhat inconsistently.
5 replies
Bob van de Vijver
@bobvandevijver

I'm looking at the changeset generated by this tool and wonder whether certain formatting options related to assignment alignment from PHPStorm are available as well:

     $this->state->pConnection = DriverManager::getConnection([
-        'url'           => $connectionString,
-        'password'      => $password,
+        'url' => $connectionString,
+        'password' => $password,
         'driverOptions' => $driverOptions,
-        'charset'       => 'UTF8',
+        'charset' => 'UTF8',
     ], $configuration);

As you can see the original alignment has been removed, while that one improves readability in my opinion. Is there any way to achieve the same result with php-cs-fixer without implementing a custom rule?

2 replies
Karel
@karelkangro
hi, how I can set no white space before the opening parentheses in statements like if() foreach() etc, currently it looks like default is to use space there like if ()
1 reply
cctgteddy
@cctgteddy
Hi, is it possible for me to specifically whitelist a pattern of files to apply? I'm adding a new large module to a legacy project and at this time I'd like to just apply php-cs-fixer to it.
webbgroup
@webbgroup
hey all. Is there a way to enforce camelCase or snake_case?
In the code I see this
doc/rules/index.rst: Enforce camel (or snake) case for PHPUnit test methods, following configuration. phpmd.xml: <rule ref="rulesets/controversial.xml/CamelCaseClassName" /> phpmd.xml: <rule ref="rulesets/controversial.xml/CamelCaseMethodName" /> phpmd.xml: <rule ref="rulesets/controversial.xml/CamelCaseParameterName" /> phpmd.xml: <rule ref="rulesets/controversial.xml/CamelCasePropertyName" /> phpmd.xml: <rule ref="rulesets/controversial.xml/CamelCaseVariableName" />
But there aren't any rules in any rulesets that I am using PSR12 . Even PSR12-risky doesn't seem to have it

```PHP Warning: Module 'ast' already loaded in Unknown on line 0
Description of the @PSR12:risky set.
Rules that follow PSR-12 (https://www.php-fig.org/psr/psr-12/) standard.
This set contains risky rules.

  • no_trailing_whitespace_in_string risky
    | There must be no trailing whitespace in strings.

  • no_unreachable_default_argument_value risky
    | In function arguments there must not be arguments with default values before non-default ones.
    ```

SpacePossum
@SpacePossum
Hi and thanks for your question. I think you might be mixing tooling here as the example configuration is for phpmd, which is a tool I use in a lot projects, however it is not this tool : ) Currently we don't have a rule to enforce the naming of variables, methods, functions, classes, etc. into camel/pascal/snake/etc casing , and we'll likely not have any time soon. The tool is a "fixer" and not a "sniffer" and is also not a "refactor" tool, this is by design/concept/scope, but also the way it is build we cannot safely (or low-risky) do such refactoring at the moment.
TLDR: we don't have such rules because of the scope and design of the tool
webbgroup
@webbgroup
So @SpacePossum so is the current model is to use phpunit to test for features like this now then?
1 reply
William
@wevns
Hi, I'm writing my own fixer. I came across this issue which has been open for three and a half years asking for a fixer (FriendsOfPHP/PHP-CS-Fixer#3855) and I was wondering if pull requests to add new a new fixer like the one requested in the issue would be accepted? Thank you! 😀
2 replies
MJ
@Lowkey2224
Is there any proper way to maintain a set of Rules that me and my team aggreed on, somewhere centralized so that all Projects have these rules by default? Or do I have to set this up manually on every project?
1 reply
Sebastian Neubert
@sebastianneubert

hey, I'm currently chasing a bug in php-cs-fixer

I have following config excluding a file with a syntax error:

$finder = PhpCsFixer\Finder::create()
    ->exclude(__DIR__ . '/tests/data/Invalid.php')
    ->in(__DIR__ . '/src')
    ->in(__DIR__ . '/tests')
    ->append([__FILE__]);

$config = new PhpCsFixer\Config();
return $config->setRules([
    '@PSR12' => true,
    'array_syntax' => ['syntax' => 'short'],
])->setFinder($finder);

but I get an error that the excluded file have invalid syntax (which is on purpose)

do I use the $finder in a wrong way or is it currently not possible to ignore/exclude invalid syntax files?

SpacePossum
@SpacePossum
hi! I think exclude is only for directories, you can try ->notName , the docs for Symfony Finder are here https://symfony.com/doc/current/components/finder.html with examples
Sebastian Neubert
@sebastianneubert
thank you for the reply. Indeed this was a syntax misunderstanding from my side. I could fix that by this configuration.
$finder = PhpCsFixer\Finder::create()
    ->in(__DIR__ . '/src')
    ->in(__DIR__ . '/tests')->notPath('data/Invalid.php')
    ->append([__FILE__]);
Mewes Kochheim
@MewesK
Hi guys. Is there an official way to write custom formatters for PHP CS Fixer? I need support for the generic sonarqube format. Couldn't find custom formatters mentioned in the docs.
Dariusz RumiƄski
@keradus
We dont have custom formatter support now. Is sonarcube format spec well defined ? I would be happy to accept PR to add it to main repo. Also, maybe SonarCube supports checkstyle format? We have that one in place
nwehrhan
@nwehrhan

I want to format

        if (true) {
            return true;
        }
        if (false) {
            return false;
        }

to

        if (true) {
            return true;
        }

        if (false) {
            return false;
        }
3 replies
With blank lines between the if statements but can't find the rule. Can anyone help me out?
nwehrhan
@nwehrhan
Whats the cache doing? I don't see docs on .php_cs.cache
SpacePossum
@SpacePossum
some more background from the docs here
https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v3.6.0/doc/usage.rst#caching
there is more if search the doc for --using-cache
the cache is made based on the version of the tool you use, the configuration you use and if the files your are fixing have changed
it speeds up the process a lot if you run it in let say a CI step or something like that
I would advice to (keep) use it and to git-ignore the the cache file
sandermarechal
@sandermarechal:matrix.org
[m]
Hello. Is there a fixer that converts deep a FQCN like \Foo\Bar\Baz to a short version + a use statement? I can't seem to find any. The GlobalNamespaceImportFixer only does it for global classes. Thanks in advance!
Near
@nateriver74

Hello, is there any sniff out there that enforces a space between inline comments
Correct:

// mycomment

wrong

//mycomment
SpacePossum
@SpacePossum
5 replies
Near
@nateriver74

Hello!
There will be some rule to order the "echo" and "print" function, in such a way that it is on the same line and with a single white space.

Correct:
echo "Hello world!";

Wrong:
echo ``` "Hello
world!";

Beforehand thank you very much!

@codejack
@kondasMajid
Hello guys i need help to fix this, https://stackoverflow.com/q/71601840/18290176
1 reply
Max Ageev
@Legion112
1 reply
Dariusz RumiƄski
@keradus
Sounds great, would you like to raise a PR with proposed implementation ?
Alexander
@nyatMeat

Hi guys! I have 2.9.13 version, and I'm looking for the rule to delete empty line before the break statement?

                );

                break;

            case 1:

to

                );
                break;

            case 1:

I've used couple of rules blank_line_before_statement and no_extra_blank_lines
but they are not working

My rule config
        '@PHP74Migration' => true,
        '@PHP74Migration:risky' => false,
        '@PHPUnit84Migration:risky' => false,
        '@PSR12' => true,
        '@PhpCsFixer' => true,
        'function_declaration' => ['closure_function_spacing' => 'none'],
        'blank_line_after_namespace' => true,
        'class_attributes_separation' => [
            'elements' => [
                'const' => 'one',
                'method' => 'one',
                'property' => 'one',
            ],
        ],
        'declare_strict_types' => true,
        'trailing_comma_in_multiline' => ['elements' => ['arguments', 'arrays']],
        'increment_style' => ['style' => 'post'],
        'binary_operator_spaces' => ['align_double_arrow' => false],
        'phpdoc_align' => ['align' => 'left'],
        'trim_array_spaces' => true,
        'no_trailing_comma_in_singleline_array' => true,
        'ordered_class_elements' => [
            'use_trait',
            'constant_public',
            'constant_protected',
            'constant_private',
            'property_public',
            'property_protected',
            'property_private',
            'construct',
            'destruct',
            'phpunit',
            'magic',
            'method_public',
            'method_protected',
            'method_private',
        ],
        'general_phpdoc_annotation_remove' => ['annotations' => ['expectedDeprecation']],
        'concat_space' => ['spacing' => 'one'],
        'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'],
        'whitespace_after_comma_in_array' => true,
        'cast_spaces' => true,
        'yoda_style' => false,
What rules can I use to achieve codestyle I need?
1 reply
SpacePossum
@SpacePossum
use blank_line_before_statement with config ['statements' => ['break']] , you can see it if you do php-cs-fixer describe blank_line_before_statement,
in PHP config it is like:
'blank_line_before_statement' => ['statements' => ['break']],
2 replies
sgfgdf
@sgfgdf_twitter
hi, guys! is there a way to use php-cs-fixer to generate report with the found issues and their respective line numbers? i found this issue FriendsOfPHP/PHP-CS-Fixer#3601, but did not found any working solution there. are there any intentions to support such feature or not?
1 reply
Sergey Fomin
@mpakfm

Hi, maybe anyone had a problem with binary_operator_spaces. Yesterday it broke. I don`t know why.
I have this config:

'binary_operator_spaces' => [
                'description' => 'Binary operators should be surrounded by space as configured',
                'config'      => [
                    'default'   => null,
                    'operators' => [
                        '=>'  => 'align_single_space',
                        '='     => 'align_single_space',
                        '&='  => 'align_single_space',

And before broke this code was error:

            $aSort = $a['SORT'] ?? null;
            $bSort = $b['SORT'] ?? null;
            $aID = $a['LESSON_ID'] ?? null;
            $bID = $b['LESSON_ID'] ?? null;
            $aSort = TypeCaster::int($aSort);
            $bSort = TypeCaster::int($bSort);
            $aID = TypeCaster::int($aID);
            $bID = TypeCaster::int($bID);

But now PhpCsFixer does not see mistaken formatting

Sergey Fomin
@mpakfm
image.png
Mike Street
@mikestreety

(Sorry if I missed some sort of search and this has been asked before...)

Is there a way of forcing the semi-colon on a new line in a multi-line statement?

E.g.

$this
    ->methodOne()
    ->methodTwo();

Becomes

$this
    ->methodOne()
    ->methodTwo()
;
Thanks anyway!
1 reply
Sergey Fomin
@mpakfm
Update for my message:
I trying and testing this file: vendor/friendsofphp/php-cs-fixer/src/Fixer/Operator/BinaryOperatorSpacesFixer.php
Fixer can not working with lambda functions:
image.png