Tweak to php-cs-fixer Parameters (#2683)

For a recent change, I removed some errors from Phpstan baseline and instead added annotations in the source members. I did this work incrementally, and was surprised when php-cs-fixer required a change from `// @phpstan-ignore-next-line` to `/** @phpstan-ignore-next-line */`. No problem thinks I, and continue to modify several members using the new convention until php-cs-fixer required a change from `/** @phpstan-ignore-next-line */` to `// @phpstan-ignore-next-line`??? I did as directed, and continued to be surprised for the rest of that ticket.

Having had time to research, the problem is due to two options in the php-cs-fixer config file `'comment_to_phpdoc' => true` and `'phpdoc_to_comment' => true`. It seems that php-cs-fixer is treating these annotations the same as doc-blocks, expecting `/**` before a `structural element`, and `//` otherwise. For the statements where I had questions, it expects `/**` before a statement which you might be able to precede with `/** @var`, and `//` where you would not be able to precede it with `/** @var`. However, in this case, what it is doing is forcing what appear to be inconsistencies between otherwise identical statements, whereas php-cs-fixer is supposed to be supporting consistent syntax throughout the project. This PR changes both options to false, allowing (but not requiring) a consistent syntax for these examples. It contains an example of a change from each format to the other, changes which php-cs-fixer would previously have flagged.

An added bonus for this change is that Scrutinizer annotations can now be added to the code; these were often rejected by php-cs-fixer. These should, of course, be used very conservatively, but there are cases where Scrutinizer's analysis is either faulty or not helpful. This PR takes advantage of the change by adding annotations to eliminate the two existing problems which Scrutinizer classifies as 'Security', problems for which there is no sensible way to satisfy Scrutinizer's complaint.

No executable code is changed by this PR.
This commit is contained in:
oleibman 2022-03-16 15:34:40 -07:00 committed by GitHub
parent 78c27c03ca
commit f2f626e02c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 6 deletions

View File

@ -26,7 +26,7 @@ $config
'combine_consecutive_issets' => true, 'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true, 'combine_consecutive_unsets' => true,
'combine_nested_dirname' => true, 'combine_nested_dirname' => true,
'comment_to_phpdoc' => true, 'comment_to_phpdoc' => false, // interferes with annotations
'compact_nullable_typehint' => true, 'compact_nullable_typehint' => true,
'concat_space' => ['spacing' => 'one'], 'concat_space' => ['spacing' => 'one'],
'constant_case' => true, 'constant_case' => true,
@ -171,7 +171,7 @@ $config
'phpdoc_separation' => true, 'phpdoc_separation' => true,
'phpdoc_single_line_var_spacing' => true, 'phpdoc_single_line_var_spacing' => true,
'phpdoc_summary' => true, 'phpdoc_summary' => true,
'phpdoc_to_comment' => true, 'phpdoc_to_comment' => false, // interferes with annotations
'phpdoc_to_param_type' => false, // Because experimental, but interesting for one shot use 'phpdoc_to_param_type' => false, // Because experimental, but interesting for one shot use
'phpdoc_to_return_type' => false, // idem 'phpdoc_to_return_type' => false, // idem
'phpdoc_trim' => true, 'phpdoc_trim' => true,

View File

@ -619,6 +619,7 @@ class Html
// Load the HTML file into the DOM object // Load the HTML file into the DOM object
// Note the use of error suppression, because typically this will be an html fragment, so not fully valid markup // Note the use of error suppression, because typically this will be an html fragment, so not fully valid markup
$prefix = '<?xml encoding="UTF-8">'; $prefix = '<?xml encoding="UTF-8">';
/** @scrutinizer ignore-unhandled */
@$dom->loadHTML($prefix . $html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); @$dom->loadHTML($prefix . $html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
// Discard excess white space // Discard excess white space
$dom->preserveWhiteSpace = false; $dom->preserveWhiteSpace = false;
@ -808,7 +809,7 @@ class Html
if (isset($callbacks[$callbackTag])) { if (isset($callbacks[$callbackTag])) {
$elementHandler = $callbacks[$callbackTag]; $elementHandler = $callbacks[$callbackTag];
if (method_exists($this, $elementHandler)) { if (method_exists($this, $elementHandler)) {
// @phpstan-ignore-next-line /** @phpstan-ignore-next-line */
call_user_func([$this, $elementHandler], $element); call_user_func([$this, $elementHandler], $element);
} }
} }

View File

@ -71,7 +71,7 @@ class MD5
*/ */
public function add(string $data): void public function add(string $data): void
{ {
/** @phpstan-ignore-next-line */ // @phpstan-ignore-next-line
$words = array_values(unpack('V16', $data)); $words = array_values(unpack('V16', $data));
$A = $this->a; $A = $this->a;

View File

@ -54,7 +54,9 @@ class XMLWriter extends \XMLWriter
public function __destruct() public function __destruct()
{ {
// Unlink temporary files // Unlink temporary files
// There is nothing reasonable to do if unlink fails.
if ($this->tempFileName != '') { if ($this->tempFileName != '') {
/** @scrutinizer ignore-unhandled */
@unlink($this->tempFileName); @unlink($this->tempFileName);
} }
} }

View File

@ -35,8 +35,7 @@ class Row
*/ */
public function __destruct() public function __destruct()
{ {
// @phpstan-ignore-next-line $this->worksheet = null; // @phpstan-ignore-line
$this->worksheet = null;
} }
/** /**