kalessil / phpinspectionsea

A Static Code Analyzer for PHP (a PhpStorm/Idea Plugin)
https://plugins.jetbrains.com/plugin/7622?pr=phpStorm
Other
1.44k stars 118 forks source link

Senseless proxy function False Positive for method with PHPStan PHPDoc comment #1947

Open SebastianSimon opened 4 months ago

SebastianSimon commented 4 months ago
Subject Details
Plugin Php Inspections (EA Extended) or Php Inspections (EA Ultimate), 5.0.0.0
Language level PHP 8.3

Current behaviour

The inspection hint “[EA] 'isEmpty' method can be dropped, as it only calls parent's one.” is triggered for derived methods that introduce a PHPDoc comment that changes semantics of the base method. In this example, @phpstan-impure is needed because PHPStan has a heuristic where isEmpty is assumed to be a pure getter, but it’s clearly not pure. Can’t modify the base class because it’s part of a library

<?php

declare(strict_types=1);

namespace X;

class ExampleCase
{
    private array $data = [];

    public function isEmpty(): bool
    {
        return $this->data === [];
    }
}
<?php

declare(strict_types=1);

namespace X;

class ExampleCase2 extends ExampleCase
{
    /**
     * @phpstan-impure
     */
    public function isEmpty(): bool // [EA] 'isEmpty' method can be dropped, as it only calls parent's one.
    {
        return parent::isEmpty();
    }
}
Bildschirmfoto 2024-06-03 um 09 43 38

Expected behaviour

The Senseless proxy function inspection should probably ignore derived methods with a PHPDoc comment.

Environment details

IntelliJ IDEA 2024.1.2 (Ultimate Edition)
Build #IU-241.17011.79, built on May 22, 2024
Licensed to yep, me, trust me.
You have a perpetual fallback license for this version.
Subscription is active until April 26, 2025.
Runtime version: 17.0.11+1-b1207.24 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 14.5
GC: G1 Young Generation, G1 Old Generation
Memory: 4096M
Cores: 12
Metal Rendering is ON
Registry:
  ide.experimental.ui=true
  org.toml.json.schema=false
Non-Bundled Plugins:
  ru.sadv1r.ansible-vault-editor-idea-plugin (1.21)
  de.femtopedia.diffplugin (2.1.13)
  com.jetbrains.rust (241.25989.199)
  com.intellij.ml.llm (241.17011.2)
  name.kropp.intellij.makefile (241.14494.150)
  com.intellij.mermaid (0.0.22+IJ.232)
  com.intellij.kubernetes (241.17011.84)
  nl.rubensten.texifyidea (0.9.5)
  com.jetbrains.space (241.17011.48)
  com.jetbrains.php (241.17011.119)
  org.jetbrains.plugins.phpstorm-remote-interpreter (241.14494.158)
  org.jetbrains.plugins.phpstorm-docker (241.14494.158)
  com.intellij.php.psalm (241.17011.119)
  com.intellij.php.tools.quality.phpstan (241.17011.119)
  com.kalessil.phpStorm.phpInspectionsEA (5.0.0.0)
  NEON support (0.5.4)
  de.espend.idea.php.annotation (10.0.0)
  com.mallowigi (97.0.0)
  commit-prefix-plugin (1.3.0)
  fr.adrienbrault.idea.symfony2plugin (2024.1.274)
  com.laravel_idea.tailwind (1.4.2)
  mobi.hsz.idea.gitignore (4.5.3)
  izhangzhihao.rainbow.brackets (2024.2.3-241)
  ru.adelf.idea.dotenv (2024.1)
Kotlin: 241.17011.79-IJ
ea-inspections-team commented 1 month ago

Thank you for reporting @SebastianSimon.

It's an interesting case, from the example I can see that original class have no doc-block at all. Can you confirm the library method you are referencing to also had no doc-block?