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.
.php_cs
(extra _
)Custom
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 -----------
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'],
])
;
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.
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
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
bool
. We don't have the choice, as bool
is valid PHP internal primitive type, while boolean
is not - https://3v4l.org/9JsVS
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,
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 '';
}
}
!$value
?
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.)