Skip to content

Fix coding style missed by phpbcf#2875

Closed
jtojnar wants to merge 1 commit intoRSS-Bridge:masterfrom
jtojnar:stragglers
Closed

Fix coding style missed by phpbcf#2875
jtojnar wants to merge 1 commit intoRSS-Bridge:masterfrom
jtojnar:stragglers

Conversation

@jtojnar
Copy link
Contributor

@jtojnar jtojnar commented Jul 1, 2022

$ composer require --dev friendsofphp/php-cs-fixer

$ echo >.php-cs-fixer.dist.php "<?php

$finder = PhpCsFixer\Finder::create()
    ->exclude('squizlabsD')
    ->in(__DIR__);

$rules = [
    '@PSR12' => true,
    '@PSR12:risky' => true,
    '@PHP74Migration' => true,
    '@PHP74Migration:risky' => true,
    // buggy, duplicates existing comment sometimes
    'no_break_comment' => false,
    'array_syntax' => true,
    'binary_operator_spaces' => true,
    'lowercase_static_reference' => true,
    'visibility_required' => false,
];

$config = new PhpCsFixer\Config();

return $config
    ->setRules($rules)
    ->setRiskyAllowed(true)
    ->setFinder($finder);
"

$ vendor/bin/php-cs-fixer --version
PHP CS Fixer 3.8.0 BerSzcz against war! by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 7.4.30

$ vendor/bin/php-cs-fixer fix

$ composer require --dev friendsofphp/php-cs-fixer

$ echo >.php-cs-fixer.dist.php "<?php

$finder = PhpCsFixer\Finder::create()
    ->exclude('squizlabsD')
    ->in(__DIR__);

$rules = [
    '@psr12' => true,
    // '@psr12:risky' => true,
    '@PHP74Migration' => true,
    // '@PHP74Migration:risky' => true,
    // buggy, duplicates existing comment sometimes
    'no_break_comment' => false,
    'array_syntax' => true,
    'binary_operator_spaces' => true,
    'lowercase_static_reference' => true,
    'visibility_required' => false,
];

$config = new PhpCsFixer\Config();

return $config
    ->setRules($rules)
    // ->setRiskyAllowed(true)
    ->setFinder($finder);
"

$ vendor/bin/php-cs-fixer --version
PHP CS Fixer 3.8.0 BerSzcz against war! by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 7.4.30

$ vendor/bin/php-cs-fixer fix
@dvikan
Copy link
Contributor

dvikan commented Jul 4, 2022

I prefer not create a big diff in the vcs history since we already did one. Reproducing this diff requires additional tooling which I don't like. Most of these add a trailing comma in arrays which isn't super important. I am unsure about the indentation changes in heredocs and in array key => val alignment.

@dvikan dvikan closed this Jul 4, 2022
@jtojnar
Copy link
Contributor Author

jtojnar commented Jul 4, 2022

I prefer not create a big diff in the vcs history since we already did one.

That’s why I proposed doing it as a part of #2872. Now we have no other choice than making a second PR.

Reproducing this diff requires additional tooling which I don't like.

You can just install it one time and then drop it with git clean. Or you can review the changes manually like I did. The alternative is leaving the formatting broken, which makes it easier for mistakes to happen.

Or we could replace CodeSniffer with PHP-CS-Fixer project-wide since it seems to work more reliably.

I felt that the PHP-CS-Fixer defaults were reasonable but can adjust the formatting further if necessary:

  • Trailing array commas make refactoring easier – you can just add/remove/reorder array items without changing different lines.
  • Sane heredoc syntax was introduced in PHP 7.3. It makes the code structure easier to understand since the heredocs no longer break the nesting hierarchy.
  • The spacing around binary operators can be adjusted with ['operators' => ['=>' => 'align_single_space']] – but single space on both sides like any other binary operator makes more sense to me since aligning it manually is pain, both initially and every time a longer key is added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants