<?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
Thank you for your report.
Fixed in https://github.com/slevomat/coding-standard/commit/431e9d71e05b7a2d7c291c41aa08435414eb432e
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.
Most helpful comment
Thank you for your report.
Fixed in https://github.com/slevomat/coding-standard/commit/431e9d71e05b7a2d7c291c41aa08435414eb432e