Skip to content

Commit

Permalink
ColumnWithoutAnnotation: make sure that $timestamps and $primaryKey c…
Browse files Browse the repository at this point in the history
…ould be a referenced value (eg. a constant);
  • Loading branch information
rentalhost committed Jun 1, 2017
1 parent 325d71f commit c563a17
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <weak_warning descr="@property $id was not annotated">$primaryKey</weak_warning> = self::PRIMARY_KEY;
}
class EloquentModel_TimestampColumnFromConstant extends Model {
const TIMESTAMPS_TRUE = true;
protected <weak_warning descr="@property $created_at was not annotated"><weak_warning descr="@property $updated_at was not annotated">$timestamps</weak_warning></weak_warning> = self::TIMESTAMPS_TRUE;
}

class CC_EloquentModel_TimestampsUndefined extends Model {
protected $timestamps;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit c563a17

Please sign in to comment.