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
Alexandr
@goodjinny
How to achieve a replacement of the fully-qualified namespace with an import?
image.png
Is any rule makes that?
Dave van der Brugge
@dmvdbrugge
@goodjinny fully_qualified_strict_types
Alexandr
@goodjinny
@dmvdbrugge Thank you!
3 replies
Paul Atkins
@PaulAtkins88
Hey everyone, this may be a obvious question, but I cannot find anywhere in the php-cs-fixer options (I am in VS Code) a way to set character line limit?
Julien Falque
@julienfalque
@PaulAtkins88 PHP CS Fixer does not have a rule to limit line length.
1 reply
Dariusz Rumiński
@keradus
Markus Podar
@mfn

Already testing it :)

I've a looooooong list of rules: is there a way to see which rule(s) applied in a certain situation? To ease drilling down, figuring from where a possible incorrect change might come from?

1 reply
Caleb Mazalevskis
@Maikuolan
I have some PHP classes, which have version constraints of PHP >= 5.4, and under PHP CS Fixer 3.0.0-beta.1, said classes are being flagged by the visibility_required rule, due to some defined constants in those classes. Under PHP CS Fixer 2.18.4 and earlier, said classes weren't being flagged (exact same code, just different PHP CS Fixer versions). I had believed that the visibility requirements were part of PSR-12, but the rules I'm using with PHP CS Fixer are PSR-2. Maybe I got something wrong there? I'm not sure. Anyway, since constant visibility wasn't implemented into PHP until 7.1, and said classes have constraints of PHP >= 5.4, declaring visibility there would be a breaking change to those classes (because increasing the minimum required PHP version). Any suggestions for how I should proceed? e.g., create a new issue about it at the PHP CS Fixer issue tracker on GitHub, or, don't worry about creating an issue, instead, just disabling that particular rule when running PHP CS Fixer, or, something else? Cheers.
Kuba Werłos
@kubawerlos
@Maikuolan this is because the default for visibility_required fixed had changed in 3.0 and config for PSR2 uses default value, I've made a fix: FriendsOfPHP/PHP-CS-Fixer#5560 - make a review if you can
Caleb Mazalevskis
@Maikuolan
@kubawerlos Cheers. I'll review it now. :-) :+1:
Supun Budhajeewa
@budhajeewa_twitter

Hey,

Is there a rule to format the following:

$object->chainedMethod1()->chainedMethodN();

As follows:

$object
    ->chainedMethod1()
    ->chainedMethodN()
;
2 replies
Tom Klingenberg
@ktomk
just for the enjoyment: include(/dev/null): failed to open stream: Success
Eduar Bastidas
@MrEduar
Hi guys! A question for you, is there a rule to change the EOL of the files automatically?
Eduar Bastidas
@MrEduar
Thanks @julienfalque. I will look into it.
Eduar Bastidas
@MrEduar
Works perfect!
I'm looking for a last rule but I can't get it.
I would like the returns to have a blank line before it. Is there a rule for that?
Eduar Bastidas
@MrEduar
I got it, thank you very much :)
Miguel Couto
@Mig1st4ck
Hi i am trying this tool, and it looks great.
Is there any way to remove "header_comment"
1 reply
Pavel Bezdverniy
@Ferikl
Hey guys, can I somehow create a rule to handle this case: I have multiple classes with myFunc() function and I want to have this function very first in every class
4 replies
Tac Tacelosky
@tacman
Kudos on the near-release of 3.0
Is there a rule that removes the blank space(s) before the class definition and functions that are in a file without a class? PhpStorm does this when reformatting, but I can't find a rule in cs-fixer that does this.
Tac Tacelosky
@tacman
             class x { 
                   }
to
class x
{
}
1 reply
Jeroen Keppens
@amazium
Quick question: is it only possible to use php cs fixer from the command line, or can it also be used as a library to format a string containing php? For a tool I am building, I am generating code and I would like to run php cs fixer on the generated code directly (so call a function to format a string containing the contents of a php file, rather then using the command line to process a file). I might have missed something, but I got the feeling it is not doable or at least not in an easy way?
2 replies
zephirfan
@zephirfan
What to do with the deprecation message "- A list of elements is deprecated, use a dictionary of const|method|property => none|one instead."?
3 replies
Vikram Bhaskaran
@vbasky
What is the replacement for Config::create() in 3.0 ?
6 replies
Mark Roeling
@mroeling
Hi, since I couldn't find it online: is there already a rule for https://wiki.php.net/rfc/trailing_comma_in_parameter_list ?
Julien Falque
@julienfalque
1 reply
Tom Klingenberg
@ktomk
is it by intention that the indentation_type fixer does not fix mixed indents? I'm on ^3.0 and despite fix running through the project still has space before tab in indent within PHP files.
@PSR12 is the first rule in the config. Tested also isolated, gives the same.
This message was deleted
Tom Klingenberg
@ktomk
I may be hunting ghosts with the indents, as those are within multiline strings as I now see.
Which then is somewhat correct from php-cs-fixer perspective.
Jack Tran
@jackgusrix

Hi, I have problem when run php-cs-fixer with config file
PHP Fatal error: Uncaught Error: Call to undefined method PhpCsFixer\Config::create() in /Users/dinhchuongtran/Documents/Sources/Php/configPhpFixer/.phpcsfixer:17
Stack trace:

#0 /Users/dinhchuongtran/.composer/vendor/friendsofphp/php-cs-fixer/src/Console/ConfigurationResolver.php(836): include()

#1 /Users/dinhchuongtran/.composer/vendor/friendsofphp/php-cs-fixer/src/Console/ConfigurationResolver.php(229): PhpCsFixer\Console\ConfigurationResolver::separatedContextLessInclude('/Users/dinhchuo...')

#2 /Users/dinhchuongtran/.composer/vendor/friendsofphp/php-cs-fixer/src/Console/ConfigurationResolver.php(561): PhpCsFixer\Console\ConfigurationResolver->getConfig()

#3 /Users/dinhchuongtran/.composer/vendor/friendsofphp/php-cs-fixer/src/Console/ConfigurationResolver.php(406): PhpCsFixer\Console\ConfigurationResolver->getFormat()

#4 /Users/dinhchuongtran/.composer/vendor/friendsofphp/php-cs-fixer/src/Console/Command/FixCommand.php(258): PhpCsFixer\Console\ConfigurationResolver->getReporter()

#5 /Users/dinhchuongtran/.composer/vendor/ in /Users/dinhchuongtran/Documents/Sources/Php/configPhpFixer/.phpcsfixer on line 17

Fatal error: Uncaught Error: Call to undefined method PhpCsFixer\Config::create() in /Users/dinhchuongtran/Documents/Sources/Php/configPhpFixer/.phpcsfixer:17

please help
2 replies
Tomás Soler
@TJSoler
Hi all,
According to the readme, the recommended way to install php-cs-fixer is in a dedicated composer in a subfolder, that being the case, I guess the vendor in the subfolder also needs to be ignored, and then, every time the project get's installed, needs to not only do the general composer install, but also the composer install of the subfolder?
3 replies
King MSM
@phpboah:matrix.org
[m]
Hello. Can anyone tell me how do i use the list-files command in the CLI. I just want to view the list of files that need fixing with just one single rule.
1 reply
I tried doing php vendor/bin/php-cs-fixer list-files --rules=unused_imports src but it doesn't work.
Fred McClurg
@fredmcclurg_gitlab

Is there any way to convert a numerically (integer) indexed associative array to a comma delimited value array?

For example, my current code looks like this:

'menu' => [
    0 => [
        'caption' => 'Assessor\'s Duties',
        'url' => 'assessorsDuties.php',
    ],
    1 => [
        'caption' => 'Reducing Tax Liability',
        'url' => 'reducingTaxLiability.php',
    ],
    ...

And I would like to convert it into the following:

'menu' => [
    [
        'caption' => 'Assessor\'s Duties',
        'url' => 'assessorsDuties.php',
    ],
    [
        'caption' => 'Reducing Tax Liability',
        'url' => 'reducingTaxLiability.php',
    ],
    ...

If a built-in rule does not exist, how difficult would it be for a savvy developer to implement this? If this is not already an existing rule, please add this to your request queue.

Sincere thanks!

1 reply
Kirill Dakhnyuk
@KirillDakhnyuk
image.png
Hello! Can someone share new config file? Php cs fixer installed globally and previous I create config via Config::create, how can I call constructor now?
4 replies
Kirill Dakhnyuk
@KirillDakhnyuk
image.png
Fung Tsz Yin
@RayFungHK
image.png
Seem the config file is correct but I can't use the custom ruleset in PHPStorm (v3.0)
1 reply
Dariusz Rumiński
@keradus
This message was deleted
SirRFI
@SirRFI

Hello. I need help adjusting my config - the following needs to be fixed:

  • In multiline methods (because they don't fit in 120 characters), opening brace { is moved to the same line as return type (got: }: returnType, expected }: returnType\n{
  • Keywords catch, finally and else are moved to closing bracket (}) line (got: } else {, expected: }\nelse {)
  • Keyword elseif is not split onto else if
  • else if is changed to nested if else { if (...) { ... } }
  • Some /** comments (PHPDoc?) are changed to regular comments (//) or multi-line comments (/*)

The config file:

<?php

declare(strict_types=1);

/*
 * This document has been generated with
 * https://mlocati.github.io/php-cs-fixer-configurator/#version:3.0.0-rc.1|configurator
 * you can change this configuration by importing this file.
 */
$config = new PhpCsFixer\Config();
return $config
    ->setRiskyAllowed(true)
    ->setRules([
        '@PHP80Migration' => true,
        '@PHP80Migration:risky' => true,
        '@PSR1' => true,
        '@PSR2' => true,
        '@PhpCsFixer:risky' => true,
        '@PhpCsFixer' => true,
        'cast_spaces' => ['space'=>'none'],
        'date_time_immutable' => true,
        'elseif' => false,
        'final_class' => true,
        'final_public_method_for_abstract_class' => true,
        'global_namespace_import' => ['import_classes'=>true],
        'increment_style' => false,
        'mb_str_functions' => true,
        'multiline_whitespace_before_semicolons' => ['strategy'=>'new_line_for_chained_calls'],
        'native_function_invocation' => false,
        'no_break_comment' => false,
        'nullable_type_declaration_for_default_null_value' => true,
        'php_unit_dedicate_assert' => true,
        'php_unit_dedicate_assert_internal_type' => true,
        'php_unit_expectation' => true,
        'php_unit_internal_class' => false,
        'php_unit_namespaced' => true,
        'php_unit_no_expectation_annotation' => true,
        'php_unit_test_class_requires_covers' => false,
        'phpdoc_add_missing_param_annotation' => false,
        'phpdoc_align' => ['align'=>'left'],
        'yoda_style' => false,
    ])
    ->setFinder(PhpCsFixer\Finder::create()
        ->exclude('vendor')
        ->in(__DIR__)
    )
    ->setCacheFile(__DIR__.'/var/.php-cs-fixer.cache')
;
SpacePossum
@SpacePossum
hi there!

In multiline methods (because they don't fit in 120 characters), opening brace { is moved to the same line as return type (got: }: returnType, expected }: returnType\n{
this is not supported, you can disable the rule braces to stop the fixing: 'braces' => false

Keywords catch, finally and else are moved to closing bracket (}) line (got: } else {, expected: }\nelse {)
this is not supported

Keyword elseif is not split onto else if
you can disable the rule; 'elseif' => false to stop this from happening

else if is changed to nested if else { if (...) { ... } }
this is not supported

Some /** comments (PHPDoc?) are changed to regular comments (//) or multi-line comments (/*)
you can disable the rule; 'phpdoc_to_comment' => false to stop this from happening

SirRFI
@SirRFI

you can disable the rule; 'elseif' => false to stop this from happening
It's already disabled. I expect elseif to be split, not merged.

Turning off braces indeed solved some of these, at a price though. I am surprised these two are not supported.

Thanks

1 reply
Chanaka Abeysinghe
@chanakasan
hi !,
Does php-cs-fixer detect things like missing imports for classes?
1 reply