phpinspectionsea icon indicating copy to clipboard operation
phpinspectionsea copied to clipboard

Suggest use is_a when it possible

Open Koc opened this issue 6 years ago • 5 comments

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

Koc avatar Jan 14 '19 12:01 Koc

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

PS: it also possible to use instanceof here.

kalessil avatar Jan 14 '19 13:01 kalessil

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

orklah avatar Jan 14 '19 13:01 orklah

PS: it also possible to use instanceof here.

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

Koc avatar Jan 14 '19 20:01 Koc

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

kalessil avatar Jan 18 '19 16:01 kalessil

Marking as a bug, to catch my eye

kalessil avatar Apr 23 '19 19:04 kalessil