From c563a17b7698b1e0db1684a3f0b426b30332b01f Mon Sep 17 00:00:00 2001 From: David Rodrigues Date: Thu, 1 Jun 2017 11:50:32 -0300 Subject: [PATCH] ColumnWithoutAnnotation: make sure that $timestamps and $primaryKey could be a referenced value (eg. a constant); --- ...olumnWithoutAnnotationInspection.fixed.php | 21 +++++++++++++++++++ .../ColumnWithoutAnnotationInspection.php | 14 +++++++++++++ .../ColumnWithoutAnnotationInspection.java | 10 +++++++-- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/resources-tests/laravelInsight/annotation/ColumnWithoutAnnotationInspection.fixed.php b/resources-tests/laravelInsight/annotation/ColumnWithoutAnnotationInspection.fixed.php index cffcab0..4815293 100644 --- a/resources-tests/laravelInsight/annotation/ColumnWithoutAnnotationInspection.fixed.php +++ b/resources-tests/laravelInsight/annotation/ColumnWithoutAnnotationInspection.fixed.php @@ -408,3 +408,24 @@ class CC_EloquentModel_WithANotConstantTimestampsValue extends Model { class CC_EloquentModel_WithANotStringPrimaryKey extends Model { protected $primaryKey = 123; } + +/** + * @property mixed $id + */ +class EloquentModel_PrimaryKeyColumnFromConstant extends Model { + const PRIMARY_KEY = 'id'; + protected $primaryKey = self::PRIMARY_KEY; +} + +/** + * @property mixed $created_at + * @property mixed $updated_at + */ +class EloquentModel_TimestampColumnFromConstant extends Model { + const TIMESTAMPS_TRUE = true; + protected $timestamps = self::TIMESTAMPS_TRUE; +} + +class CC_EloquentModel_TimestampsUndefined extends Model { + protected $timestamps; +} diff --git a/resources-tests/laravelInsight/annotation/ColumnWithoutAnnotationInspection.php b/resources-tests/laravelInsight/annotation/ColumnWithoutAnnotationInspection.php index 980c8ea..6a3e3ad 100644 --- a/resources-tests/laravelInsight/annotation/ColumnWithoutAnnotationInspection.php +++ b/resources-tests/laravelInsight/annotation/ColumnWithoutAnnotationInspection.php @@ -341,3 +341,17 @@ class CC_EloquentModel_WithANotConstantTimestampsValue extends Model { class CC_EloquentModel_WithANotStringPrimaryKey extends Model { protected $primaryKey = 123; } + +class EloquentModel_PrimaryKeyColumnFromConstant extends Model { + const PRIMARY_KEY = 'id'; + protected $primaryKey = self::PRIMARY_KEY; +} + +class EloquentModel_TimestampColumnFromConstant extends Model { + const TIMESTAMPS_TRUE = true; + protected $timestamps = self::TIMESTAMPS_TRUE; +} + +class CC_EloquentModel_TimestampsUndefined extends Model { + protected $timestamps; +} diff --git a/src/laravelInsight/annotation/ColumnWithoutAnnotationInspection.java b/src/laravelInsight/annotation/ColumnWithoutAnnotationInspection.java index 4c89058..ef3a61c 100644 --- a/src/laravelInsight/annotation/ColumnWithoutAnnotationInspection.java +++ b/src/laravelInsight/annotation/ColumnWithoutAnnotationInspection.java @@ -88,11 +88,17 @@ static void reportTimestamps( final PsiElement fieldTimestampsDefaultValue = fieldTimestamps.getDefaultValue(); - if (!(fieldTimestampsDefaultValue instanceof ConstantReference)) { + if (!(fieldTimestampsDefaultValue instanceof PhpExpression)) { return; } - if (!"true".equals(fieldTimestampsDefaultValue.getText())) { + final PsiElement fieldTimestampsDefaultValueResolved = PhpExpressionUtil.from((PhpExpression) fieldTimestampsDefaultValue); + + if (!(fieldTimestampsDefaultValueResolved instanceof ConstantReference)) { + return; + } + + if (!"true".equals(fieldTimestampsDefaultValueResolved.getText())) { return; }