kalessil / phpinspectionsea

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

Suggest use is_a when it possible #1165

Open Koc opened 5 years ago

Koc commented 5 years ago
Subject Details
Issue type Feature request
Plugin Php Inspections EA Extended v3.0.10
Language level PHP 7.2

Current behaviour (description/screenshot:)

if (!in_array(ResultItemSubscriber::class, class_implements($resultBuilder))) {
    throw new \RuntimeException(sprintf('Result builder class "%s" should implements "%s" interface.', $resultBuilder, ResultItemSubscriber::class));
}

For now code suggests only add true 3rd argument to in_array function.

Expected behaviour

Would be nice suggest (and provide hotfix for it) for replasing this kind of code with is_a call.

Environment details

PhpStorm 2018.3.3
Build #PS-183.5153.36, built on January 9, 2019
Licensed to XXX
Subscription is active until November 13, 2019
JRE: 1.8.0_152-release-1343-b26 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.15.0-43-generic
kalessil commented 5 years ago

Thank you for the proposal @Koc, I'll evaluate the case.

PS: it also possible to use instanceof here.

orklah commented 5 years ago

Hi @kalessil , it seems that it's the same as one of the cases here: https://github.com/kalessil/phpinspectionsea/issues/1143#issuecomment-450931889

Koc commented 5 years ago

PS: it also possible to use instanceof here.

no, because in this context $resultBuilder is FQCN, not an object.

kalessil commented 5 years ago

@koc: understood, thank you =) @orklah: moving upper in my list =)

kalessil commented 5 years ago

Marking as a bug, to catch my eye