From c0b230de570fc19d2a0b4afdb0b57b629ff0c221 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 8 Sep 2021 13:03:20 +0200 Subject: [PATCH] Fixed some minor issues related to edge cases --- src/Generator/JsonGenerator.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Generator/JsonGenerator.php b/src/Generator/JsonGenerator.php index 6a087b6..583d365 100644 --- a/src/Generator/JsonGenerator.php +++ b/src/Generator/JsonGenerator.php @@ -214,7 +214,13 @@ private function getMetaEntry(string $parserFilename, bool $throwOnMissing = fal private function walkTocTreeAndReturnHierarchy(string $filename, array &$walkedFiles): array { $hierarchy = []; - foreach ($this->getMetaEntry($filename)->getTocs() as $toc) { + + // happens in edge-cases such as empty or not found documents + if (null === $meta = $this->getMetaEntry($filename)) { + return $hierarchy; + } + + foreach ($meta->getTocs() as $toc) { foreach ($toc as $tocFilename) { // only walk a file one time, the first time you see it if (in_array($tocFilename, $walkedFiles, true)) { @@ -273,7 +279,10 @@ private function determineParents(string $parserFilename, array $tocTreeHierarch private function makeRelativeLink(string $currentFilename, string $filename): array { - $meta = $this->getMetaEntry($filename); + // happens in edge-cases such as empty or not found documents + if (null === $meta = $this->getMetaEntry($filename)) { + return ['title' => '', 'link' => '']; + } return [ 'title' => $meta->getTitle(),