Skip to content

Commit

Permalink
simplified #3
Browse files Browse the repository at this point in the history
  • Loading branch information
abbadon1334 committed Jul 11, 2019
1 parent 10a9d24 commit fb0db2e
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 61 deletions.
63 changes: 63 additions & 0 deletions docs/api/JuliusHaertl/PHPDocToRst/ApiDocBuilder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,66 @@ Methods



.. rst-class:: private

.. php:method:: private parseInterfaces( $file)
:Parameters:
* **$file** (:any:`phpDocumentor\\Reflection\\Php\\File <phpDocumentor\\Reflection\\Php\\File>`)


:Returns: array



.. rst-class:: private

.. php:method:: private parseClasses( $file)
:Parameters:
* **$file** (:any:`phpDocumentor\\Reflection\\Php\\File <phpDocumentor\\Reflection\\Php\\File>`)


:Returns: array



.. rst-class:: private

.. php:method:: private parseTraits( $file)
:Parameters:
* **$file** (:any:`phpDocumentor\\Reflection\\Php\\File <phpDocumentor\\Reflection\\Php\\File>`)





.. rst-class:: private

.. php:method:: private parseFunctions( $file)
:Parameters:
* **$file** (:any:`phpDocumentor\\Reflection\\Php\\File <phpDocumentor\\Reflection\\Php\\File>`)


:Returns: bool | string



.. rst-class:: private

.. php:method:: private parseConstants( $file)
:Parameters:
* **$file** (:any:`phpDocumentor\\Reflection\\Php\\File <phpDocumentor\\Reflection\\Php\\File>`)





166 changes: 105 additions & 61 deletions src/ApiDocBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,72 +200,18 @@ private function parseFiles()
foreach ($this->extensions as $extension) {
$extension->prepare();
}

$this->log('Start building files');

foreach ($this->project->getFiles() as $file) {
/**
* Go though interfaces/classes/functions of files and build documentation
*/
foreach ($file->getInterfaces() as $interface) {
$fqsen = $interface->getFqsen();
$builder = new InterfaceFileBuilder($file, $interface, $this->extensions);
$filename = $this->dstDir . str_replace('\\', '/', $fqsen) . '.rst';
file_put_contents($filename, $builder->getContent());
$this->docFiles[(string)$interface->getFqsen()] = str_replace('\\', '/', $fqsen);

// also build root namespace in indexes
if (strpos((string)substr($fqsen, 1), '\\') === false) {
$this->project->getRootNamespace()->addInterface($fqsen);
}
$this->debug('Written interface documentation to ' . $filename);
}

foreach ($file->getClasses() as $class) {
$fqsen = $class->getFqsen();
$builder = new ClassFileBuilder($file, $class, $this->extensions);
$filename = $this->dstDir . str_replace('\\', '/', $fqsen) . '.rst';
file_put_contents($filename, $builder->getContent());
$this->docFiles[(string)$class->getFqsen()] = str_replace('\\', '/', $fqsen);

// also build root namespace in indexes
if (strpos((string)substr($class->getFqsen(), 1), '\\') === false) {
$this->project->getRootNamespace()->addClass($fqsen);
}
$this->debug('Written class documentation to ' . $filename);
}

foreach ($file->getTraits() as $trait) {
$fqsen = $trait->getFqsen();
$builder = new TraitFileBuilder($file, $trait, $this->extensions);
$filename = $this->dstDir . str_replace('\\', '/', $fqsen) . '.rst';
file_put_contents($filename, $builder->getContent());
$this->docFiles[(string)$trait->getFqsen()] = str_replace('\\', '/', $fqsen);

// also build root namespace in indexes
if (strpos((string)substr($fqsen, 1), '\\') === false) {
$this->project->getRootNamespace()->addTrait($fqsen);
}
$this->debug('Written trait documentation to ' . $filename);
}

// build array of functions per namespace
foreach ($file->getFunctions() as $function) {
$namespace = substr(PhpDomainBuilder::getNamespace($function), 0, -2);
$namespace = $namespace === '' ? '\\' : $namespace;
if (!array_key_exists($namespace, $this->functions)) {
$this->functions[$namespace] = [];
}
$this->functions[$namespace][] = $function;
}
// build array of constants per namespace
foreach ($file->getConstants() as $constant) {
$namespace = PhpDomainBuilder::getNamespace($constant);
$namespace = $namespace === '' ? '\\' : $namespace;
if (!array_key_exists($namespace, $this->constants)) {
$this->constants[$namespace] = [];
}
$this->constants[$namespace][] = $constant;
}

$this->parseInterfaces($file);
$this->parseClasses($file);
$this->parseTraits($file);
$this->parseFunctions($file);
$this->parseConstants($file);
}
}

Expand Down Expand Up @@ -344,4 +290,102 @@ public function addExtension($class, $arguments = [])
$this->extensionNames[] = $class;
$this->extensionArguments[$class] = $arguments;
}

/**
* @param \phpDocumentor\Reflection\Php\File $file
*
* @return array
*/
private function parseInterfaces(\phpDocumentor\Reflection\Php\File $file): void
{
foreach ($file->getInterfaces() as $interface) {
$fqsen = $interface->getFqsen();
$builder = new InterfaceFileBuilder($file, $interface, $this->extensions);
$filename = $this->dstDir . str_replace('\\', '/', $fqsen) . '.rst';
file_put_contents($filename, $builder->getContent());
$this->docFiles[(string)$interface->getFqsen()] = str_replace('\\', '/', $fqsen);

// also build root namespace in indexes
if (strpos((string)substr($fqsen, 1), '\\') === false) {
$this->project->getRootNamespace()->addInterface($fqsen);
}
$this->debug('Written interface documentation to ' . $filename);
}
}

/**
* @param \phpDocumentor\Reflection\Php\File $file
*
* @return array
*/
private function parseClasses(\phpDocumentor\Reflection\Php\File $file): void
{
foreach ($file->getClasses() as $class) {
$fqsen = $class->getFqsen();
$builder = new ClassFileBuilder($file, $class, $this->extensions);
$filename = $this->dstDir . str_replace('\\', '/', $fqsen) . '.rst';
file_put_contents($filename, $builder->getContent());
$this->docFiles[(string)$class->getFqsen()] = str_replace('\\', '/', $fqsen);

// also build root namespace in indexes
if (strpos((string)substr($class->getFqsen(), 1), '\\') === false) {
$this->project->getRootNamespace()->addClass($fqsen);
}
$this->debug('Written class documentation to ' . $filename);
}
}

/**
* @param \phpDocumentor\Reflection\Php\File $file
*/
private function parseTraits(\phpDocumentor\Reflection\Php\File $file): void
{
foreach ($file->getTraits() as $trait) {
$fqsen = $trait->getFqsen();
$builder = new TraitFileBuilder($file, $trait, $this->extensions);
$filename = $this->dstDir . str_replace('\\', '/', $fqsen) . '.rst';
file_put_contents($filename, $builder->getContent());
$this->docFiles[(string)$trait->getFqsen()] = str_replace('\\', '/', $fqsen);

// also build root namespace in indexes
if (strpos((string)substr($fqsen, 1), '\\') === false) {
$this->project->getRootNamespace()->addTrait($fqsen);
}
$this->debug('Written trait documentation to ' . $filename);
}
}

/**
* @param \phpDocumentor\Reflection\Php\File $file
*
* @return bool|string
*/
private function parseFunctions(\phpDocumentor\Reflection\Php\File $file) :void
{
// build array of functions per namespace
foreach ($file->getFunctions() as $function) {
$namespace = substr(PhpDomainBuilder::getNamespace($function), 0, -2);
$namespace = $namespace === '' ? '\\' : $namespace;
if (!array_key_exists($namespace, $this->functions)) {
$this->functions[$namespace] = [];
}
$this->functions[$namespace][] = $function;
}
}

/**
* @param \phpDocumentor\Reflection\Php\File $file
*/
private function parseConstants(\phpDocumentor\Reflection\Php\File $file): void
{
// build array of constants per namespace
foreach ($file->getConstants() as $constant) {
$namespace = PhpDomainBuilder::getNamespace($constant);
$namespace = $namespace === '' ? '\\' : $namespace;
if (!array_key_exists($namespace, $this->constants)) {
$this->constants[$namespace] = [];
}
$this->constants[$namespace][] = $constant;
}
}
}

0 comments on commit fb0db2e

Please sign in to comment.