deprecated-packages / symplify

[DISCONTINUED] Check split packages in their own repositories :)
MIT License
622 stars 190 forks source link

Tokens::findBlockEnd(): Argument #2 ($searchIndex) must be of type int, null given #4382

Closed rez1dent3 closed 2 years ago

rez1dent3 commented 2 years ago

Hello. Upgrading from 11.1.5 to 11.1.6 introduced an incomprehensible error.

 composer req symplify/easy-coding-standard:11.1.6 --dev

ecs.php

<?php

declare(strict_types=1);

use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
use PhpCsFixer\Fixer\Phpdoc\GeneralPhpdocAnnotationRemoveFixer;
use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestClassRequiresCoversFixer;
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ECSConfig $containerConfigurator): void {
    $services = $containerConfigurator->services();
    $services->set(ArraySyntaxFixer::class)
        ->call('configure', [[
            'syntax' => 'short',
        ]]);

    $services->set(DeclareStrictTypesFixer::class);
    $services->set(LineLengthFixer::class);

    $parameters = $containerConfigurator->parameters();
    $parameters->set(Option::PARALLEL, true);

    $containerConfigurator->paths([
        __DIR__ . '/config',
        __DIR__ . '/database',
        __DIR__ . '/resources/lang',
        __DIR__ . '/src',
        __DIR__ . '/tests',
    ]);

    $containerConfigurator->skip([
        GeneralPhpdocAnnotationRemoveFixer::class,
        PhpUnitTestClassRequiresCoversFixer::class,
    ]);

    $containerConfigurator->import(SetList::CLEAN_CODE);
    $containerConfigurator->import(SetList::SYMPLIFY);
    $containerConfigurator->import(SetList::COMMON);
    $containerConfigurator->import(SetList::PSR_12);
    $containerConfigurator->import(SetList::CONTROL_STRUCTURES);
    $containerConfigurator->import(SetList::NAMESPACES);
    $containerConfigurator->import(SetList::STRICT);
    $containerConfigurator->import(SetList::PHPUNIT);
};
php vendor/bin/ecs check --debug --clear-cache
....
 [ERROR] System error: "Fixing of "tests/Infra/Factories/BuyerFactory.php" file by                                      
         "PhpCsFixer\Fixer\Whitespace\MethodChainingIndentationFixer" failed:                                           
         PhpCsFixer\Tokenizer\Tokens::findBlockEnd(): Argument #2 ($searchIndex) must be of type int, null given, called
         in                                                                                                             
         /Users/babichev/projects/laravel-wallet/vendor/symplify/easy-coding-standard/vendor/friendsofphp/php-cs-fixer/s
         rc/Fixer/Whitespace/MethodChainingIndentationFixer.php on line 70 in file                                      
         /Users/babichev/projects/laravel-wallet/vendor/symplify/easy-coding-standard/vendor/friendsofphp/php-cs-fixer/s
         rc/Tokenizer/Tokens.php on line 310"Run ECS with "--debug" option and post the report here:                    
         https://github.com/symplify/symplify/issues/new in tests/Infra/Factories/BuyerFactory.php:182                  

BuyerFactory.php

<?php

declare(strict_types=1);

namespace Bavix\Wallet\Test\Infra\Factories;

use Bavix\Wallet\Test\Infra\Models\Buyer;
use Illuminate\Database\Eloquent\Factories\Factory;

class BuyerFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = Buyer::class;

    /**
     * Define the model's default state.
     */
    public function definition(): array
    {
        return [
            'name' => $this->faker->name,
            'email' => $this->faker->unique()
                ->safeEmail,
        ];
    }
}

There is no error on version 11.1.5, everything works correctly.

More details can be found at the link: https://github.com/bavix/laravel-wallet/runs/8120706935?check_suite_focus=true


And here is the successful passage of the code on version 11.1.5: https://github.com/bavix/laravel-wallet/runs/8100185166?check_suite_focus=true

TomasVotruba commented 2 years ago

The MethodChainingIndentationFixer is a rule from https://github.com/FriendsOfPHP/PHP-CS-Fixer It must be fixed there first.

There is possibly new relesae of PHP CS Fixer with this bug.

rez1dent3 commented 2 years ago

@TomasVotruba Yes, that's right. I pulled up the latest version 3.11.0 and the problem went away. I see your release 11.1.7. Similarly, the problem is no more. Thank you.

bug: Fix MethodChainingIndentationFixer with arrow functions and class instantiation (https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/5587) bug: MethodChainingIndentationFixer - Fix bug with attribute access (https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/6573)