Skip to content

Named arg + Constant = "Type Constant is not used in this file" (phpcs v3.10.0) #504

@LastDragon-ru

Description

@LastDragon-ru

I think you should try to report it to PHPCS first.
(c) @kukulich

Sorry, I'm not sure this is related to phpcs or slevomat, so I've posted it in both repos 🤷‍♂️

slevomat/coding-standard#1680

Describe the bug

Since phpcs v3.10.0 the code generate false positive errors about unused constants. Seems it is caused by named arg (no error without it).

------------------------------------------------------------------------- FOUND 2 ERRORS AFFECTING 2 LINES ------------------------------------------------------------------------- 7 | ERROR | [x] Type PREG_SPLIT_DELIM_CAPTURE is not used in this file. 8 | ERROR | [x] Type PREG_SPLIT_NO_EMPTY is not used in this file. ------------------------------------------------------------------------- PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY ------------------------------------------------------------------------- 

Code sample

<?php declare(strict_types = 1); namespace Bug; use function preg_split; use const PREG_SPLIT_DELIM_CAPTURE; use const PREG_SPLIT_NO_EMPTY; preg_split('/((.)\g{-1}*)/um', 'abc', flags: PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);

Custom ruleset

<?xml version="1.0"?> <ruleset name="LaraAspStandard" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./vendor-bin/phpcs/vendor/squizlabs/php_codesniffer/phpcs.xsd"> <config name="installed_paths" value="../../slevomat/coding-standard"/> <rule ref="SlevomatCodingStandard.Namespaces.UnusedUses"> <properties> <property name="searchAnnotations" value="true"/> <property name="ignoredAnnotationNames" type="array"> <element value="@dataProvider"/> </property> </properties> </rule> </ruleset>

Expected behavior

No errors.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions