From 3160e96357abc4377dd66a6c10001f658b806f17 Mon Sep 17 00:00:00 2001 From: David Rodrigues Date: Thu, 22 Jun 2017 08:10:57 -0300 Subject: [PATCH] PropertyWithoutAnnotationInspection: fixing Fluent direct type; --- .../PropertyWithoutAnnotationInspection.php | 9 ++++++++- src/laravelInsight/fluent/FluentUtil.java | 20 +++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/resources-tests/laravelInsight/fluent/PropertyWithoutAnnotationInspection.php b/resources-tests/laravelInsight/fluent/PropertyWithoutAnnotationInspection.php index c41dcc1..ceb804f 100644 --- a/resources-tests/laravelInsight/fluent/PropertyWithoutAnnotationInspection.php +++ b/resources-tests/laravelInsight/fluent/PropertyWithoutAnnotationInspection.php @@ -27,7 +27,7 @@ class Fluent $fluentInstantiatedDirectly = new FluentDirect; $fluentInstantiatedDirectly->shouldNotAccept; - class ChildFluent extends Fluent + class ChildFluent extends FluentDirect { public $publicIsOkay; } @@ -52,4 +52,11 @@ class ChildFluent extends Fluent // Code-coverage: $fluentInstantiatedIndirectly->{'fieldNameIsEmpty'}; + + class NotAFluent + { + } + + $notAFluentInstance = new NotAFluent(); + $notAFluentInstance->shouldBeIgnored; } diff --git a/src/laravelInsight/fluent/FluentUtil.java b/src/laravelInsight/fluent/FluentUtil.java index e0cf73e..d6a3b99 100644 --- a/src/laravelInsight/fluent/FluentUtil.java +++ b/src/laravelInsight/fluent/FluentUtil.java @@ -27,8 +27,7 @@ static boolean isUsingDirectly(@Nullable final PsiElement parameter) { final PhpClass expressionClass = expressionClasses.get(0); final String expressionClassFQN = expressionClass.getFQN(); - final boolean isDirectInstance = expressionClassFQN.equals(LaravelClasses.SUPPORT_FLUENT.toString()) || - expressionClassFQN.equals(LaravelClasses.SUPPORT_FLUENT_L54.toString()); + final boolean isDirectInstance = isFluentFQN(expressionClassFQN); if (!isDirectInstance && (PhpClassUtil.findSuperOfType(expressionClass, LaravelClasses.SUPPORT_FLUENT.toString()) == null)) { @@ -39,7 +38,7 @@ static boolean isUsingDirectly(@Nullable final PsiElement parameter) { // new \Facades\Illuminate\Support\Fluent (facade, from Laravel 5.4); // Case #2: new \Fluent (facade); return isDirectInstance || - (StringUtils.countMatches(expressionClassFQN, "\\") == 1); + isFacade(expressionClassFQN); } static boolean isUsingIndirectly(@Nullable final PsiElement parameter) { @@ -56,8 +55,17 @@ static boolean isUsingIndirectly(@Nullable final PsiElement parameter) { final PhpClass expressionClass = expressionClasses.get(0); final String expressionClassFQN = expressionClass.getFQN(); - return !expressionClassFQN.equals(LaravelClasses.SUPPORT_FLUENT.toString()) && - !expressionClassFQN.equals(LaravelClasses.SUPPORT_FLUENT_L54.toString()) && - (PhpClassUtil.findSuperOfType(expressionClass, LaravelClasses.SUPPORT_FLUENT.toString()) == null); + return !isFluentFQN(expressionClassFQN) && + !isFacade(expressionClassFQN) && + (PhpClassUtil.findSuperOfType(expressionClass, LaravelClasses.SUPPORT_FLUENT.toString()) != null); + } + + private static boolean isFacade(final String classFQN) { + return StringUtils.countMatches(classFQN, "\\") == 1; + } + + private static boolean isFluentFQN(final String classFQN) { + return classFQN.equals(LaravelClasses.SUPPORT_FLUENT.toString()) || + classFQN.equals(LaravelClasses.SUPPORT_FLUENT_L54.toString()); } }