slevomat / coding-standard

Slevomat Coding Standard for PHP_CodeSniffer provides many useful sniffs
MIT License
1.39k stars 171 forks source link

`Undefined index: scope_closer` in UseStatementHelper.php#L193 #1532

Closed williamdes closed 1 year ago

williamdes commented 1 year ago

phpcbf

PHP Fatal error:  Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Undefined index: scope_closer in vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php on line 193 in vendor/squizlabs/php_codesniffer/src/Runner.php:608
Stack trace:
#0 vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php(193): PHP_CodeSniffer\Runner->handleErrors(8, 'Undefined index...', '/mnt/Dev/@phpmy...', 193, Array)
#1 vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/SniffLocalCache.php(42): SlevomatCodingStandard\Helpers\UseStatementHelper::SlevomatCodingStandard\Helpers\{closure}()
#2 vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/SniffLocalCache.php(31): SlevomatCodingStandard\Helpers\SniffLocalCache::setIfNotCached(0, '/mnt/Dev/@phpmy...', Object(Closure))
#3 vend in vendor/squizlabs/php_codesniffer/src/Runner.php on line 608

phpcs

   1 | ERROR   | [ ] An error occurred during processing; checking has been aborted. The error message was: Undefined index: scope_closer in
     |         |     /mnt/Dev/@phpmyadmin/sql-parser/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php on line 193 (Internal.Exception)

I trimmed down the example to

<?php

declare(strict_types=1);

namespace PhpMyAdmin\SqlParser\Tests\Builder;

use Generator;
use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Tests\TestCase;

class AlterStatementTest extends TestCase
{
    public function testBuilderPartitions(): void
    {
        $parser = new Parser(
            <<<SQL
            ALTER TABLE trips PARTITION BY RANGE (MONTH(trip_date))
            (
                PARTITION p01 VALUES LESS THAN (02),
                PARTITION p02 VALUES LESS THAN (03),
                PARTITION p03 VALUES LESS THAN (04),
                PARTITION p04 VALUES LESS THAN (05),
                PARTITION p05 VALUES LESS THAN (06),
                PARTITION p06 VALUES LESS THAN (07),
                PARTITION p07 VALUES LESS THAN (08),
                PARTITION p08 VALUES LESS THAN (09),
                PARTITION p09 VALUES LESS THAN (10),
                PARTITION p10 VALUES LESS THAN (11),
                PARTITION p11 VALUES LESS THAN (12),
                PARTITION p12 VALUES LESS THAN (13),
                PARTITION pmaxval VALUES LESS THAN MAXVALUE
            );
            SQL
        );
    }
}

Using slevomat/coding-standard 7.2.1 It's most possible this still exists

kukulich commented 1 year ago

Please try newest version.

williamdes commented 1 year ago

Please try newest version.

Please re-open, I just tried 8.8.0

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 1 | ERROR | An error occurred during processing; checking has been aborted. The error message was: Undefined index: scope_closer in
   |       | vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php on line 194 (Internal.Exception)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

⚠️ This needs to be run with PHP 7.2, newer PHP 8 does not reproduce.

kukulich commented 1 year ago

So upgrade PHP :)

williamdes commented 1 year ago

So upgrade PHP :)

Hey mate seriously, your composer.json supports 7.2.. https://github.com/slevomat/coding-standard/blob/master/composer.json#L19

Clearly I don't care about this issue, I changed the syntax. But that's not a cool answer to a real bug

kukulich commented 1 year ago

The bug is probably in PHPCS itself anyway :)

github-actions[bot] commented 1 year ago

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.