Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@noinspection OnlyWritesOnParameterInspection marked as redundant when using Suppress for statement #1958

Open
InvisibleSmiley opened this issue Oct 17, 2024 · 0 comments

Comments

@InvisibleSmiley
Copy link

Subject Details
Plugin Php Inspections (EA Extended)
Language level PHP 8.1

Current behaviour

Suppress for statement produces @noinspection OnlyWritesOnParameterInspection at statement which then is marked as redundant. Suppress for file/method work without producing new issues.

Expected behaviour

Either Suppress for statement should not be available in this case, or the result should not be marked as redundant.

Test case

<?php

declare(strict_types=1);

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

class ReadonlyArrayAccess implements ArrayAccess
{
    /** @param array<mixed> $data */
    public function __construct(private array $data)
    {
    }

    public function offsetExists(mixed $offset): bool
    {
        return isset($this->data[$offset]);
    }

    public function offsetGet(mixed $offset): mixed
    {
        return $this->data[$offset] ?? null;
    }

    public function offsetSet(mixed $offset, mixed $value): void
    {
        throw new Exception('not allowed');
    }

    public function offsetUnset(mixed $offset): void
    {
        throw new Exception('not allowed');
    }
}

#[CoversClass(ReadonlyArrayAccess::class)]
class ReadonlyAccessTest extends TestCase
{
    public function testArrayAccessSet(): void
    {
        $data = new ReadonlyArrayAccess([]);
        $this->expectExceptionObject(new Exception('not allowed'));
        $data['foo'] = 'bar'; // This line triggers "Parameter/variable is not used" inspection
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant