Skip to content

Commit f2f626e

Browse files
authored
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.
1 parent 78c27c0 commit f2f626e

File tree

5 files changed

+8
-6
lines changed

5 files changed

+8
-6
lines changed

.php-cs-fixer.dist.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
'combine_consecutive_issets' => true,
2727
'combine_consecutive_unsets' => true,
2828
'combine_nested_dirname' => true,
29-
'comment_to_phpdoc' => true,
29+
'comment_to_phpdoc' => false, // interferes with annotations
3030
'compact_nullable_typehint' => true,
3131
'concat_space' => ['spacing' => 'one'],
3232
'constant_case' => true,
@@ -171,7 +171,7 @@
171171
'phpdoc_separation' => true,
172172
'phpdoc_single_line_var_spacing' => true,
173173
'phpdoc_summary' => true,
174-
'phpdoc_to_comment' => true,
174+
'phpdoc_to_comment' => false, // interferes with annotations
175175
'phpdoc_to_param_type' => false, // Because experimental, but interesting for one shot use
176176
'phpdoc_to_return_type' => false, // idem
177177
'phpdoc_trim' => true,

src/PhpSpreadsheet/Helper/Html.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ public function toRichTextObject($html)
619619
// Load the HTML file into the DOM object
620620
// Note the use of error suppression, because typically this will be an html fragment, so not fully valid markup
621621
$prefix = '<?xml encoding="UTF-8">';
622+
/** @scrutinizer ignore-unhandled */
622623
@$dom->loadHTML($prefix . $html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
623624
// Discard excess white space
624625
$dom->preserveWhiteSpace = false;
@@ -808,7 +809,7 @@ protected function handleCallback(DOMElement $element, $callbackTag, array $call
808809
if (isset($callbacks[$callbackTag])) {
809810
$elementHandler = $callbacks[$callbackTag];
810811
if (method_exists($this, $elementHandler)) {
811-
// @phpstan-ignore-next-line
812+
/** @phpstan-ignore-next-line */
812813
call_user_func([$this, $elementHandler], $element);
813814
}
814815
}

src/PhpSpreadsheet/Reader/Xls/MD5.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function getContext()
7171
*/
7272
public function add(string $data): void
7373
{
74-
/** @phpstan-ignore-next-line */
74+
// @phpstan-ignore-next-line
7575
$words = array_values(unpack('V16', $data));
7676

7777
$A = $this->a;

src/PhpSpreadsheet/Shared/XMLWriter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ public function __construct($temporaryStorage = self::STORAGE_MEMORY, $temporary
5454
public function __destruct()
5555
{
5656
// Unlink temporary files
57+
// There is nothing reasonable to do if unlink fails.
5758
if ($this->tempFileName != '') {
59+
/** @scrutinizer ignore-unhandled */
5860
@unlink($this->tempFileName);
5961
}
6062
}

src/PhpSpreadsheet/Worksheet/Row.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public function __construct(?Worksheet $worksheet = null, $rowIndex = 1)
3535
*/
3636
public function __destruct()
3737
{
38-
// @phpstan-ignore-next-line
39-
$this->worksheet = null;
38+
$this->worksheet = null; // @phpstan-ignore-line
4039
}
4140

4241
/**

0 commit comments

Comments
 (0)