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
there were many changes so the doc is a little bit stale in the end I needed to write down the matrix to get an overview again.
and the phpunit migrations I did with PHP-CS Fixer and it helped a lot.
Dariusz Rumiński
@keradus
nice folks!
Dariusz Rumiński
@keradus
https://twitter.com/keradus/status/1351012586595241987 ;)
2.18 with PHP8 support is out ;)
Caleb Mazalevskis
@Maikuolan
:+1:
CodingLukas
@CodingLukas
How to enable the PSR12 option from the ruleset?
image.png
Michael Bolli
@mbolli
Hey guys, is there a rule to convert $string = 'hello ' . $username . '!'; to $string = 'hello {$username}!'; ?

How to enable the PSR12 option from the ruleset?

@CodingLukas: Use your own .phpcs config file. I recommend https://mlocati.github.io/php-cs-fixer-configurator/ for creating yours.

Dariusz Rumiński
@keradus
PSR-12 appendix:
  • file is .php_cs (extra _)
  • after having your project config file (which is best practice, as can be distributed together with the code), change PHPStorm to Custom
  • why PSR12 not available in PHPStorm? ask IntelliJ, looks like they have hardcoded rulesets rather than taking it from the app
concatenation vs interpolation rule
  • @mbolli , there is no rule like that existing currently, but do not hesitate to raise a PR with it! ;)
Dave van der Brugge
@dmvdbrugge
I think there's only "hello $username" to "hello ${username}" and then a second fixer to "hello {$username}"
Michael Bolli
@mbolli
yep I saw these and have them activated. ok I'll raise a PR when I get the time :) thanks
Julius Peinelt
@jpeinelt
Thanks for all the work for v2.18!! For my php8.0 the nullsafe-operator gets deleted though: $attachment?->hash is fixed to $attachmenthash. Any rule that I have to activate? couldn't find it in the docs...
Kuba Werłos
@kubawerlos
Hi @jpeinelt can you report an issue with more details such as configuration you are using and output from PHP CS Fixer run (with -v flag)?
Julius Peinelt
@jpeinelt
Hi, @kubawerlos. Sure, I'll report an issue, thanks!
Michael Bolli
@mbolli
Hey guys, another question:
Is there a rule to fix "double-nullable" function parameters?
E.g. fix public function (A $a, ?B $b = null) to public function (A $a, ?B $b)
Michael Bolli
@mbolli
Oh I missed something. Nullable != Optional...
Jochem Klaver
@7ochem
Hi guys, quick question: Does php-cs-fixer have a Github Actions ::error output mode/flag? So that Github can report issues on the files/lines within the PR files view? Just like the psalm --output-format=github option
Dariusz Rumiński
@keradus
currently, there is no support for github report format. would you like to help and work on it, @7ochem ?
Jochem Klaver
@7ochem
Sure, I could give it a try :D
Jochem Klaver
@7ochem
@keradus I created an issue for this to explain it a bit and discuss my plan: FriendsOfPHP/PHP-CS-Fixer#5482
Dariusz Rumiński
@keradus
thanks ;)
Illia Sakovich
@hivokas

Morning!
Is there a php-cs-fixer rule to update this

$a = [
    'foo'           => 12,
    'baaaaaaaaaaar' => 13,
];

to this

$a = [
    'foo' => 12,
    'baaaaaaaaaaar' => 13,
];

?

Dariusz Rumiński
@keradus
binary_operator_spaces rule:
 * Example #6. Fixing with configuration: ['operators' => ['=>' => 'single_space']].
   ---------- begin diff ----------
   --- Original
   +++ New
   @@ -1,5 +1,5 @@
    <?php
    $array = [
   -    "foo"            =>   1,
   -    "baaaaaaaaaaar"  =>  11,
   +    "foo" => 1,
   +    "baaaaaaaaaaar" => 11,
    ];

   ----------- end diff -----------
codigoergosum
@codigoergosum

After a fix removing an unnecessary else, the indentation is not corrected after the curlies are removed.

if ($something)
    return;
else {
    $something = 1;
    $somethingElse = 2;
}

--- becomes ---
if ($something)
{
    return;
}
    $something = 1;
    $somethingElse = 2;

I think this might be due to a feature intended to preserve deep indenting of multi-line end-of-line comments. But it's forcing manual intervention in what would other wise be beautiful automatic cleanups. Any chance there's a configuration we change to get it right?

return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'@PhpCsFixer' => true,
'braces' => ['position_after_control_structures' => 'next'],
'concat_space' => ['spacing' => 'one'],
'yoda_style' => ['equal' => null, 'identical' => null],
'blank_line_before_statement' => false,
'ordered_class_elements' => ['order' => []],
'no_unneeded_curly_braces' => false,
// We don't want to turn off this elseif flag, as that will
// change else if {} to else { if {}}.
// 'elseif' => false,
'phpdoc_align' => ['align' => 'left'],
])
;

Dariusz Rumiński
@keradus
try again with braces => true, would the result be the same?
codigoergosum
@codigoergosum

With that change the result is the same. But. I think I left out something important. This code is at file scope. It's contained in <?php, but there are no curly braces around it. Makes it seem sort of unfair to expect a braces rule to do anything about it! It's too bad no_useless_else doesn't clean up after itself; but except in this case, that's a perfectly reasonable choice.

In short, I think this is just FriendsOfPHP/PHP-CS-Fixer#3082 .

Thanks for your response; sorry I didn't fully understand the problem from the start.

Dariusz Rumiński
@keradus
@codigoergosum , I see!
for the non-braces file, maybe you can give it a try and raise a PR to improve that? ;)
about "cleaning up after itself" - we would need to ask each fixer to apply some non-rule related changes around too, calling repeating responsibility of other rules, but in limited code scope. TL;DR - we expect one to run full rule-set rather than single rule
thavarajansmi
@thavarajansmi
hi all
have a doubt
i have the following code
thavarajansmi
@thavarajansmi
class ContractTemplateDocModel extends CoreModel
{
    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = false;

if i change bool to boolean for a squiz rule Squiz.Commenting.VariableComment.IncorrectVarType, php-csfixer automatically change the type from boolean to bool

is there a way to keep bool as boolean and int as integer

Dave van der Brugge
@dmvdbrugge
This is done by the phpdoc_scalar rule which you can either not enable, disable, or configure specifically. See https://mlocati.github.io/php-cs-fixer-configurator/#version:2.18|fixer:phpdoc_scalar
I don't think there's a rule that automatically fixes it your way around.
Dariusz Rumiński
@keradus
@thavarajansmi , consider using bool. We don't have the choice, as bool is valid PHP internal primitive type, while boolean is not - https://3v4l.org/9JsVS
thavarajansmi
@thavarajansmi

This is done by the phpdoc_scalar rule which you can either not enable, disable, or configure specifically. See https://mlocati.github.io/php-cs-fixer-configurator/#version:2.18|fixer:phpdoc_scalar

Thanks for the wonderful information,

Anton
@WinterSilence

Hi! I'm looking for fixer combines&sanitizes any inline comments between methods in docBlock.
before:

class Foo
{
    public function getLine()
    {
    }

    /*******************************/
    /* ugly comment to __toString  */
    /* multiline!                  */
    /*******************************/

    public function __toString()
    {
        return '';
    }
}

after:

class Foo
{
    public function getLine()
    {
    }

    /**
     * ugly comment to __toString multiline!
     */
    public function __toString()
    {
        return '';
    }
}
Do you have similar fixers?
Ruud Kamphuis
@ruudk

Hi all! I'm looking for a fixer that can do

if (!$value) => if ($value === false)

Does this exist?

Kuba Werłos
@kubawerlos
@WinterSilence there is only fixer to shrink multiple asterisks down to /** and **/
@ruudk there is no such fixer and I doubt will ever be - what is wrong with !$value?
Dave van der Brugge
@dmvdbrugge
To add, it's not even the correct replacement, as semantically it's if ((bool)$value === false) which is only the same when you know for sure $value is a bool to begin with. As PHP-CS-Fixer cannot know that, if there were such a rule, it had to be "Risky" too because it actually changes behaviour, and I doubt people would even want to run that rule. (You are of course free to implement the rule yourself and use it in your own config.)
Marco De Mori
@mdemori
Hi, How can I change the line lenght limit? seem that currently is set as "85 char" can I extend to 120 ? i use PhpStorm as IDE if is relevant..
Dariusz Rumiński
@keradus
@mdemori , it's not configuration of PHP CS Fixer. look for this configuration in your IDE or other tools you are using in your project
Glen Solsberry
@gms8994
Wasn't there, at one point, a cs-fixer rule that would pull fully qualified class names up to the use block at the top?
Dave van der Brugge
@dmvdbrugge
fully_qualified_strict_types seems to do so, however it only works for parameter and return types, not all usages.
Kamil Tekiela
@kamil-tekiela
I am using CS fixer 2.18.2 but it throws an error on constructor property promotion. What can I do to fix it?