PHPSA\Analyzer::registerScalarPasses PHP 메소드

registerScalarPasses() 공개 메소드

public registerScalarPasses ( array $scalarPasses )
$scalarPasses array all the scalar analyzers
    public function registerScalarPasses(array $scalarPasses)
    {
        foreach ($scalarPasses as $pass) {
            if (!$pass instanceof AnalyzerPassInterface) {
                throw new \RuntimeException('Analyzer pass must implement AnalyzerPassInterface');
            }
            $bindOnScalars = $pass->getRegister();
            foreach ($bindOnScalars as $bindOnScalar) {
                if (isset($this->bindOnScalars[$bindOnScalar])) {
                    $this->bindOnScalars[$bindOnScalar][] = $pass;
                } else {
                    $this->bindOnScalars[$bindOnScalar] = [$pass];
                }
            }
        }
    }

Usage Example

예제 #1
0
파일: Factory.php 프로젝트: ovr/phpsa
 /**
  * @param EventManager $eventManager
  * @param Configuration $config
  * @return Analyzer
  */
 public static function factory(EventManager $eventManager, Configuration $config)
 {
     $analyzersConfig = $config->getValue('analyzers');
     $filterEnabled = function ($passClass) use($config, $analyzersConfig) {
         /** @var AnalyzerPass\Metadata $passMetadata */
         $passMetadata = $passClass::getMetadata();
         if (!isset($analyzersConfig[$passMetadata->getName()])) {
             return false;
         }
         if (!$analyzersConfig[$passMetadata->getName()]['enabled']) {
             return false;
         }
         if (!$passMetadata->allowsPhpVersion($config->getValue('language_level'))) {
             return false;
         }
         return true;
     };
     $instanciate = function ($passClass) use($analyzersConfig) {
         $passName = $passClass::getMetadata()->getName();
         return new $passClass($analyzersConfig[$passName]);
     };
     $analyzer = new Analyzer($eventManager);
     $analyzer->registerExpressionPasses(array_map($instanciate, array_filter(self::getExpressionPasses(), $filterEnabled)));
     $analyzer->registerStatementPasses(array_map($instanciate, array_filter(self::getStatementPasses(), $filterEnabled)));
     $analyzer->registerScalarPasses(array_map($instanciate, array_filter(self::getScalarPasses(), $filterEnabled)));
     $analyzer->bind();
     return $analyzer;
 }