phpinspectionsea
phpinspectionsea copied to clipboard
Self class referencing inspection doesn't check return or parameter type
Subject | Details |
---|---|
Plugin | Php Inspections (EA Extended) 4.0.6.3 |
Language level | PHP 7.4 |
Current behaviour
Independent of the configuration of the inspection. If I run the inspection explicitly, it also doesn't find anything.
Expected behaviour
The incorrect style is detected
Environment details
PhpStorm 2021.2 EAP Build #PS-212.3724.24, built on June 4, 2021 Runtime version: 11.0.11+9-b1481.1 x86_64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 10.15.7 GC: G1 Young Generation, G1 Old Generation Memory: 4096M Cores: 12 Registry: run.processes.with.pty=TRUE, debugger.watches.in.variables=false Non-Bundled Plugins: com.dubreuia (2.2.0), ConsoleUrlLink (0.6), Native Neighbourhood (1.3.0), com.github.leomillon.uuidgenerator (4.4.1), com.intellij.ideolog (203.0.27.0), com.nerdscorner.android.plugin.github (2.1.1), com.star.intellij.console.link (1.0), com.vecheslav.darculaDarkerTheme (1.2.0), indent-rainbow.indent-rainbow (1.6.1), krasa.CpuUsageIndicator (1.14), mobi.hsz.idea.gitignore (4.1.1), name.kropp.intellij.makefile (212.3724.3), AWSCloudFormation (212.3724.3), org.sylfra.idea.plugins.linessorter (1.0.1), some.awesome (1.14), intellij.prettierJS (212.3724.2), NEON support (0.5.1), com.aurimasniekis.phppsr4namespacedetector (1.0.1), com.axeldev.php1Up (0.1.2), com.funivan.idea.phpClean (2020.12.22), com.github.woru.options-completion-phpstorm-plugin (0.0.7), com.kalessil.phpStorm.phpInspectionsEA (4.0.6.3), com.ptby.dynamicreturntypeplugin (2.0.12), com.wbars.php.folding (1.0.3), de.espend.idea.php.phpunit (5.1), dev.dohpaz.php-extras (1.2.0), me.artspb.idea.eval.plugin (0.4), net.king2500.plugins.PhpAdvancedAutoComplete (1.1.0), lv.midiana.misc.phpstorm-plugins.deep-keys (2021.03.26.001), de.espend.idea.php.toolbox (5.1.1), de.espend.idea.php.annotation (8.0.0), fr.adrienbrault.idea.symfony2plugin (0.23.209), izhangzhihao.rainbow.brackets (6.17)
What exactly is the problem here? I don't get it...
The inspection should mark either the class name (FooBar
) or self
as the wrong style, according to the inspections setting.
I think this inspection (Code Style -> Self class referencing) is not applied here, as this is not expected to be applied. The inspection description clearly says it supports:
-
new MyClass
-
MyClass::CONSTANT
-
MyClass::staticMethod()
-
MyClass::$staticProperty
-
MyClass::class
Also, to be honest, I'm not sure if writing this snippet with these 2 ways is really a code smell. It's clearly the same classes as it is a final one, but without the "final" keyword, the 2 signatures have probably different meanings.
You're right about the description. But I remember having the possibility to quick fix the return type. Either this was another inspection or a case of false memory :shrug:
The final
is irrelevant in this case, since this is no case of self
vs. static
, but "only" a code style issue.
Thanks for reporting @ComiR. As folks mentioning, methods signatures are not checked by the inspection. Perhaps it was the inspection for declaring return type hints which was suggesting 'self' as return type?
For final classes, we are considering to analyze methods signatures as well.
@rentalhost, what are your toughs on this (asking as it was your PR initially)? We can hide this behind a new setting, which is disabled by default. Or totally skip if this doesn't fit the original idea.
@ea-inspections-team As far as I remember, it wasn't part of the original proposal. But I think it's an interesting option. A setting to define the default style would also be nice (if it doesn't already exist).
Perhaps it was the inspection for declaring return type hints which was suggesting 'self' as return type?
Maybe. self
is btw only suggested if the @return
annotation type is $this
or self
. If the class name is used in the annotation or the annotation is missing completely, the class name is used as return type.