diff --git a/libs/ConfigBuilder.php b/libs/ConfigBuilder.php index 8998610e..8cf47f7f 100644 --- a/libs/ConfigBuilder.php +++ b/libs/ConfigBuilder.php @@ -159,7 +159,7 @@ private function resolveThemeVariant() } if (!is_dir($themesPath . $theme)) { - throw new \RuntimeException("Theme '{$theme}' not found"); + throw new ConfigurationException("Theme '{$theme}' not found"); } return [$theme, $variant]; diff --git a/libs/ConfigurationException.php b/libs/ConfigurationException.php new file mode 100644 index 00000000..248096c7 --- /dev/null +++ b/libs/ConfigurationException.php @@ -0,0 +1,5 @@ +generator = new $class($this); @@ -270,7 +272,7 @@ public static function getOutput() * * @param array|string $messages The message as an array of lines or a single string * @param bool $newline Whether to add a newline - * @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL + * @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants) */ public static function write($messages, $newline = false, $options = 0) { @@ -281,7 +283,7 @@ public static function write($messages, $newline = false, $options = 0) * Writes a message to the output and adds a newline at the end. * * @param array|string $messages The message as an array of lines of a single string - * @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL + * @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants) */ public static function writeln($messages, $options = 0) { diff --git a/libs/DauxHelper.php b/libs/DauxHelper.php index 08d246a3..3230933d 100644 --- a/libs/DauxHelper.php +++ b/libs/DauxHelper.php @@ -1,6 +1,5 @@ getUri(); $this->attachments[$filename] = ['filename' => $filename, 'content' => $file->getContent()]; } else { - throw new \RuntimeException("Cannot embed image as we don't understand its type."); + throw new Exception("Cannot embed image as we don't understand its type."); } return $this->createImageTag($filename, $attributes); diff --git a/libs/Format/Confluence/DuplicateTitleException.php b/libs/Format/Confluence/DuplicateTitleException.php index 3b4f6b7f..a7ea9107 100644 --- a/libs/Format/Confluence/DuplicateTitleException.php +++ b/libs/Format/Confluence/DuplicateTitleException.php @@ -1,5 +1,7 @@ getConfluenceConfiguration(); if ($confluence == null) { - throw new \RuntimeException('You must specify your Confluence configuration'); + throw new ConfluenceConfigurationException('You must specify your Confluence configuration'); } $mandatory = ['base_url', 'user', 'pass', 'prefix']; @@ -43,11 +43,13 @@ public function checkConfiguration() if (count($errors)) { $message = "The following options are mandatory for confluence : '" . implode("', '", $errors) . "'"; - throw new \RuntimeException($message); + throw new ConfluenceConfigurationException($message); } if (!$confluence->hasAncestorId() && !$confluence->hasRootId()) { - throw new \RuntimeException("You must specify an 'ancestor_id' or a 'root_id' for confluence."); + throw new ConfluenceConfigurationException( + "You must specify an 'ancestor_id' or a 'root_id' for confluence." + ); } } diff --git a/libs/Format/Confluence/Publisher.php b/libs/Format/Confluence/Publisher.php index 41874ad3..1493724b 100644 --- a/libs/Format/Confluence/Publisher.php +++ b/libs/Format/Confluence/Publisher.php @@ -45,7 +45,11 @@ public function diff($local, $remote, $level) if ($local && array_key_exists('children', $local)) { $remoteChildren = $remote && array_key_exists('children', $remote) ? $remote['children'] : []; foreach ($local['children'] as $title => $content) { - $this->diff($content, array_key_exists($title, $remoteChildren) ? $remoteChildren[$title] : null, "$level "); + $this->diff( + $content, + array_key_exists($title, $remoteChildren) ? $remoteChildren[$title] : null, + "$level " + ); } } @@ -117,14 +121,18 @@ protected function getRootPage($tree) array_map(function ($page) { return $page['title']; }, $pages) ); - throw new \RuntimeException("Could not find a page named '$rootTitle' but found ['$pageNames']."); + throw new ConfluenceConfigurationException( + "Could not find a page named '$rootTitle' but found ['$pageNames']." + ); } if ($this->confluence->hasRootId()) { return $this->client->getPage($this->confluence->getRootId()); } - throw new \RuntimeException('You must at least specify a `root_id` or `ancestor_id` in your confluence configuration.'); + throw new ConfluenceConfigurationException( + 'You must at least specify a `root_id` or `ancestor_id` in your confluence configuration.' + ); } protected function createPage($parentId, $entry, $published) diff --git a/libs/Format/HTML/ContentTypes/Markdown/ImageRenderer.php b/libs/Format/HTML/ContentTypes/Markdown/ImageRenderer.php index cd6a46f8..4c8b70de 100644 --- a/libs/Format/HTML/ContentTypes/Markdown/ImageRenderer.php +++ b/libs/Format/HTML/ContentTypes/Markdown/ImageRenderer.php @@ -10,7 +10,7 @@ use League\Config\ConfigurationInterface; use Todaymade\Daux\Config; use Todaymade\Daux\DauxHelper; -use Todaymade\Daux\Exception\LinkNotFoundException; +use Todaymade\Daux\LinkNotFoundException; class ImageRenderer implements NodeRendererInterface, XmlNodeRendererInterface, ConfigurationAwareInterface { diff --git a/libs/Format/HTMLFile/ContentTypes/Markdown/LinkRenderer.php b/libs/Format/HTMLFile/ContentTypes/Markdown/LinkRenderer.php index 926d4c9d..7cd3c74c 100644 --- a/libs/Format/HTMLFile/ContentTypes/Markdown/LinkRenderer.php +++ b/libs/Format/HTMLFile/ContentTypes/Markdown/LinkRenderer.php @@ -4,7 +4,7 @@ use League\CommonMark\Node\Node; use League\CommonMark\Renderer\ChildNodeRendererInterface; use Todaymade\Daux\DauxHelper; -use Todaymade\Daux\Exception\LinkNotFoundException; +use Todaymade\Daux\LinkNotFoundException; class LinkRenderer extends \Todaymade\Daux\ContentTypes\Markdown\LinkRenderer { diff --git a/libs/GeneratorHelper.php b/libs/GeneratorHelper.php index 2d36b9f9..cebfa851 100755 --- a/libs/GeneratorHelper.php +++ b/libs/GeneratorHelper.php @@ -38,7 +38,7 @@ public static function copyRecursive($source, $destination) $dir = opendir($source); if ($dir === false) { - throw new \RuntimeException("Cannot copy '$source' to '$destination'"); + throw new Exception("Cannot copy '$source' to '$destination'"); } while (false !== ($file = readdir($dir))) { diff --git a/libs/LinkNotFoundException.php b/libs/LinkNotFoundException.php new file mode 100644 index 00000000..b7ebb114 --- /dev/null +++ b/libs/LinkNotFoundException.php @@ -0,0 +1,5 @@ +daux->getGenerator(); if (!$generator instanceof LiveGenerator) { - throw new \RuntimeException( + throw new Exception( "The generator '" . get_class($generator) . "' does not implement the interface " . "'Todaymade\\Daux\\Format\\Base\\LiveGenerator' and thus doesn't support live rendering." ); diff --git a/libs/Tree/Builder.php b/libs/Tree/Builder.php index 59ae50b8..d2a8ac55 100644 --- a/libs/Tree/Builder.php +++ b/libs/Tree/Builder.php @@ -1,10 +1,11 @@ getFilename(); - if (in_array($filename, static::$IGNORED)) { + if (in_array($filename, static::$ignoredPaths)) { return true; } @@ -44,7 +45,7 @@ protected static function getName($path) preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $m); if (!isset($m[3])) { - throw new \RuntimeException('Name not found'); + throw new Exception('Name not found'); } return $m[3]; @@ -143,7 +144,7 @@ public static function createContent(Directory $parent, \SplFileInfo $file) */ public static function removeSortingInformations($filename) { - preg_match('/^[-+]?[0-9]*_?(.*)/', $filename, $matches); + preg_match('/^[-+]?\d*_?(.*)/', $filename, $matches); // Remove the numeric part // of the filename, only if diff --git a/libs/Tree/Content.php b/libs/Tree/Content.php index 4060a77e..8a058aa6 100644 --- a/libs/Tree/Content.php +++ b/libs/Tree/Content.php @@ -3,6 +3,7 @@ use League\CommonMark\Extension\FrontMatter\Data\SymfonyYamlFrontMatterParser; use League\CommonMark\Extension\FrontMatter\Exception\InvalidFrontMatterException; use League\CommonMark\Extension\FrontMatter\FrontMatterParser; +use Todaymade\Daux\Exception; class Content extends ContentAbstract { @@ -28,7 +29,7 @@ protected function getFrontMatter() if ($this->manuallySetContent) { $content = $this->content; } elseif (!$this->getPath()) { - throw new \RuntimeException('Empty content'); + throw new Exception('Empty content'); } else { $content = file_get_contents($this->getPath()); } @@ -120,7 +121,7 @@ protected function parseAttributes() $file = $this->getUrl(); } - throw new \RuntimeException('Could not parse front matter in ' . $file, 0, $e); + throw new Exception('Could not parse front matter in "' . $file . '"', 0, $e); } } diff --git a/libs/Tree/Directory.php b/libs/Tree/Directory.php index f5e2da4b..83fa0b20 100644 --- a/libs/Tree/Directory.php +++ b/libs/Tree/Directory.php @@ -120,7 +120,7 @@ public function removeChild(Entry $entry): void public function getConfig(): Config { if (!$this->parent) { - throw new \RuntimeException('Could not retrieve configuration. Are you sure that your tree has a Root ?'); + throw new TreeException('Could not retrieve configuration. Are you sure that your tree has a Root ?'); } return $this->parent->getConfig(); @@ -224,10 +224,8 @@ public function hasContent(): bool if ($node instanceof Content) { return true; } - if ($node instanceof self) { - if ($node->hasContent()) { - return true; - } + if ($node instanceof self && $node->hasContent()) { + return true; } } @@ -281,7 +279,7 @@ public function offsetGet($offset): mixed public function offsetSet($offset, $value): void { if (!$value instanceof Entry) { - throw new \RuntimeException('The value is not of type Entry'); + throw new TreeException('The value is not of type Entry'); } $this->addChild($value); diff --git a/libs/Tree/TreeException.php b/libs/Tree/TreeException.php new file mode 100644 index 00000000..eb6e0d66 --- /dev/null +++ b/libs/Tree/TreeException.php @@ -0,0 +1,7 @@ +