Skip to content

Commit 12507d6

Browse files
committed
Add description to processVariable
1 parent 6a19a67 commit 12507d6

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,25 @@ protected function isVariableASymbolicObjectProperty(File $phpcsFile, $stackPtr,
11401140
}
11411141

11421142
/**
1143-
* Called to process normal member vars.
1143+
* Process a normal variable in the code
1144+
*
1145+
* Most importantly, this function determines if the variable use is a "read"
1146+
* (using the variable for something) or a "write" (an assignment) or,
1147+
* sometimes, both at once.
1148+
*
1149+
* It also determines the scope of the variable (where it begins and ends).
1150+
*
1151+
* Using these two pieces of information, we can determine if the variable is
1152+
* being used ("read") without having been defined ("write").
1153+
*
1154+
* We can also determine, once the scan has hit the end of a scope, if any of
1155+
* the variables within that scope have been defined ("write") without being
1156+
* used ("read"). That behavior, however, happens in the `processScopeClose`
1157+
* function using the data gathered by this function.
1158+
*
1159+
* Some variables are used in more complex ways, so there are other similar
1160+
* functions to this one, like `processVariableInString`, and
1161+
* `processCompact`. They have the same purpose as this function, though.
11441162
*
11451163
* @param File $phpcsFile The PHP_CodeSniffer file where this token was found.
11461164
* @param int $stackPtr The position where the token was found.
@@ -1159,7 +1177,7 @@ protected function processVariable(File $phpcsFile, $stackPtr) {
11591177
return;
11601178
}
11611179

1162-
// Determine if variable is being assigned or read.
1180+
// Determine if variable is being assigned ("write") or used ("read").
11631181

11641182
// Read methods that preempt assignment:
11651183
// Are we a $object->$property type symbolic reference?

0 commit comments

Comments
 (0)