private function extractBrokerDataForParserResult(Broker $broker) { $allFoundClasses = $broker->getClasses(Backend::TOKENIZED_CLASSES | Backend::INTERNAL_CLASSES | Backend::NONEXISTENT_CLASSES); $classes = new ArrayObject($allFoundClasses); $constants = new ArrayObject($broker->getConstants()); $functions = new ArrayObject($broker->getFunctions()); $internalClasses = new ArrayObject($broker->getClasses(Backend::INTERNAL_CLASSES)); $tokenizedClasses = new ArrayObject($broker->getClasses(Backend::TOKENIZED_CLASSES)); $classes->uksort('strcasecmp'); $constants->uksort('strcasecmp'); $functions->uksort('strcasecmp'); $this->loadToParserResult($classes, $constants, $functions, $internalClasses, $tokenizedClasses); }
/** * Compares items parsed from filesystem and from a PHAR archive. * * @param \TokenReflection\Broker $filesystem Filesystem TR broker * @param \TokenReflection\Broker $phar PHAR TR broker * @param integer $format PHAR archive format * @param integer $compression PHAR archive compression * @param integer $wholeArchive Whole archive compressed */ private function archiveTest(Broker $filesystem, Broker $phar, $format, $compression, $wholeArchive) { $fsConstants = $filesystem->getConstants(); $pharConstants = $phar->getConstants(); $this->assertSame(count($fsConstants), count($pharConstants)); foreach (array_keys($fsConstants) as $name) { $this->assertArrayHasKey($name, $pharConstants); } $fsClasses = $filesystem->getClasses(); $pharClasses = $phar->getClasses(); $this->assertSame(count($fsClasses), count($pharClasses)); foreach (array_keys($fsClasses) as $name) { $this->assertArrayHasKey($name, $pharClasses); } $fsFunctions = $filesystem->getFunctions(); $pharFunctions = $phar->getFunctions(); $this->assertSame(count($fsFunctions), count($pharFunctions)); foreach (array_keys($fsFunctions) as $name) { $this->assertArrayHasKey($name, $pharFunctions); } }
/** * Scans and parses PHP files. * * @return array * @throws \RuntimeException If no PHP files have been found. */ public function parse() { $files = array(); $flags = \RecursiveDirectoryIterator::CURRENT_AS_FILEINFO | \RecursiveDirectoryIterator::SKIP_DOTS; if (defined('\\RecursiveDirectoryIterator::FOLLOW_SYMLINKS')) { // Available from PHP 5.3.1 $flags |= \RecursiveDirectoryIterator::FOLLOW_SYMLINKS; } foreach ($this->config->source as $source) { $entries = array(); if (is_dir($source)) { foreach (new \RecursiveIteratorIterator(new SourceFilesFilterIterator(new \RecursiveDirectoryIterator($source, $flags), $this->config->exclude)) as $entry) { if (!$entry->isFile()) { continue; } $entries[] = $entry; } } elseif ($this->isPhar($source)) { if (!extension_loaded('phar')) { throw new RuntimeException('Phar extension is not loaded'); } foreach (new \RecursiveIteratorIterator(new \Phar($source, $flags)) as $entry) { if (!$entry->isFile()) { continue; } $entries[] = $entry; } } else { $entries[] = new \SplFileInfo($source); } $regexp = '~\\.' . implode('|', $this->config->extensions->toArray()) . '$~i'; foreach ($entries as $entry) { if (!preg_match($regexp, $entry->getFilename())) { continue; } $pathName = $this->normalizePath($entry->getPathName()); $files[$pathName] = $entry->getSize(); if (false !== $entry->getRealPath() && $pathName !== $entry->getRealPath()) { $this->symlinks[$entry->getRealPath()] = $pathName; } } } if (empty($files)) { throw new RuntimeException('No PHP files found'); } $this->fireEvent('parseStart', array_sum($files)); $broker = new Broker(new Backend($this, !empty($this->config->report)), Broker::OPTION_DEFAULT & ~(Broker::OPTION_PARSE_FUNCTION_BODY | Broker::OPTION_SAVE_TOKEN_STREAM)); $errors = array(); foreach ($files as $filePath => $size) { $content = $this->charsetConvertor->convertFile($filePath); try { $broker->processString($content, $filePath); } catch (\Exception $e) { $errors[] = $e; } $this->fireEvent('parseProgress', $size); } // Classes $this->parsedClasses->exchangeArray($broker->getClasses(Backend::TOKENIZED_CLASSES | Backend::INTERNAL_CLASSES | Backend::NONEXISTENT_CLASSES)); $this->parsedClasses->uksort('strcasecmp'); // Constants $this->parsedConstants->exchangeArray($broker->getConstants()); $this->parsedConstants->uksort('strcasecmp'); // Functions $this->parsedFunctions->exchangeArray($broker->getFunctions()); $this->parsedFunctions->uksort('strcasecmp'); $documentedCounter = function ($count, $element) { return $count += (int) $element->isDocumented(); }; return (object) array('classes' => count($broker->getClasses(Backend::TOKENIZED_CLASSES)), 'constants' => count($this->parsedConstants), 'functions' => count($this->parsedFunctions), 'internalClasses' => count($broker->getClasses(Backend::INTERNAL_CLASSES)), 'documentedClasses' => array_reduce($broker->getClasses(Backend::TOKENIZED_CLASSES), $documentedCounter), 'documentedConstants' => array_reduce($this->parsedConstants->getArrayCopy(), $documentedCounter), 'documentedFunctions' => array_reduce($this->parsedFunctions->getArrayCopy(), $documentedCounter), 'documentedInternalClasses' => array_reduce($broker->getClasses(Backend::INTERNAL_CLASSES), $documentedCounter), 'errors' => $errors); }