Skip to content

Commit def8412

Browse files
authored
Merge pull request #111 from Automattic/undefined-this-in-trait
Don't report on undefined `$this` within Trait, similarly to class.
2 parents ed54c4e + 0af3d34 commit def8412

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

WordPressVIPMinimum/Sniffs/Variables/VariableAnalysisSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ protected function checkForThisWithinClass(
800800
if ($tokens[$scopePtr]['code'] === T_CLOSURE) {
801801
return false;
802802
}
803-
if ($scopeCode === T_CLASS) {
803+
if ($scopeCode === T_CLASS || $scopeCode === T_TRAIT) {
804804
return true;
805805
}
806806
}

WordPressVIPMinimum/Tests/Variables/VariableAnalysisUnitTest.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,11 @@
33
function foo() {
44
$a = 'Hello';
55
$c = compact( $a, $b );
6+
}
7+
8+
trait bar {
9+
function foo() {
10+
$this->bar(); // Undefined $this in trait OK.
11+
}
12+
function bar() {}
613
}

0 commit comments

Comments
 (0)