Fix scrutinizer hints

This commit is contained in:
Stéphane Goetz 2019-12-07 11:22:40 +01:00
parent b5633e93c7
commit 8215808282
12 changed files with 55 additions and 46 deletions

View File

@ -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)

View File

@ -1,6 +1,7 @@
<?php namespace Todaymade\Daux;
use Todaymade\Daux\Tree\Content;
use Todaymade\Daux\Tree\Entry;
use Todaymade\Daux\Format\HTML\Config as HTMLConfig;
use Todaymade\Daux\Format\HTML\Theme as Theme;
use Todaymade\Daux\Format\Confluence\Config as ConfluenceConfig;
@ -95,7 +96,7 @@ class Config extends BaseConfig
// As the global configuration is always present, we
// need to test for the existence of the legacy value
// first. Then use the current value.
if (array_key_exists('live', $this) && array_key_exists('inherit_index', $this['live'])) {
if ($this->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() {

View File

@ -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) {

View File

@ -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));
}
}
}

View File

@ -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("<fg=red>Failed to create temporary file for configuration</fg=red>");
return 1;
}
$path = stream_get_meta_data($file)['uri'];
fwrite($file, serialize($daux->getConfig()));

View File

@ -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');
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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'));
}

View File

@ -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());

View File

@ -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;

View File

@ -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(