slevomat / coding-standard

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

SlevomatCodingStandard.ControlStructures.EarlyExit - Fatal error #343

Closed EvgenyOrekhov closed 6 years ago

EvgenyOrekhov commented 6 years ago

.............E................E..................E..... Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 2147483656 bytes) in /app/vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/EarlyExitSniff.php on line 476

https://github.com/slevomat/coding-standard/blob/1e609159241fa90d5a429f185b2ea9b881340a7c/SlevomatCodingStandard/Sniffs/ControlStructures/EarlyExitSniff.php#L476

I don't know how to make PHP_CodeSniffer tell me the name of the file that trips up the sniffer.

Slevomat Coding Standard version: 4.5.2 PHP version: 7.2.3

kukulich commented 6 years ago

@EvgenyOrekhov Can you try dev-master?

EvgenyOrekhov commented 6 years ago

@kukulich I will try it on Monday.

EvgenyOrekhov commented 6 years ago

@kukulich Got the same error on dev-master:

.............E................E..................E..... Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 2147483656 bytes) in /app/vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/EarlyExitSniff.php on line 488

https://github.com/slevomat/coding-standard/blob/2b5a5a2768f058fd77cb069974b7fe9427cae94c/SlevomatCodingStandard/Sniffs/ControlStructures/EarlyExitSniff.php#L488

Slevomat Coding Standard version: 2b5a5a2

kukulich commented 6 years ago

@EvgenyOrekhov Ok. Please try verbose modes for PHPCS to detect the file and please post the file here. I'm not able to fix it without the code.

EvgenyOrekhov commented 6 years ago

@kukulich Here you go:

<?php if ($a): ?>
    true
<?php else: ?>
    false
<?php endif; ?>

<?php else: ?> is the cause of the infinite loop.

kukulich commented 6 years ago

@EvgenyOrekhov This doesn't look like a file you should check with PHPCS...

EvgenyOrekhov commented 6 years ago

@kukulich I reduced the original file to the simplest case that generates the error. The original file is a "view" file that contains HTML and PHP. PHP_CodeSniffer's built-in sniffers are perfectly capable of analyzing this kind of files.

kukulich commented 6 years ago

Ok but I don't want to support view files. I don't see any benefit. So I'm sorry but I'll not fix this.

EvgenyOrekhov commented 6 years ago

@kukulich I checked the following code:

<?php

class Example
{
    public function f($a)
    {
        if ($a):
            return 'true';
        else:
            return 'false';
        endif;
    }
}

It's not a view, but It also generates the out of memory error because of else:.

github-actions[bot] commented 4 years 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.