From 82158082824eab25a1a91a22c79b22bce8ca20a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Goetz?= Date: Sat, 7 Dec 2019 11:22:40 +0100 Subject: [PATCH] Fix scrutinizer hints --- libs/BaseConfig.php | 4 +-- libs/Config.php | 13 ++++---- libs/ConfigBuilder.php | 8 ++--- libs/Console/DauxCommand.php | 2 +- libs/Console/Serve.php | 6 ++++ libs/Format/Confluence/Config.php | 30 +++++++++---------- .../ContentTypes/Markdown/ImageRenderer.php | 1 + libs/Format/Confluence/Generator.php | 6 ++-- libs/Format/HTML/Config.php | 13 ++++---- libs/Format/HTML/Generator.php | 10 +++---- libs/Format/HTML/Template.php | 6 ++-- libs/Format/HTMLFile/Generator.php | 2 +- 12 files changed, 55 insertions(+), 46 deletions(-) diff --git a/libs/BaseConfig.php b/libs/BaseConfig.php index 6e1ec4d..7d29f09 100644 --- a/libs/BaseConfig.php +++ b/libs/BaseConfig.php @@ -15,7 +15,7 @@ class BaseConfig extends ArrayObject foreach ($newValues as $key => $value) { // If the key doesn't exist yet, // we can simply set it. - if (!array_key_exists($key, $this)) { + if (!array_key_exists($key, /** @scrutinizer ignore-type */ $this)) { $this[$key] = $value; continue; } @@ -39,7 +39,7 @@ class BaseConfig extends ArrayObject public function hasValue($key) { - return array_key_exists($key, $this); + return array_key_exists($key, /** @scrutinizer ignore-type */ $this); } public function getValue($key) diff --git a/libs/Config.php b/libs/Config.php index 560ea56..eaa92b2 100644 --- a/libs/Config.php +++ b/libs/Config.php @@ -1,6 +1,7 @@ hasValue('live') && array_key_exists('inherit_index', $this['live'])) { return $this['live']['inherit_index']; } @@ -164,7 +165,7 @@ class Config extends BaseConfig } public function setImage($value) { - return $this->setValue('image', $value); + $this->setValue('image', $value); } public function getLocalBase() { @@ -201,7 +202,7 @@ class Config extends BaseConfig } public function setEntryPage($value) { - return $this->setValue('entry_page', $value); + $this->setValue('entry_page', $value); } public function hasRequest(): bool { @@ -213,7 +214,7 @@ class Config extends BaseConfig } public function setRequest($value) { - return $this->setValue('request', $value); + $this->setValue('request', $value); } public function getIndex() { @@ -221,7 +222,7 @@ class Config extends BaseConfig } public function setIndex($value) { - return $this->setValue('index', $value); + $this->setValue('index', $value); } public function hasProcessorInstance() { @@ -233,7 +234,7 @@ class Config extends BaseConfig } public function setProcessorInstance($value) { - return $this->setValue('processor_instance', $value); + $this->setValue('processor_instance', $value); } public function getIgnore() { diff --git a/libs/ConfigBuilder.php b/libs/ConfigBuilder.php index 7bc33dc..7ffcb7c 100644 --- a/libs/ConfigBuilder.php +++ b/libs/ConfigBuilder.php @@ -13,11 +13,11 @@ class ConfigBuilder $this->config['local_base'] = dirname(__DIR__); } - static function fromFile($file): Config { + public static function fromFile($file): Config { return unserialize(file_get_contents($file)); } - static function withMode($mode = Daux::STATIC_MODE): ConfigBuilder { + public static function withMode($mode = Daux::STATIC_MODE): ConfigBuilder { $builder = new ConfigBuilder($mode); $builder->loadBaseConfiguration(); return $builder; @@ -101,7 +101,7 @@ class ConfigBuilder return $this; } - function build(): Config { + public function build(): Config { $this->initializeConfiguration(); return $this->config; @@ -257,7 +257,7 @@ class ConfigBuilder /** * @param string|null $path * @param string $basedir - * @param "dir"|"file" $type + * @param string $type * @return false|null|string */ private function findLocation($path, $basedir, $type) { diff --git a/libs/Console/DauxCommand.php b/libs/Console/DauxCommand.php index defe0f1..e1ad986 100644 --- a/libs/Console/DauxCommand.php +++ b/libs/Console/DauxCommand.php @@ -61,7 +61,7 @@ class DauxCommand extends SymfonyCommand { $class = $daux->getProcessorClass(); if (!empty($class)) { - $daux->setProcessor(new $class($daux, $output, $width)); + $daux->setProcessor(new $class($daux, $daux->getOutput(), $width)); } } } diff --git a/libs/Console/Serve.php b/libs/Console/Serve.php index cf8e738..0775483 100755 --- a/libs/Console/Serve.php +++ b/libs/Console/Serve.php @@ -43,6 +43,12 @@ class Serve extends DauxCommand // Write the current configuration to a file to read it from the other serving side $file = tmpfile(); + + if (!$file) { + $output->writeln("Failed to create temporary file for configuration"); + return 1; + } + $path = stream_get_meta_data($file)['uri']; fwrite($file, serialize($daux->getConfig())); diff --git a/libs/Format/Confluence/Config.php b/libs/Format/Confluence/Config.php index 8311a68..907b4d6 100644 --- a/libs/Format/Confluence/Config.php +++ b/libs/Format/Confluence/Config.php @@ -5,62 +5,62 @@ use Todaymade\Daux\BaseConfig; class Config extends BaseConfig { public function shouldAutoDeleteOrphanedPages() { - if (array_key_exists('delete', $this)) { - return $this['delete']; + if ($this->hasValue('delete')) { + return $this->getValue('delete'); } return false; } public function getUpdateThreshold() { - return array_key_exists('update_threshold', $this) ? $this['update_threshold'] : 2; + return $this->hasValue('update_threshold') ? $this->getValue('update_threshold') : 2; } public function getPrefix() { - return $this['prefix']; + return $this->getValue('prefix'); } public function getBaseUrl() { - return $this['base_url']; + return $this->getValue('base_url'); } public function getUser() { - return $this['user']; + return $this->getValue('user'); } public function getPassword() { - return $this['pass']; + return $this->getValue('pass'); } public function getSpaceId() { - return $this['space_id']; + return $this->getValue('space_id'); } public function hasAncestorId() { - return array_key_exists('ancestor_id', $this); + return $this->hasValue('ancestor_id'); } public function getAncestorId() { - return $this['ancestor_id']; + return $this->getValue('ancestor_id'); } public function setAncestorId($value) { - $this['ancestor_id'] = $value; + $this->setValue('ancestor_id', $value); } public function hasRootId() { - return array_key_exists('root_id', $this); + return $this->hasValue('root_id'); } public function getRootId() { - return $this['root_id']; + return $this->getValue('root_id'); } public function hasHeader() { - return array_key_exists('header', $this); + return $this->hasValue('header'); } public function getHeader() { - return $this['header']; + return $this->getValue('header'); } } diff --git a/libs/Format/Confluence/ContentTypes/Markdown/ImageRenderer.php b/libs/Format/Confluence/ContentTypes/Markdown/ImageRenderer.php index 90c5225..970f53b 100644 --- a/libs/Format/Confluence/ContentTypes/Markdown/ImageRenderer.php +++ b/libs/Format/Confluence/ContentTypes/Markdown/ImageRenderer.php @@ -4,6 +4,7 @@ use League\CommonMark\ElementRendererInterface; use League\CommonMark\HtmlElement; use League\CommonMark\Inline\Element\AbstractInline; use League\CommonMark\Inline\Element\Image; +use League\CommonMark\Inline\Renderer\InlineRendererInterface; use League\CommonMark\Util\ConfigurationAwareInterface; use League\CommonMark\Util\ConfigurationInterface; diff --git a/libs/Format/Confluence/Generator.php b/libs/Format/Confluence/Generator.php index a452651..3929975 100644 --- a/libs/Format/Confluence/Generator.php +++ b/libs/Format/Confluence/Generator.php @@ -2,7 +2,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Todaymade\Daux\Config; +use Todaymade\Daux\Config as GlobalConfig; use Todaymade\Daux\Console\RunAction; use Todaymade\Daux\Daux; use Todaymade\Daux\Tree\Content; @@ -40,7 +40,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator $mandatory = ['space_id', 'base_url', 'user', 'pass', 'prefix']; $errors = []; foreach ($mandatory as $key) { - if (!array_key_exists($key, $confluence)) { + if (!$confluence->hasValue($key)) { $errors[] = $key; } } @@ -96,7 +96,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator $publisher->publish($tree); } - private function generateRecursive(Directory $tree, Config $config, $base_url = '') + private function generateRecursive(Directory $tree, GlobalConfig $config, $base_url = '') { $final = ['title' => $this->prefix . $tree->getTitle()]; $config['base_url'] = $base_url; diff --git a/libs/Format/HTML/Config.php b/libs/Format/HTML/Config.php index 4ea352a..509bee7 100644 --- a/libs/Format/HTML/Config.php +++ b/libs/Format/HTML/Config.php @@ -16,17 +16,18 @@ class Config extends BaseConfig public function getEditOn() { - if (array_key_exists('edit_on', $this)) { - if (is_string($this['edit_on'])) { - return $this->prepareGithubUrl($this['edit_on']); + if ($this->hasValue('edit_on')) { + $edit_on = $this->getValue('edit_on'); + if (is_string($edit_on)) { + return $this->prepareGithubUrl($edit_on); } else { - $this['edit_on']['basepath'] = rtrim($this['edit_on']['basepath'], '/'); + $edit_on['basepath'] = rtrim($edit_on['basepath'], '/'); - return $this['edit_on']; + return $edit_on; } } - if (array_key_exists('edit_on_github', $this)) { + if ($this->hasValue('edit_on_github')) { return $this->prepareGithubUrl($this->getValue('edit_on_github')); } diff --git a/libs/Format/HTML/Generator.php b/libs/Format/HTML/Generator.php index 3eb41ca..9b66d32 100755 --- a/libs/Format/HTML/Generator.php +++ b/libs/Format/HTML/Generator.php @@ -2,7 +2,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Todaymade\Daux\Config; +use Todaymade\Daux\Config as GlobalConfig; use Todaymade\Daux\Console\RunAction; use Todaymade\Daux\Daux; use Todaymade\Daux\DauxHelper; @@ -143,14 +143,14 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator * * @param Directory $tree * @param string $output_dir - * @param \Todaymade\Daux\Config $config + * @param GlobalConfig $config * @param OutputInterface $output * @param int $width * @param bool $index_pages * @param string $base_url * @throws \Exception */ - private function generateRecursive(Directory $tree, $output_dir, $config, $output, $width, $index_pages, $base_url = '') + private function generateRecursive(Directory $tree, $output_dir, GlobalConfig $config, $output, $width, $index_pages, $base_url = '') { DauxHelper::rebaseConfiguration($config, $base_url); @@ -197,10 +197,10 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator /** * @param Entry $node - * @param Config $config + * @param GlobalConfig $config * @return \Todaymade\Daux\Format\Base\Page */ - public function generateOne(Entry $node, Config $config) + public function generateOne(Entry $node, GlobalConfig $config) { if ($node instanceof Raw) { return new RawPage($node->getPath()); diff --git a/libs/Format/HTML/Template.php b/libs/Format/HTML/Template.php index 28fc6ae..d8fdc63 100644 --- a/libs/Format/HTML/Template.php +++ b/libs/Format/HTML/Template.php @@ -4,7 +4,7 @@ namespace Todaymade\Daux\Format\HTML; use League\Plates\Engine; use Symfony\Component\Console\Output\OutputInterface; -use Todaymade\Daux\Config; +use Todaymade\Daux\Config as GlobalConfig; use Todaymade\Daux\Daux; use Todaymade\Daux\Tree\Content; use Todaymade\Daux\Tree\Directory; @@ -19,12 +19,12 @@ class Template * @param string $base * @param string $theme */ - public function __construct(Config $config) + public function __construct(GlobalConfig $config) { $this->config = $config; } - public function getEngine(Config $config) + public function getEngine(GlobalConfig $config) { if ($this->engine) { return $this->engine; diff --git a/libs/Format/HTMLFile/Generator.php b/libs/Format/HTMLFile/Generator.php index 6161491..12b15f2 100644 --- a/libs/Format/HTMLFile/Generator.php +++ b/libs/Format/HTMLFile/Generator.php @@ -49,7 +49,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator $config = $this->daux->getConfig(); if (is_null($destination)) { - $destination = $this->config->getLocalBase() . DIRECTORY_SEPARATOR . 'static'; + $destination = $config->getLocalBase() . DIRECTORY_SEPARATOR . 'static'; } $this->runAction(