Skip to content

Allowed names/prefixes for unused variables #1083

Open
@kekmitkep

Description

@kekmitkep

Is your feature request related to a problem?

When using callbacks for example for filter calls on arrays and you only use the $value, the $key parameter might be unused.

There are also multiple other use cases (like workarounds for interface implementation or deep code analysis #490 ) where this could be an issue.

This is prevalent in UnusedFunctionParameterSniff.

Describe the solution you'd like

There could be reserved names or prefixes that are ignored by the unused variable/parameter check.

Should be flagged:

        $selectedCompanies = $companyOptions->values()->filter(
            fn($item, $index): bool => in_array($index + 1, $selectedIndices, true)
        );

Should not be flagged:

        $selectedCompanies = $companyOptions->values()->filter(
            fn($_, $index): bool => in_array($index + 1, $selectedIndices, true)
        );

Additional context (optional)

A similar thing has already been added for PHPMD: phpmd/phpmd#278
phpmd/phpmd#319

For consistency's sake I would suggest a similar or the same approach.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions