/** * @covers phpDocumentor\Descriptor\ProjectDescriptor::__construct * @covers phpDocumentor\Descriptor\ProjectDescriptor::setFiles * @covers phpDocumentor\Descriptor\ProjectDescriptor::getFiles */ public function testGetSetFiles() { $this->assertInstanceOf('phpDocumentor\\Descriptor\\Collection', $this->fixture->getFiles()); $filesCollection = new Collection(); $this->fixture->setFiles($filesCollection); $this->assertSame($filesCollection, $this->fixture->getFiles()); }
/** * This method generates the checkstyle.xml report * * @param ProjectDescriptor $project Document containing the structure. * @param Transformation $transformation Transformation to execute. * * @return void */ public function transform(ProjectDescriptor $project, Transformation $transformation) { $artifact = $this->getDestinationPath($transformation); $this->checkForSpacesInPath($artifact); $document = new \DOMDocument(); $document->formatOutput = true; $report = $document->createElement('checkstyle'); $report->setAttribute('version', '1.3.0'); $document->appendChild($report); /** @var FileDescriptor $fileDescriptor */ foreach ($project->getFiles()->getAll() as $fileDescriptor) { $file = $document->createElement('file'); $file->setAttribute('name', $fileDescriptor->getPath()); $report->appendChild($file); /** @var Error $error */ foreach ($fileDescriptor->getAllErrors()->getAll() as $error) { $item = $document->createElement('error'); $item->setAttribute('line', $error->getLine()); $item->setAttribute('severity', $error->getSeverity()); $item->setAttribute('message', vsprintf($this->getTranslator()->translate($error->getCode()), $error->getContext())); $item->setAttribute('source', 'phpDocumentor.file.' . $error->getCode()); $file->appendChild($item); } } $this->saveCheckstyleReport($artifact, $document); }
/** * {@inheritDoc} */ public function execute(ProjectDescriptor $project) { $elementCollection = new Collection(); $project->getIndexes()->set('elements', $elementCollection); $constantsIndex = $project->getIndexes()->get('constants', new Collection()); $functionsIndex = $project->getIndexes()->get('functions', new Collection()); $classesIndex = $project->getIndexes()->get('classes', new Collection()); $interfacesIndex = $project->getIndexes()->get('interfaces', new Collection()); $traitsIndex = $project->getIndexes()->get('traits', new Collection()); foreach ($project->getFiles() as $file) { $this->addElementsToIndexes($file->getConstants()->getAll(), array($constantsIndex, $elementCollection)); $this->addElementsToIndexes($file->getFunctions()->getAll(), array($functionsIndex, $elementCollection)); foreach ($file->getClasses()->getAll() as $element) { $this->addElementsToIndexes($element, array($classesIndex, $elementCollection)); $this->addElementsToIndexes($this->getSubElements($element), array($elementCollection)); } foreach ($file->getInterfaces()->getAll() as $element) { $this->addElementsToIndexes($element, array($interfacesIndex, $elementCollection)); $this->addElementsToIndexes($this->getSubElements($element), array($elementCollection)); } foreach ($file->getTraits()->getAll() as $element) { $this->addElementsToIndexes($element, array($traitsIndex, $elementCollection)); $this->addElementsToIndexes($this->getSubElements($element), array($elementCollection)); } } }
/** * {@inheritDoc} */ public function execute(ProjectDescriptor $project) { $project->getIndexes()->get('elements', new Collection())->set('~\\', $project->getNamespace()); $project->getIndexes()->get('namespaces', new Collection())->add($project->getNamespace()); foreach ($project->getFiles() as $file) { $this->addElementsOfTypeToNamespace($project, $file->getConstants()->getAll(), 'constants'); $this->addElementsOfTypeToNamespace($project, $file->getFunctions()->getAll(), 'functions'); $this->addElementsOfTypeToNamespace($project, $file->getClasses()->getAll(), 'classes'); $this->addElementsOfTypeToNamespace($project, $file->getInterfaces()->getAll(), 'interfaces'); $this->addElementsOfTypeToNamespace($project, $file->getTraits()->getAll(), 'traits'); } }
/** * {@inheritDoc} */ public function execute(ProjectDescriptor $project) { $project->getIndexes()->set('packages', new Collection()); $project->getIndexes()->packages['\\'] = new PackageDescriptor(); foreach ($project->getFiles() as $file) { $this->addElementsOfTypeToPackage($project, $file->getConstants()->getAll(), 'constants'); $this->addElementsOfTypeToPackage($project, $file->getFunctions()->getAll(), 'functions'); $this->addElementsOfTypeToPackage($project, $file->getClasses()->getAll(), 'classes'); $this->addElementsOfTypeToPackage($project, $file->getInterfaces()->getAll(), 'interfaces'); $this->addElementsOfTypeToPackage($project, $file->getTraits()->getAll(), 'traits'); } }
/** * @covers phpDocumentor\Compiler\Pass\PackageTreeBuilder::execute * @covers phpDocumentor\Compiler\Pass\PackageTreeBuilder::addElementsOfTypeToPackage */ public function testAddFunctionToNamespace() { $function = new FunctionDescriptor(); $function->setPackage('My\\Space'); $function->setFullyQualifiedStructuralElementName('My\\Space\\Function1'); $this->project->getFiles()->get(0)->getFunctions()->add($function); // double check if a second function in the same deep namespace ends up at the right location $function2 = new FunctionDescriptor(); $function2->setPackage('My\\Space'); $function2->setFullyQualifiedStructuralElementName('My\\Space\\Function2'); $this->project->getFiles()->get(0)->getFunctions()->add($function2); $this->fixture->execute($this->project); $this->assertSame(array($function, $function2), $this->project->getIndexes()->get('packages')->get('\\My\\Space')->getFunctions()->getAll()); }
/** * @covers phpDocumentor\Compiler\Pass\ElementsIndexBuilder::execute * @covers phpDocumentor\Compiler\Pass\ElementsIndexBuilder::addElementsToIndexes * @covers phpDocumentor\Compiler\Pass\ElementsIndexBuilder::getIndexKey * @covers phpDocumentor\Compiler\Pass\ElementsIndexBuilder::getSubElements */ public function testAddMethodsToIndex() { $file1 = $this->project->getFiles()->get(0); $classDescriptor1 = new ClassDescriptor(); $classDescriptor1->setFullyQualifiedStructuralElementName('My\\Space\\Class1'); $file1->getClasses()->add($classDescriptor1); $classMethodDescriptor1 = new MethodDescriptor(); $classMethodDescriptor1->setFullyQualifiedStructuralElementName('My\\Space\\Class1::METHOD'); $classDescriptor1->getMethods()->add($classMethodDescriptor1); $file2 = $this->project->getFiles()->get(1); $classDescriptor2 = new ClassDescriptor(); $classDescriptor2->setFullyQualifiedStructuralElementName('My\\Space\\Class2'); $file2->getClasses()->add($classDescriptor2); $classMethodDescriptor2 = new MethodDescriptor(); $classMethodDescriptor2->setFullyQualifiedStructuralElementName('My\\Space\\Class2::METHOD'); $classDescriptor2->getMethods()->add($classMethodDescriptor2); $this->fixture->execute($this->project); $elements = $this->project->getIndexes()->get('elements')->getAll(); $this->assertCount(4, $elements); $this->assertSame(array('My\\Space\\Class1', 'My\\Space\\Class1::METHOD', 'My\\Space\\Class2', 'My\\Space\\Class2::METHOD'), array_keys($elements)); $this->assertSame(array($classDescriptor1, $classMethodDescriptor1, $classDescriptor2, $classMethodDescriptor2), array_values($elements)); // class methods are not indexed separately $this->assertNull($this->project->getIndexes()->get('methods')); }
/** * Stores a Project Descriptor in the Cache. * * @param ProjectDescriptor $projectDescriptor * * @return void */ public function save(ProjectDescriptor $projectDescriptor) { $keys = array(); $cache = $this->getCache(); /** @var IteratorInterface $iteratorInterface */ $iteratorInterface = $cache->getIterator(); // FIXME: Workaround for: https://github.com/zendframework/zf2/pull/4154 if ($iteratorInterface->valid()) { foreach ($cache as $key) { $keys[] = $key; } } // store the settings for this Project Descriptor $cache->setItem(self::KEY_SETTINGS, $projectDescriptor->getSettings()); // store cache items $usedKeys = array(); foreach ($projectDescriptor->getFiles() as $file) { $key = self::FILE_PREFIX . md5($file->getPath()); $usedKeys[] = $key; $cache->setItem($key, $file); } // remove any keys that are no longer used. $invalidatedKeys = array_diff($keys, $usedKeys); if ($invalidatedKeys) { $cache->removeItems($invalidatedKeys); } if ($cache instanceof OptimizableInterface) { $cache->optimize(); } }
/** * This method generates the AST output * * @param ProjectDescriptor $project Document containing the structure. * @param Transformation $transformation Transformation to execute. * * @return void */ public function transform(ProjectDescriptor $project, Transformation $transformation) { $artifact = $this->getDestinationPath($transformation); $this->xml = new \DOMDocument('1.0', 'utf-8'); $this->xml->formatOutput = true; $document_element = new \DOMElement('project'); $this->xml->appendChild($document_element); $document_element->setAttribute('title', $project->getName()); $document_element->setAttribute('version', Application::$VERSION); $transformer = $transformation->getTransformer(); foreach ($project->getFiles() as $file) { $this->buildFile($document_element, $file, $transformer); } $this->finalize($project); file_put_contents($artifact, $this->xml->saveXML()); }
/** * This method writes every source code entry in the structure file to a highlighted file. * * @param ProjectDescriptor $project Document containing the structure. * @param Transformation $transformation Transformation to execute. * * @return void */ public function transform(ProjectDescriptor $project, Transformation $transformation) { $artifact = $transformation->getTransformer()->getTarget() . DIRECTORY_SEPARATOR . ($transformation->getArtifact() ? $transformation->getArtifact() : 'source'); /** @var FileDescriptor $file */ foreach ($project->getFiles() as $file) { $filename = $file->getPath(); $source = $file->getSource(); $root = str_repeat('../', count(explode(DIRECTORY_SEPARATOR, $filename))); $path = $artifact . DIRECTORY_SEPARATOR . $filename; if (!file_exists(dirname($path))) { mkdir(dirname($path), 0755, true); } $source = htmlentities($source); file_put_contents($path . '.html', <<<HTML <html> <head> <script type="text/javascript" src="{$root}js/jquery-1.4.2.min.js"> </script> <script type="text/javascript" src="{$root}syntax_highlighter/scripts/shCore.js"> </script> <script type="text/javascript" src="{$root}syntax_highlighter/scripts/shBrushJScript.js"> </script> <script type="text/javascript" src="{$root}syntax_highlighter/scripts/shBrushPhp.js"> </script> <script type="text/javascript" src="{$root}syntax_highlighter/scripts/shBrushXml.js"> </script> <link href="{$root}syntax_highlighter/styles/shCore.css" rel="stylesheet" type="text/css" /> <link href="{$root}syntax_highlighter/styles/shCoreEclipse.css" rel="stylesheet" type="text/css" /> <link href="{$root}syntax_highlighter/styles/shThemeWordpress.css" rel="stylesheet" type="text/css" /> </head> <body> <pre class="brush: php">{$source}</pre> <script type="text/javascript"> SyntaxHighlighter.all() jQuery('.gutter div').each(function(key, data){ jQuery(data).prepend('<a name="L'+jQuery(data).text()+'"/>'); }); </script> </body> </html> HTML ); } }
/** * Get number of markers. * * @param ProjectDescriptor $project * * @return int */ protected function getMarkerCounter(ProjectDescriptor $project) { $markerCounter = 0; /* @var $fileDescriptor FileDescriptor */ foreach ($project->getFiles()->getAll() as $fileDescriptor) { $markerCounter += $fileDescriptor->getMarkers()->count(); } return $markerCounter; }