Skip to content

Commit

Permalink
[#12] ColumnWithoutAnnotation: for accessors, identify type from retu…
Browse files Browse the repository at this point in the history
…rn type;
  • Loading branch information
rentalhost committed Jun 1, 2017
1 parent 979b100 commit 5c6e35e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,12 @@ class <weak_warning descr="@property $id was not annotated">Eloquent_IdSuffix</w
}
(new Eloquent_IdSuffix)-><weak_warning descr="@property $user_id was not annotated">user_id</weak_warning>;
class <weak_warning descr="@property $id was not annotated">Eloquent_IdentifyAccessorReturnType</weak_warning> extends EloquentSimulation
{
public function <weak_warning descr="@property $identify_as_string was not annotated">getIdentifyAsStringAttribute</weak_warning>(): string {
}
}

(new Eloquent_IdentifyAccessorReturnType)-><weak_warning descr="@property $identify_as_string was not annotated">identify_as_string</weak_warning>;

Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 5c6e35e

Please sign in to comment.