From ac60948fab6fb8a5714292ee2f1417e571902164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Goetz?= Date: Sat, 7 Dec 2019 16:32:38 +0100 Subject: [PATCH] Other Scrutinizer fixes --- libs/ConfigBuilder.php | 2 +- libs/Console/ClearCache.php | 2 +- libs/Console/Serve.php | 4 ++-- libs/Daux.php | 2 +- libs/Format/Confluence/Api.php | 5 +++++ .../Confluence/ContentTypes/Markdown/ImageRenderer.php | 2 +- libs/Format/Confluence/Generator.php | 2 +- libs/Format/HTML/ContentTypes/Markdown/TOC/Processor.php | 2 +- libs/Format/HTMLFile/Generator.php | 2 +- libs/GeneratorHelper.php | 2 +- libs/Server/ExtensionMimeTypeGuesser.php | 2 +- libs/Tree/Builder.php | 4 +++- 12 files changed, 19 insertions(+), 12 deletions(-) diff --git a/libs/ConfigBuilder.php b/libs/ConfigBuilder.php index 7ffcb7c..18503c1 100644 --- a/libs/ConfigBuilder.php +++ b/libs/ConfigBuilder.php @@ -262,7 +262,7 @@ class ConfigBuilder */ private function findLocation($path, $basedir, $type) { // If Path is explicitly null, it's useless to go further - if ($path == null) { + if ($path === null) { return null; } diff --git a/libs/Console/ClearCache.php b/libs/Console/ClearCache.php index 04a7317..a8ab88b 100644 --- a/libs/Console/ClearCache.php +++ b/libs/Console/ClearCache.php @@ -16,7 +16,7 @@ class ClearCache extends SymfonyCommand protected function execute(InputInterface $input, OutputInterface $output) { - $output->writeln("Clearing cache at '" . Cache::getDirectory() ."'"); + $output->writeln("Clearing cache at '" . Cache::getDirectory() . "'"); Cache::clear(); $output->writeln("Cache cleared"); diff --git a/libs/Console/Serve.php b/libs/Console/Serve.php index 0775483..65dd270 100755 --- a/libs/Console/Serve.php +++ b/libs/Console/Serve.php @@ -44,7 +44,7 @@ class Serve extends DauxCommand // Write the current configuration to a file to read it from the other serving side $file = tmpfile(); - if (!$file) { + if ($file === false) { $output->writeln("Failed to create temporary file for configuration"); return 1; } @@ -54,7 +54,7 @@ class Serve extends DauxCommand chdir(__DIR__ . '/../../'); - putenv('DAUX_CONFIG='. $path); + putenv('DAUX_CONFIG=' . $path); putenv('DAUX_VERBOSITY=' . $output->getVerbosity()); putenv('DAUX_EXTENSION=' . DAUX_EXTENSION); diff --git a/libs/Daux.php b/libs/Daux.php index eb66fe5..7c7a99a 100644 --- a/libs/Daux.php +++ b/libs/Daux.php @@ -85,7 +85,7 @@ class Daux $entry_page[$key] = $this->tree->getEntries()[$key]->getFirstPage(); } } else { - $entry_page= $this->tree->getFirstPage(); + $entry_page = $this->tree->getFirstPage(); } $this->config->setEntryPage($entry_page); $this->merged_tree = true; diff --git a/libs/Format/Confluence/Api.php b/libs/Format/Confluence/Api.php index 81d1c38..d3e26af 100644 --- a/libs/Format/Confluence/Api.php +++ b/libs/Format/Confluence/Api.php @@ -218,6 +218,11 @@ class Api public function showSourceCode($css, $lineNumber, $column) { $lines = preg_split("/\r?\n/", $css); + + if ($lines === false) { + return $css; + } + $start = max($lineNumber - 3, 0); $end = min($lineNumber + 2, count($lines)); diff --git a/libs/Format/Confluence/ContentTypes/Markdown/ImageRenderer.php b/libs/Format/Confluence/ContentTypes/Markdown/ImageRenderer.php index 970f53b..52e8c3b 100644 --- a/libs/Format/Confluence/ContentTypes/Markdown/ImageRenderer.php +++ b/libs/Format/Confluence/ContentTypes/Markdown/ImageRenderer.php @@ -45,7 +45,7 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf ); } - return parent::render($inline, $htmlRenderer); + return $this->parent->render($inline, $htmlRenderer); } /** diff --git a/libs/Format/Confluence/Generator.php b/libs/Format/Confluence/Generator.php index 3929975..7ff54eb 100644 --- a/libs/Format/Confluence/Generator.php +++ b/libs/Format/Confluence/Generator.php @@ -49,7 +49,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator throw new \RuntimeException("The following options are mandatory for confluence : '" . implode("', '", $errors) . "'"); } - if (!array_key_exists('ancestor_id', $confluence) && !array_key_exists('root_id', $confluence)) { + if (!$confluence->hasAncestorId() && !$confluence->hasRootId()) { throw new \RuntimeException("You must specify an 'ancestor_id' or a 'root_id' for confluence."); } } diff --git a/libs/Format/HTML/ContentTypes/Markdown/TOC/Processor.php b/libs/Format/HTML/ContentTypes/Markdown/TOC/Processor.php index 07fe77e..e4db127 100644 --- a/libs/Format/HTML/ContentTypes/Markdown/TOC/Processor.php +++ b/libs/Format/HTML/ContentTypes/Markdown/TOC/Processor.php @@ -138,7 +138,7 @@ class Processor } } - $node->data['attributes']['id'] = $this->getUniqueId($document, 'page_'. $this->escaped($text)); + $node->data['attributes']['id'] = $this->getUniqueId($document, 'page_' . $this->escaped($text)); } /** diff --git a/libs/Format/HTMLFile/Generator.php b/libs/Format/HTMLFile/Generator.php index 12b15f2..0982cbb 100644 --- a/libs/Format/HTMLFile/Generator.php +++ b/libs/Format/HTMLFile/Generator.php @@ -73,7 +73,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator $this->runAction( 'Generating ' . $current->getTitle(), $width, - function () use ($book, $current, $config) { + function() use ($book, $current, $config) { $contentType = $this->daux->getContentTypeHandler()->getType($current); $content = ContentPage::fromFile($current, $config, $contentType); $content->templateRenderer = $this->templateRenderer; diff --git a/libs/GeneratorHelper.php b/libs/GeneratorHelper.php index 263cfe1..3eaf188 100755 --- a/libs/GeneratorHelper.php +++ b/libs/GeneratorHelper.php @@ -39,7 +39,7 @@ class GeneratorHelper $dir = opendir($source); - if (!$dir) { + if ($dir === false) { throw new RuntimeException("Cannot copy '$source' to '$destination'"); } diff --git a/libs/Server/ExtensionMimeTypeGuesser.php b/libs/Server/ExtensionMimeTypeGuesser.php index e6ac395..30b8db4 100644 --- a/libs/Server/ExtensionMimeTypeGuesser.php +++ b/libs/Server/ExtensionMimeTypeGuesser.php @@ -20,7 +20,7 @@ class ExtensionMimeTypeGuesser implements MimeTypeGuesserInterface */ public function guessMimeType(string $path): ?string { - $extension = pathinfo($path,PATHINFO_EXTENSION); + $extension = pathinfo($path, PATHINFO_EXTENSION); if ($extension == "css") { return "text/css"; diff --git a/libs/Tree/Builder.php b/libs/Tree/Builder.php index db76d09..51e058a 100644 --- a/libs/Tree/Builder.php +++ b/libs/Tree/Builder.php @@ -59,7 +59,9 @@ class Builder */ public static function build($node, $ignore) { - if (($it = new \FilesystemIterator($node->getPath())) == false) { + try { + $it = new \FilesystemIterator($node->getPath()); + } catch (\UnexpectedValueException $e) { return; }