public function compile(Context $context)
{
$context->scopePointer = null;
/**
* @todo Implement class map...
*/
foreach ($this->classes as $class) {
$extends = $class->getExtendsClass();
if ($extends) {
if (isset($this->classes[$extends])) {
$class->setExtendsClassDefinition($this->classes[$extends]);
} else {
if (class_exists($extends, true)) {
$class->setExtendsClassDefinition(new RuntimeClassDefinition(new ReflectionClass($extends)));
}
}
}
}
foreach ($this->functions as $function) {
/**
* @todo Configuration
*
* Ignore functions compiling from vendor
*/
$checkVendor = strpos($function->getFilepath(), './vendor');
if ($checkVendor !== false && $checkVendor < 3) {
continue;
}
$function->compile($context);
}
foreach ($this->traits as $trait) {
/**
* @todo Configuration
*
* Ignore traits compiling from vendor
*/
$checkVendor = strpos($trait->getFilepath(), './vendor');
if ($checkVendor !== false && $checkVendor < 3) {
continue;
}
$trait->compile($context);
}
foreach ($this->classes as $class) {
/**
* @todo Configuration
*
* Ignore Classes compiling from vendor
*/
$checkVendor = strpos($class->getFilepath(), './vendor');
if ($checkVendor !== false && $checkVendor < 3) {
continue;
}
$class->compile($context);
}
}
/** * @dataProvider provideTestParseAndDump * * @param $file * @param string $analyzer * @param string $expectedDump * @throws \PHPSA\Exception\RuntimeException * @throws \Webiny\Component\EventManager\EventManagerException */ public function testParseAndDump($file, $analyzer, $expectedDump) { $compiler = new Compiler(); $fileParser = new FileParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7, new \PhpParser\Lexer\Emulative(array('usedAttributes' => array('comments', 'startLine', 'endLine', 'startTokenPos', 'endTokenPos')))), $compiler); $context = new Context(new \Symfony\Component\Console\Output\NullOutput(), $application = new Application(), $this->getEventManager($analyzer)); $application->compiler = $compiler; $fileParser->parserFile($file, $context); $compiler->compile($context); $expectedArray = json_decode($expectedDump, true); $expectedType = $expectedArray[0]["type"]; $issues = array_map(function (Issue $issue) { $location = $issue->getLocation(); return ['type' => $issue->getCheckName(), 'message' => $issue->getDescription(), 'file' => $location->getFileName(), 'line' => $location->getLineStart()]; }, $application->getIssuesCollector()->getIssues()); foreach ($expectedArray as $check) { self::assertContains($check, $issues, $file); // every expected Issue is in the collector } foreach ($issues as $check) { if ($check["type"] == $expectedType) { self::assertContains($check, $expectedArray, $file); // there is no other issue in the collector with the same type } } }