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);
     }
 }
Beispiel #3
0
 /**
  * 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);
 }
Beispiel #4
0
 /**
  * Will run an inspection for a certain file/directory and will return a version instance
  * resulting from the changes compared to former inspections
  *
  * @param string $srcPath Path to the file/directory to inspect
  *
  * @return \Herrera\Version\Builder
  *
  * @throws \Exception
  */
 public function runInspection($srcPath)
 {
     // check if we got something we can work with
     if (!is_readable($srcPath)) {
         throw new \Exception(sprintf('Cannot read from source path %s', $srcPath));
     }
     $broker = new Broker(new Memory());
     if (is_dir($srcPath)) {
         $broker->processDirectory($srcPath);
     } else {
         $broker->processFile($srcPath);
     }
     // iterate all php files and check for an API annotation
     $inspector = $this->getInspector();
     foreach ($broker->getClasses() as $classReflection) {
         // we can continue iteration if we did not get any valuable information from this file
         if (!$classReflection instanceof \TokenReflection\ReflectionClass) {
             continue;
         }
         // if we got the API annotation we have to work with it
         if ($classReflection->hasAnnotation(ApiAnnotation::ANNOTATION)) {
             $formerReflection = $this->cache->load($classReflection->getName());
             // check for possible changes
             $inspector->inspect($classReflection, $formerReflection);
             // save the current reflection object as a base for later comparison
             $this->cache->store($classReflection);
         }
     }
     // get the result and increment the version accordingly
     $result = $inspector->getResult();
     $incrementationMethod = 'increment' . ucfirst(strtolower($result->getIncrementVersion()));
     $version = $this->getBaseVersion();
     if (method_exists($version, $incrementationMethod)) {
         $version->{$incrementationMethod}();
     }
     return $version;
 }