本文整理汇总了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;
}
}
}