Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dev/src/DocGenerator/Command/Docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('--------------');
Expand All @@ -145,7 +145,7 @@ private function generateComponentDocumentation(
$component['id'],
$paths['manifest'],
$release,
$linkCrossComponent
$isComponent
);

$docs->generate($component['path'], $pretty);
Expand Down
10 changes: 5 additions & 5 deletions dev/src/DocGenerator/DocGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DocGenerator
private $componentId;
private $manifestPath;
private $release;
private $linkCrossComponent;
private $isComponent;

/**
* @param array $files
Expand All @@ -48,7 +48,7 @@ public function __construct(
$componentId,
$manifestPath,
$release,
$linkCrossComponent = true
$isComponent = true
) {
$this->types = $types;
$this->files = $files;
Expand All @@ -57,7 +57,7 @@ public function __construct(
$this->componentId = $componentId;
$this->manifestPath = $manifestPath;
$this->release = $release;
$this->linkCrossComponent = $linkCrossComponent;
$this->isComponent = $isComponent;
}

/**
Expand Down Expand Up @@ -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);
Expand All @@ -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'
]);
Expand Down
29 changes: 17 additions & 12 deletions dev/src/DocGenerator/Parser/CodeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,39 @@ 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;
private $externalTypes;
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;
$this->externalTypes = json_decode(file_get_contents(__DIR__ .'/../../../../docs/external-classes.json'), true);
$this->componentId = $componentId;
$this->manifestPath = $manifestPath;
$this->release = $release;
$this->linkCrossComponent = $linkCrossComponent;
$this->isComponent = $isComponent;
}

public function parse()
Expand All @@ -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)
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -611,8 +613,6 @@ private function splitDescription($description)
];
}

private static $composerFiles = [];

private function isComponent($composerPath)
{
if (isset(self::$composerFiles[$composerPath])) {
Expand All @@ -628,4 +628,9 @@ private function isComponent($composerPath)

return false;
}

private function getSource()
{
return 'src' . explode('src', $this->path)[1];
}
}