Coding-standard: SlevomatCodingStandard.Variables.UnusedVariable.UnusedVariable: false positive for `(string) $index++`

Created on 27 May 2021  路  2Comments  路  Source: slevomat/coding-standard

<?php declare(strict_types = 1);

namespace Test;

use function var_dump;

$map   = [];
$index = 0;
$files = [1,2,3];

foreach ($files as $variable => $stream) {
    // or $name       = 'file'.($index++);
    $name       = (string) $index++;
    $map[$name] = $variable;
}

var_dump($map);
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd">
    <config name="installed_paths" value="../../slevomat/coding-standard"/>
    <file>./packages</file>
    <rule ref="SlevomatCodingStandard.Variables.UnusedVariable">
        <properties>
            <property name="ignoreUnusedValuesWhenOnlyKeysAreUsedInForeach" value="true"/>
        </properties>
    </rule>
</ruleset>
> @php ./vendor/bin/phpcs 'packages/Bug.php'

FILE: /project/packages/Bug.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 12 | ERROR | Unused variable $index.
----------------------------------------------------------------------

Time: 289ms; Memory: 14MB
Bug

Most helpful comment

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings