本文整理匯總了PHP中PhpCsFixer\Tokenizer\TokensAnalyzer::getClassyElements方法的典型用法代碼示例。如果您正苦於以下問題:PHP TokensAnalyzer::getClassyElements方法的具體用法?PHP TokensAnalyzer::getClassyElements怎麽用?PHP TokensAnalyzer::getClassyElements使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PhpCsFixer\Tokenizer\TokensAnalyzer
的用法示例。
在下文中一共展示了TokensAnalyzer::getClassyElements方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: fix
/**
* {@inheritdoc}
*/
public function fix(\SplFileInfo $file, Tokens $tokens)
{
$analyzer = new TokensAnalyzer($tokens);
$elements = array_reverse($analyzer->getClassyElements(), true);
foreach ($elements as $index => $element) {
if (!in_array($element['type'], $this->configuration, true)) {
continue;
// not in configuration
}
$this->fixElement($tokens, $index);
}
}
示例2: testGetClassyElements
public function testGetClassyElements()
{
$source = <<<'PHP'
<?php
class Foo
{
public $prop0;
protected $prop1;
private $prop2 = 1;
var $prop3 = array(1,2,3);
const CONSTANT = 'constant value';
public function bar4()
{
$a = 5;
return " ({$a})";
}
public function bar5($data)
{
$message = $data;
$example = function ($arg) use ($message) {
echo $arg . ' ' . $message;
};
$example('hello');
}
}
function test(){}
class Foo2
{
const CONSTANT = 'constant value';
}
PHP;
$tokens = Tokens::fromCode($source);
$tokensAnalyzer = new TokensAnalyzer($tokens);
$elements = array_values($tokensAnalyzer->getClassyElements());
$this->assertCount(8, $elements);
$this->assertSame('property', $elements[0]['type']);
$this->assertSame('property', $elements[1]['type']);
$this->assertSame('property', $elements[2]['type']);
$this->assertSame('property', $elements[3]['type']);
$this->assertSame('const', $elements[4]['type']);
$this->assertSame('method', $elements[5]['type']);
$this->assertSame('method', $elements[6]['type']);
$this->assertSame('const', $elements[7]['type']);
}
示例3: fix
/**
* {@inheritdoc}
*/
public function fix(\SplFileInfo $file, Tokens $tokens)
{
$tokensAnalyzer = new TokensAnalyzer($tokens);
$elements = $tokensAnalyzer->getClassyElements();
foreach (array_reverse($elements, true) as $index => $element) {
if ('method' === $element['type']) {
$this->overrideAttribs($tokens, $index, $this->grabAttribsBeforeMethodToken($tokens, $index));
// force whitespace between function keyword and function name to be single space char
$afterToken = $tokens[++$index];
if ($afterToken->isWhitespace()) {
$afterToken->setContent(' ');
}
} elseif ('property' === $element['type']) {
$prevIndex = $tokens->getPrevTokenOfKind($index, array(';', ',', '{'));
if (!$prevIndex || !$tokens[$prevIndex]->equals(',')) {
$this->overrideAttribs($tokens, $index, $this->grabAttribsBeforePropertyToken($tokens, $index));
}
}
}
}
示例4: fix
/**
* {@inheritdoc}
*/
public function fix(\SplFileInfo $file, Tokens $tokens)
{
$tokensAnalyzer = new TokensAnalyzer($tokens);
$elements = $tokensAnalyzer->getClassyElements();
foreach (array_reverse($elements, true) as $index => $element) {
if (!in_array($element['type'], $this->configuration, true)) {
continue;
}
switch ($element['type']) {
case 'method':
$this->fixMethodVisibility($tokens, $index);
break;
case 'property':
$this->fixPropertyVisibility($tokens, $index);
break;
case 'const':
$this->fixConstVisibility($tokens, $index);
break;
}
}
}