squizlabs/php_codesniffer 3.3.2slevomat/coding-standard 4.8.3An error occurred during processing; checking has been aborted. The error message was: Undefined
| | index: scope_closer in
| | /Users/me/work/code/project/vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/ControlStructureSpacingSniff.php
| | on line 263 (Internal.Exception)
class ChangeDbCharsetToRealUtf8
{
public function changeDbCharset(string $connection, string $newCharset, string $newCollate): void
{
$columnsWithVarcharType = [];
foreach ($columnsWithVarcharType as $columnMeta) {
$tableDotColumn = "{$columnMeta->TABLE_NAME}.{$columnMeta->COLUMN_NAME}";
if (true) {
$queuedTableChanges[$columnMeta->TABLE_NAME][] = "CHANGE `{$columnMeta->COLUMN_NAME}` `{$columnMeta->COLUMN_NAME}` VARCHAR(191) CHARACTER SET {$newCharset} COLLATE {$newCollate}";
echo "-- Shrinking queued: {$tableDotColumn} ({$columnMeta->CHARACTER_MAXIMUM_LENGTH} => 191)\n";
} else if ($newCharset === 'utf8' && $columnMeta->CHARACTER_MAXIMUM_LENGTH === 191) {
$queuedTableChanges[$columnMeta->TABLE_NAME][] = "CHANGE `{$columnMeta->COLUMN_NAME}` `{$columnMeta->COLUMN_NAME}` VARCHAR(255) CHARACTER SET {$newCharset} COLLATE {$newCollate}";
echo "-- Expanding queued: {$tableDotColumn} ({$columnMeta->CHARACTER_MAXIMUM_LENGTH} => 255)\n";
} else {
$queuedTableChanges[$columnMeta->TABLE_NAME][] = "CHANGE `{$columnMeta->COLUMN_NAME}` `{$columnMeta->COLUMN_NAME}` VARCHAR({$columnMeta->CHARACTER_MAXIMUM_LENGTH}) CHARACTER SET {$newCharset} COLLATE {$newCollate}";
}
}
}
}
I found that problem caused by else if. It works fine with elseif
else if is not supported, such issues had been reported multiple times before and always closed as _won't fix - send PR if you need it_. :)
@Majkl578
Thanks, I also don't see any reasons to spend time on writing a code to support else if, let's close this issue 馃憤
BTW: is there an inspection for else if/elseif ?
I will only improve the reported error.
BTW: is there an inspection for
else if/elseif?
Yes, in Doctrine CS we use this:
<!-- Disallow else if in favor of elseif -->
<rule ref="PSR2.ControlStructures.ElseIfDeclaration.NotAllowed">
<type>error</type>
</rule>
Needs to be escalated to error, it's warning by default afaik.
If your CS is not based on PSR 2, you'll probably also need to import the rule itself:
<rule ref="PSR2.ControlStructures.ElseIfDeclaration"/>
Not sure about the consequences of the error in description, but in my case, it causes a fatal error in PHPCBF so that it cannot proceed with fixing other files. While the workaround is simple, the failure itself may become a barrier which would scare out new adopters with existing codebases.
If you know what you're doing and you know you need to get the job done, you'll figure out a workaround. But if someone is just trying the tool and seeing a fatal error, they may just give up and have negative feelings associated with the tool, the standard and the coding standards in general.
I do agree that making the standard work with if /else is not necessary, but fixing the fatal error is a must.
Error reporting improved in https://github.com/slevomat/coding-standard/commit/cadf1fdee8c3a9b4542b37cc37688b5a6803fd33
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
I will only improve the reported error.