當前位置: 首頁>>代碼示例>>PHP>>正文


PHP TokensAnalyzer::getClassyElements方法代碼示例

本文整理匯總了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);
     }
 }
開發者ID:fabpot,項目名稱:php-cs-fixer,代碼行數:15,代碼來源:SingleClassElementPerStatementFixer.php

示例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']);
    }
開發者ID:GrahamForks,項目名稱:PHP-CS-Fixer,代碼行數:49,代碼來源:TokensAnalyzerTest.php

示例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));
             }
         }
     }
 }
開發者ID:cryode,項目名稱:PHP-CS-Fixer,代碼行數:23,代碼來源:VisibilityRequiredFixer.php

示例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;
         }
     }
 }
開發者ID:friendsofphp,項目名稱:php-cs-fixer,代碼行數:24,代碼來源:VisibilityRequiredFixer.php


注:本文中的PhpCsFixer\Tokenizer\TokensAnalyzer::getClassyElements方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。