public function satisfy(array $configuration, AstClassReferenceInterface $classReference, AstMap $astMap, CollectorFactory $collectorFactory, AstParserInterface $astParser)
 {
     if (!$astParser instanceof NikicPhpParser) {
         return false;
     }
     $ast = $astParser->getAstForClassname($classReference->getClassName());
     /** @var $classMethods ClassMethod[] */
     $classMethods = $astParser->findNodesOfType($ast, ClassMethod::class);
     foreach ($classMethods as $classMethod) {
         if (preg_match('/' . $this->getMethodNameRegexByConfiguration($configuration) . '/i', $classMethod->name, $collectorFactory)) {
             return true;
         }
     }
     return false;
 }
Beispiel #2
0
 /**
  * @param AstInheritInterface $inheritDependency
  * @param \ArrayObject|null $alreadyResolved
  * @param \SplStack|null $path
  * @return array
  */
 private function resolveDepsRecursive(AstInheritInterface $inheritDependency, \ArrayObject $alreadyResolved = null, \SplStack $path = null)
 {
     if ($alreadyResolved == null) {
         $alreadyResolved = new \ArrayObject();
     }
     if ($path == null) {
         $path = new \SplStack();
         $path->push($inheritDependency);
     }
     if (isset($alreadyResolved[$inheritDependency->getClassName()])) {
         $path->pop();
         return [];
     }
     $buffer = [];
     foreach ($this->astParser->findInheritanceByClassname($inheritDependency->getClassName()) as $inherit) {
         $alreadyResolved[$inheritDependency->getClassName()] = true;
         $buffer[] = new FlattenAstInherit($inherit, iterator_to_array($path));
         $path->push($inherit);
         foreach ($this->resolveDepsRecursive($inherit, $alreadyResolved, $path) as $dep) {
             $buffer[] = $dep;
         }
         unset($alreadyResolved[$inheritDependency->getClassName()]);
         $path->pop();
     }
     return $buffer;
 }
Beispiel #3
0
 /**
  * @param AstParserInterface $astParser
  * @param EventDispatcherInterface $dispatcher
  * @param array $files
  * @return AstMap
  */
 public function createAstMapByFiles(AstParserInterface $astParser, EventDispatcherInterface $dispatcher, array $files)
 {
     $dispatcher->dispatch(PreCreateAstMapEvent::class, new PreCreateAstMapEvent(count($files)));
     $astMap = new AstMap($astParser);
     foreach ($files as $file) {
         try {
             foreach ($astParser->parse($file) as $astReference) {
                 if ($astReference instanceof AstClassReferenceInterface) {
                     $astMap->addAstClassReference($astReference);
                 } elseif ($astReference instanceof AstFileReferenceInterface) {
                     $astMap->addAstFileReferences($astReference);
                 } else {
                     throw new \LogicException('unknown AST Type.');
                 }
             }
             $dispatcher->dispatch(AstFileAnalyzedEvent::class, new AstFileAnalyzedEvent($file));
         } catch (\PhpParser\Error $e) {
             $dispatcher->dispatch(AstFileSyntaxErrorEvent::class, new AstFileSyntaxErrorEvent($file, $e->getMessage()));
         }
     }
     $dispatcher->dispatch(PostCreateAstMapEvent::class, new PostCreateAstMapEvent($astMap));
     return $astMap;
 }