2017-05-19 2 views
2

私はphpcsを使ってクラス変数のリストを取得しようとしていますが、ファイル内のすべての変数のリストしか取得できません。誰もこれを達成するためのアイデアを持っていますか?phpcsですべてのphpメンバー変数を取得する方法

スニフコード

for ($i = $stackPtr; $i < count ($tokens); $i++) { 
    $variable = $phpcsFile->findNext(T_VARIABLE, ($i)); 
    if ($variable !== false) { 
     print ($variable); 
    } else { 
     break; 
    } 
} 

私はこれらのユースケースのために正確にClassWrapperをした

<?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"; 
    } 
} 
+1

私はあなたが何をしたいのか、100%わからないんだけど、通常、あなたがAbstractVariableSniffを使用し、唯一のメンバーVARSを処理するためにそれを使うだろう。例はここにあります:https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/PEAR/Sniffs/NamingConventions/ValidVariableNameSniff.php –

答えて

1

を分析するためのファイル。

あなたは、ここにin getPropertyNames() methodをインスピレーションを見つけることができます:

/** 
* Inspired by @see TokensAnalyzer. 
* 
* @return string[] 
*/ 
public function getPropertyNames(): array 
{ 
    if ($this->propertyNames) { 
     return $this->propertyNames; 
    } 

    $classOpenerPosition = $this->classToken['scope_opener'] + 1; 
    $classCloserPosition = $this->classToken['scope_closer'] - 1; 

    $propertyTokens = $this->findClassLevelTokensType($classOpenerPosition, $classCloserPosition, T_VARIABLE); 

    $this->propertyNames = $this->extractPropertyNamesFromPropertyTokens($propertyTokens); 
    $this->propertyNames = array_merge($this->propertyNames, $this->getParentClassPropertyNames()); 

    return $this->propertyNames; 
} 
関連する問題