Skip to content

fix: OrderedClassElementsFixer - do not crash on property hook#8517

Merged
keradus merged 2 commits intoPHP-CS-Fixer:masterfrom
6b7562617765726c6f73:fix_OrderedClassElementsFixer
Mar 19, 2025
Merged

fix: OrderedClassElementsFixer - do not crash on property hook#8517
keradus merged 2 commits intoPHP-CS-Fixer:masterfrom
6b7562617765726c6f73:fix_OrderedClassElementsFixer

Conversation

@kubawerlos
Copy link
Copy Markdown
Member

@kubawerlos kubawerlos commented Mar 18, 2025

Fixes part of #8516

Comment on lines +488 to +491
if ($tokens[$index]->equals('(')) {
$index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index);
$index = $tokens->getNextTokenOfKind($index, ['{', ';']);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this PR fixing out-of-memory or crash on finding "end" token?
(or both)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not managed to get an issue with "end" token yet, got this one first. Does "Segmentation fault (core dumped)" stand for lack of memory or too deep recursion? IDK:

kub@:~/code/friendsofphp/PHP-CS-Fixer(master)$ cat test.php
<?php class Foo
{
    public function __construct(
        public string $x {
            set(string $value) {
                $this->x = $value;
            }
        },
        public bool $y,
    ) {}
}
kub@:~/code/friendsofphp/PHP-CS-Fixer(master)$ php php-cs-fixer check test.php -vvv --rules=ordered_class_elements,single_class_element_per_statement
PHP needs to be a minimum version of PHP 7.4.0 and maximum version of PHP 8.3.*.
Current PHP version: 8.4.5.
Ignoring environment requirements because `PHP_CS_FIXER_IGNORE_ENV` is set. Execution may be unstable.
PHP CS Fixer 3.72.1-DEV Persian Successor by Fabien Potencier, Dariusz Ruminski and contributors.
PHP runtime: 8.4.5
Running analysis on 7 cores with 10 files per process.
Parallel runner is an experimental feature and may be unstable, use it at your own risk. Feedback highly appreciated!
Loaded config default from "/home/kuba/code/friendsofphp/PHP-CS-Fixer-3/.php-cs-fixer.dist.php".
Using cache file ".php-cs-fixer.cache".
Paths from configuration file have been overridden by paths provided as command arguments.
 0/1 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░]   0%Segmentation fault (core dumped)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it helped with memory issue.
before, freezing
after, solved.

yet, still problems with style of outcome

@kubawerlos kubawerlos added the topic/PHP8.4 Related to features available in PHP 8.4+ label Mar 18, 2025
@kubawerlos kubawerlos changed the title fix: OrderedClassElementsFixer fix: OrderedClassElementsFixer - do not crash on property hook Mar 18, 2025
@keradus keradus merged commit 06b4bfb into PHP-CS-Fixer:master Mar 19, 2025
@keradus keradus deleted the fix_OrderedClassElementsFixer branch March 19, 2025 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug topic/PHP8.4 Related to features available in PHP 8.4+

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants