Skip to content

Endless loop when sniffing a PHP file with a git merge conflict inside a function #928

Closed
@IanCaunce

Description

@IanCaunce

I have noticed that if a php file is sniffed which contains a merge conflict inside a function it will result in an endless loop.

Example:

<?php

    function test()
    {
        $arr = array(
            'a' => 'a'
<<<<<<< HEAD
            'b' => 'b'
=======
            'c' => 'c'
>>>>>>> master
        );
    }

This will result in an endless loop when running the following command:
phpcs --report=checkstyle --standard=PSR2 ./test.php

The console will spit out the following endlessly:

PHP Notice: Undefined offset: 1014 in /home/user/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/Tokenizers/PHP.php on line 553
PHP Notice: Undefined offset: 1180 in /home/user/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/Tokenizers/PHP.php on line 1000
PHP Notice: Undefined offset: 1181 in /home/user/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/Tokenizers/PHP.php on line 1000
PHP Notice: Undefined offset: 1182 in /home/user/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/Tokenizers/PHP.php on line 1000
PHP Notice: Undefined offset: 1183 in /home/user/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/Tokenizers/PHP.php on line 1000

I have noticed this happening on other occasions with different invalid php but unfortunately I don't have any examples on hand. I am using version 2.5.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions