Skip to content

Compatibility with PHP-Parser #1286

@0zd0

Description

@0zd0

Describe the bug

When I develop sniffers and use PHPUnit and do coverage, it uses PHP-Parser, which checks that the token is a number, but you fill it with a string, I didn't delve too deeply into the purpose of this, but I found out from the stack

To reproduce

{
    "name": "onepix/wp-coding-standards",
    "type": "phpcodesniffer-standard",
    "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions",
    "license": "MIT",
    "keywords": [
        "phpcs",
        "standards",
        "static analysis",
        "WordPress"
    ],
    "autoload": {
        "psr-4": {
            "WpOnepixStandard\\": "WpOnepixStandard/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "PHP_CodeSniffer\\Tests\\": "vendor/squizlabs/php_codesniffer/tests/"
        }
    },
    "require": {
        "php": "^8.3",
        "wp-coding-standards/wpcs": "^3",
        "squizlabs/php_codesniffer": "3.13.4"
    },
    "require-dev": {
        "phpunit/phpunit": "^12",
        "vimeo/psalm": "^6.8"
    },
    "config": {
        "allow-plugins": {
            "dealerdirect/phpcodesniffer-composer-installer": true
        }
    },
    "scripts": {
        "tests:unit": "phpunit -c phpunit.xml --coverage-filter WpOnepixStandard --coverage-clover=coverage-unit.xml"
    }
}

Versions

Operating System MacOS 15.6.1 (24G90)
PHP version 8.3.26
PHP_CodeSniffer version 3.13.4
Standard custom
Install type Composer

Additional context

An error occurred inside PHPUnit.

Message:  Token T_PUBLIC_SET has ID of type string, should be int. You may be using a library with broken token emulation
Location: /IdeaProjects/wp-coding-standards/vendor/nikic/php-parser/lib/PhpParser/compatibility_tokens.php:39

#0 /IdeaProjects/wp-coding-standards/vendor/nikic/php-parser/lib/PhpParser/compatibility_tokens.php(71): PhpParser\defineCompatibilityTokens()
#1 /IdeaProjects/wp-coding-standards/vendor/nikic/php-parser/lib/PhpParser/Lexer.php(5): require('/IdeaProjects/w...')
#2 /IdeaProjects/wp-coding-standards/vendor/squizlabs/php_codesniffer/autoload.php(173): include('/IdeaProjects/w...')
#3 /IdeaProjects/wp-coding-standards/vendor/squizlabs/php_codesniffer/autoload.php(138): PHP_CodeSniffer\Autoload::loadFile('/IdeaProjects/w...')
#4 /IdeaProjects/wp-coding-standards/vendor/nikic/php-parser/lib/PhpParser/ParserFactory.php(16): PHP_CodeSniffer\Autoload::load('PhpParser\\Lexer')
#5 /IdeaProjects/wp-coding-standards/vendor/nikic/php-parser/lib/PhpParser/ParserFactory.php(40): PhpParser\ParserFactory->createForVersion(Object(PhpParser\PhpVersion))
#6 /IdeaProjects/wp-coding-standards/vendor/phpunit/php-code-coverage/src/StaticAnalysis/ParsingSourceAnalyser.php(50): PhpParser\ParserFactory->createForHostVersion()
#7 /IdeaProjects/wp-coding-standards/vendor/phpunit/php-code-coverage/src/StaticAnalysis/CachingSourceAnalyser.php(73): SebastianBergmann\CodeCoverage\StaticAnalysis\ParsingSourceAnalyser->analyse('/IdeaProjects/w...', '<?php\n\ndeclare(...', true, false)
#8 /IdeaProjects/wp-coding-standards/vendor/phpunit/php-code-coverage/src/StaticAnalysis/CacheWarmer.php(31): SebastianBergmann\CodeCoverage\StaticAnalysis\CachingSourceAnalyser->analyse('/IdeaProjects/w...', '<?php\n\ndeclare(...', true, false)
#9 /IdeaProjects/wp-coding-standards/vendor/phpunit/phpunit/src/Runner/CodeCoverage.php(145): SebastianBergmann\CodeCoverage\StaticAnalysis\CacheWarmer->warmCache('/IdeaProjects/w...', true, false, Object(SebastianBergmann\CodeCoverage\Filter))
#10 /IdeaProjects/wp-coding-standards/vendor/phpunit/phpunit/src/TextUI/Application.php(206): PHPUnit\Runner\CodeCoverage->init(Object(PHPUnit\TextUI\Configuration\Configuration), Object(PHPUnit\TextUI\Configuration\CodeCoverageFilterRegistry), false)
#11 /IdeaProjects/wp-coding-standards/vendor/phpunit/phpunit/phpunit(104): PHPUnit\TextUI\Application->run(Array)
#12 /IdeaProjects/wp-coding-standards/vendor/bin/phpunit(122): include('/IdeaProjects/w...')
#13 {main}

Please confirm

  • I have searched the issue list and am not opening a duplicate issue.
  • I have read the Contribution Guidelines and this is not a support question.
  • I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
  • I have verified the issue still exists in the 4.x branch of PHP_CodeSniffer.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions