From 5c6e35ec96cc042f3d674379a30e21a9c1a80c6f Mon Sep 17 00:00:00 2001 From: David Rodrigues Date: Thu, 1 Jun 2017 15:13:53 -0300 Subject: [PATCH] [#12] ColumnWithoutAnnotation: for accessors, identify type from return type; --- ...WithoutAnnotationInspection.matchTypes.fixed.php | 13 +++++++++++++ ...ColumnWithoutAnnotationInspection.matchTypes.php | 9 +++++++++ .../ColumnWithoutAnnotationInspection.java | 12 ++++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/resources-tests/laravelInsight/annotation/ColumnWithoutAnnotationInspection.matchTypes.fixed.php b/resources-tests/laravelInsight/annotation/ColumnWithoutAnnotationInspection.matchTypes.fixed.php index 19decc9..974a490 100644 --- a/resources-tests/laravelInsight/annotation/ColumnWithoutAnnotationInspection.matchTypes.fixed.php +++ b/resources-tests/laravelInsight/annotation/ColumnWithoutAnnotationInspection.matchTypes.fixed.php @@ -44,3 +44,16 @@ class Eloquent_IdSuffix extends EloquentSimulation } (new Eloquent_IdSuffix)->user_id; + +/** + * @property int $id + * @property string $identify_as_string + */ +class Eloquent_IdentifyAccessorReturnType extends EloquentSimulation +{ + public function getIdentifyAsStringAttribute(): string { + } +} + +(new Eloquent_IdentifyAccessorReturnType)->identify_as_string; + diff --git a/resources-tests/laravelInsight/annotation/ColumnWithoutAnnotationInspection.matchTypes.php b/resources-tests/laravelInsight/annotation/ColumnWithoutAnnotationInspection.matchTypes.php index 0cc29a8..456d7ab 100644 --- a/resources-tests/laravelInsight/annotation/ColumnWithoutAnnotationInspection.matchTypes.php +++ b/resources-tests/laravelInsight/annotation/ColumnWithoutAnnotationInspection.matchTypes.php @@ -28,3 +28,12 @@ class Eloquent_IdSuffixuser_id; + +class Eloquent_IdentifyAccessorReturnType extends EloquentSimulation +{ + public function getIdentifyAsStringAttribute(): string { + } +} + +(new Eloquent_IdentifyAccessorReturnType)->identify_as_string; + diff --git a/src/laravelInsight/annotation/ColumnWithoutAnnotationInspection.java b/src/laravelInsight/annotation/ColumnWithoutAnnotationInspection.java index 9daad5a..fbf10fd 100644 --- a/src/laravelInsight/annotation/ColumnWithoutAnnotationInspection.java +++ b/src/laravelInsight/annotation/ColumnWithoutAnnotationInspection.java @@ -183,15 +183,23 @@ static void reportAccessorOrMutator( final String methodName ) { if (methodName.endsWith("Attribute")) { - if (methodName.startsWith("get") || + final boolean isAccessor = methodName.startsWith("get"); + + if (isAccessor || methodName.startsWith("set")) { final PsiElement methodIdentifier = method.getNameIdentifier(); assert methodIdentifier != null; + String methodReturnType = "mixed"; + + if (isAccessor) { + methodReturnType = PhpFunctionUtil.getReturnType((Function) method).toString(); + } + final String methodPropertyPart = methodName.substring(3, methodName.length() - 9); validatePropertyAnnotation(problemsHolder, methodClass, methodIdentifier, - CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, methodPropertyPart), "mixed"); + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, methodPropertyPart), methodReturnType); } } }