我正在尝试使用 phpcs 获取类变量列表,但只能获取文件中所有变量的列表。有没有人对实现这一目标有任何想法?
嗅探代码
for ($i = $stackPtr; $i < count ($tokens); $i++) {
$variable = $phpcsFile->findNext(T_VARIABLE, ($i));
if ($variable !== false) {
print ($variable);
} else {
break;
}
}
要分析的文件
<?PHP
/**
* @package xxxx
* @subpackage Pro/System/Classes
* @copyright
* @author
* @link
*/
class Test_Class_AAA {
const CONSTANT = 'constant value';
public $var1 = 12;
const CONSTANT2 = 'constant value 2';
/**
* Return record schema details given a LabelIndentifier/LabelNumber or
* TransactionCode.
*
* @param string $type record type
* @param string $myextralongparam record type
* @return array record schema details (or null)
*/
private function func ($type,$myextralongparam) {
if (true) {
$x = 10;
$y = 11;
$z = $x + $y;
$f = $x - $y
$f = $x * $t;
$f = $x / $y;
$f = $x % $y;
$f = $x ** $y;
$f += 1;
$f -= 1;
$f *= 1;
$f /= 1;
$f %= 1;
if ($x === $y) {
}
if ($x !== $y) {
}
if ($x < $y) {
}
if ($x > $y) {
}
if ($x <= $y) {
}
if ($x >= $y) {
}
++$x;
} else {
}
while (true) {
}
do {
} while (true);
for ($i = 0; $i < 5; $i++) {
}
};
/**
* Return record schema details given a LabelIndentifier/LabelNumber or
* TransactionCode.
*
* @return array record schema details (or null)
*/
public function __construct () {
print "In BaseClass constructor\n";
}
}