symplify / coding-standard

Coding Standard rules for PHP projects with focus on Clean Architecture
MIT License
347 stars 20 forks source link

Add Utf8 support for LineLengthFixer #17

Open avdeev-ms opened 1 year ago

avdeev-ms commented 1 year ago

No utf8 support for LineLengthFixer. The length of the strings is not correctly calculated, because of this, an extra line break is set, where it is not necessary.

The solution would be \Symplify\CodingStandard\TokenRunner\Transformer\FixerTransformer\FirstLineLengthResolver class to use the mb_strlen function instead of strlen, or be able to configure this behavior

TomasVotruba commented 1 year ago

Could you share exact code of where current behavior fails?

avdeev-ms commented 1 year ago

Setting LineLengthFixer in ecs config (no inline_short_lines, default line length: 120):

$services->set(LineLengthFixer::class)->call(
    'configure',
    [
        [
            'inline_short_lines' => false,
        ],
    ]
);

Run ecs on code example

class Example
{
    public function decline()
    {
        //a line break will be inserted here
        $this->getDefaultHttpException('Извините, произошла ошибка. Попробуйте позже.');
        //no line break will be inserted here
        $this->getDefaultHttpException('Sorry, an unexpected error occurred. Please try later.');
    }
}

The result will be

         //a line break will be inserted here
-        $this->getDefaultHttpException('Извините, произошла ошибка. Попробуйте позже.');
+        $this->getDefaultHttpException(
+            'Извините, произошла ошибка. Попробуйте позже.',
+        );
         //no line break will be inserted here
         $this->getDefaultHttpException('Sorry, an unexpected error occurred. Please try later.');
TomasVotruba commented 1 year ago

I see, it seems valid. Feel free to add this feature with the test fixture you've provided :+1: