diff --git a/dev/src/DocGenerator/Command/Docs.php b/dev/src/DocGenerator/Command/Docs.php index 92be58916dd0..3ce2075ea814 100644 --- a/dev/src/DocGenerator/Command/Docs.php +++ b/dev/src/DocGenerator/Command/Docs.php @@ -122,7 +122,7 @@ private function generateComponentDocumentation( $tocTemplate, $release = false, $pretty = false, - $linkCrossComponent = true + $isComponent = true ) { $output->writeln(sprintf('Writing documentation for %s', $component['id'])); $output->writeln('--------------'); @@ -145,7 +145,7 @@ private function generateComponentDocumentation( $component['id'], $paths['manifest'], $release, - $linkCrossComponent + $isComponent ); $docs->generate($component['path'], $pretty); diff --git a/dev/src/DocGenerator/DocGenerator.php b/dev/src/DocGenerator/DocGenerator.php index 28ccfea0c057..5d1736a96127 100644 --- a/dev/src/DocGenerator/DocGenerator.php +++ b/dev/src/DocGenerator/DocGenerator.php @@ -35,7 +35,7 @@ class DocGenerator private $componentId; private $manifestPath; private $release; - private $linkCrossComponent; + private $isComponent; /** * @param array $files @@ -48,7 +48,7 @@ public function __construct( $componentId, $manifestPath, $release, - $linkCrossComponent = true + $isComponent = true ) { $this->types = $types; $this->files = $files; @@ -57,7 +57,7 @@ public function __construct( $this->componentId = $componentId; $this->manifestPath = $manifestPath; $this->release = $release; - $this->linkCrossComponent = $linkCrossComponent; + $this->isComponent = $isComponent; } /** @@ -88,7 +88,7 @@ public function generate($basePath, $pretty) $this->componentId, $this->manifestPath, $this->release, - $this->linkCrossComponent + $this->isComponent ); } else { $content = file_get_contents($file); @@ -104,7 +104,7 @@ public function generate($basePath, $pretty) $this->types->addType([ 'id' => $document['id'], 'title' => $document['title'], - 'contents' => ($this->linkCrossComponent) + 'contents' => ($this->isComponent) ? $this->prune($document['id'] . '.json') : $document['id'] . '.json' ]); diff --git a/dev/src/DocGenerator/Parser/CodeParser.php b/dev/src/DocGenerator/Parser/CodeParser.php index 89701460e14c..a88ed87a166c 100644 --- a/dev/src/DocGenerator/Parser/CodeParser.php +++ b/dev/src/DocGenerator/Parser/CodeParser.php @@ -31,8 +31,10 @@ class CodeParser implements ParserInterface const SNIPPET_NAME_REGEX = '/\/\/\s?\[snippet\=(\w{0,})\]/'; + private static $composerFiles = []; + private $path; - private $outputName; + private $fileName; private $reflector; private $markdown; private $projectRoot; @@ -40,20 +42,20 @@ class CodeParser implements ParserInterface private $componentId; private $manifestPath; private $release; - private $linkCrossComponent; + private $isComponent; public function __construct( $path, - $outputName, + $fileName, FileReflector $reflector, $projectRoot, $componentId, $manifestPath, $release, - $linkCrossComponent = true + $isComponent = true ) { $this->path = $path; - $this->outputName = $outputName; + $this->fileName = $fileName; $this->reflector = $reflector; $this->markdown = \Parsedown::instance(); $this->projectRoot = $projectRoot; @@ -61,7 +63,7 @@ public function __construct( $this->componentId = $componentId; $this->manifestPath = $manifestPath; $this->release = $release; - $this->linkCrossComponent = $linkCrossComponent; + $this->isComponent = $isComponent; } public function parse() @@ -84,7 +86,7 @@ private function getReflector($fileReflector) return $fileReflector->getTraits()[0]; } - throw new \Exception('Could not get reflector for '. $this->outputName); + throw new \Exception('Could not get reflector for '. $this->fileName); } private function buildDocument($reflector) @@ -219,7 +221,7 @@ private function buildMethod($method) 'id' => $method->getName(), 'type' => $method->getName() === '__construct' ? 'constructor' : 'instance', 'name' => $method->getName(), - 'source' => $this->outputName . '#L' . $method->getLineNumber(), + 'source' => $this->getSource() . '#L' . $method->getLineNumber(), 'description' => $this->buildDescription($docBlock, $split['description']), 'examples' => $this->buildExamples($split['examples']), 'resources' => $this->buildResources($resources), @@ -252,7 +254,7 @@ private function buildMagicMethod($magicMethod) 'id' => $magicMethod->getMethodName(), 'type' => $magicMethod->getMethodName() === '__construct' ? 'constructor' : 'instance', 'name' => $magicMethod->getMethodName(), - 'source' => $this->outputName, + 'source' => $this->getSource(), 'description' => $this->buildDescription($docBlock, $docText), 'examples' => $this->buildExamples($examples), 'resources' => $this->buildResources($resources), @@ -532,7 +534,7 @@ private function buildExternalType($type) private function buildLink($content) { $componentId = null; - if ($this->linkCrossComponent && substr_compare(trim($content, '\\'), 'Google\Cloud', 0, 12) === 0) { + if ($this->isComponent && substr_compare(trim($content, '\\'), 'Google\Cloud', 0, 12) === 0) { try { $matches = []; preg_match('/[Generator\<]?(Google\\\Cloud\\\[\w\\\]{0,})[\>]?[\[\]]?/', $content, $matches); @@ -611,8 +613,6 @@ private function splitDescription($description) ]; } - private static $composerFiles = []; - private function isComponent($composerPath) { if (isset(self::$composerFiles[$composerPath])) { @@ -628,4 +628,9 @@ private function isComponent($composerPath) return false; } + + private function getSource() + { + return 'src' . explode('src', $this->path)[1]; + } }