Skip to content

Commit

Permalink
Handle variable class static refs (#63)
Browse files Browse the repository at this point in the history
* Tests: add test for variable class static reference

* Allow variable class static references
  • Loading branch information
sirbrillig authored Jan 2, 2019
1 parent 14cb29e commit 6e022ca
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ protected function checkForStaticMember(File $phpcsFile, $stackPtr, $varName, $c
T_SELF,
T_PARENT,
T_STATIC,
T_VARIABLE,
];
if (! in_array($tokens[$classNamePtr]['code'], $staticReferences, true)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function testClassWithMembersWarnings() {
13,
18,
19,
62,
64,
];
$this->assertEquals($expectedWarnings, $lines);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ function method_with_member_var() {
}

class ClassWithLateStaticBinding {
public static $static_member_var;

static function method_with_late_static_binding($param) {
static::some_method($param);
static::some_method($var);
static::some_method($var); // should report a warning
static::some_method(static::CONSTANT, $param);
$called_class = get_called_class();
echo $called_class::$static_member_var;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,14 @@ public function funcUsingPropertyReferenceWithThis($meta) {
public function funcUsingPropertyReferenceWithStatic($meta) {
return static::$$meta;
}

public function funcUsingPropertyReferenceWithVariableClass($meta) {
$called_class = get_called_class();
return $called_class::$$meta;
}

public function funcUsingNamedPropertyReferenceWithVariableClass() {
$called_class = get_called_class();
return $called_class::$staticProperty;
}
}

0 comments on commit 6e022ca

Please sign in to comment.