From 8cf6a7667b33129b97bb42b7acc59677563a6c44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Goetz?= Date: Wed, 22 Apr 2020 22:24:52 +0200 Subject: [PATCH] More reformatting --- .php_cs | 16 +++++- libs/BaseConfig.php | 3 +- libs/Cache.php | 26 ++------- libs/Config.php | 7 ++- libs/ConfigBuilder.php | 35 +++++++++--- libs/Console/Application.php | 6 +- libs/Console/ClearCache.php | 2 +- libs/Console/DauxCommand.php | 2 +- libs/Console/Generate.php | 4 +- libs/Console/RunAction.php | 1 + libs/Console/Serve.php | 12 ++-- libs/ContentTypes/ContentType.php | 3 +- libs/ContentTypes/ContentTypeHandler.php | 5 +- .../Markdown/CommonMarkConverter.php | 2 - libs/ContentTypes/Markdown/ContentType.php | 7 ++- libs/ContentTypes/Markdown/LinkRenderer.php | 10 ++-- .../ContentTypes/Markdown/TableOfContents.php | 15 +---- .../Markdown/TableOfContentsParser.php | 6 -- libs/Daux.php | 25 ++++----- libs/DauxHelper.php | 42 +++++++++----- libs/Format/Base/EmbedImages.php | 3 +- libs/Format/Base/Generator.php | 6 +- libs/Format/Base/LiveGenerator.php | 2 - libs/Format/Base/Page.php | 4 +- libs/Format/Confluence/Api.php | 21 ++++--- libs/Format/Confluence/ContentPage.php | 6 +- .../ContentTypes/Markdown/CodeRenderer.php | 2 +- .../Markdown/CommonMarkConverter.php | 2 +- .../Markdown/FencedCodeRenderer.php | 2 - .../ContentTypes/Markdown/ImageRenderer.php | 4 -- .../Markdown/IndentedCodeRenderer.php | 4 +- .../ContentTypes/Markdown/LinkRenderer.php | 1 - libs/Format/Confluence/Generator.php | 3 - libs/Format/Confluence/Publisher.php | 23 ++++---- libs/Format/Confluence/PublisherDelete.php | 7 +-- libs/Format/HTML/Config.php | 9 ++- libs/Format/HTML/ContentPage.php | 18 +++--- .../Markdown/CommonMarkConverter.php | 4 +- .../Markdown/FencedCodeRenderer.php | 2 - .../ContentTypes/Markdown/ImageRenderer.php | 12 ++-- .../HTML/ContentTypes/Markdown/TOC/Entry.php | 6 +- .../ContentTypes/Markdown/TOC/Processor.php | 25 ++++----- .../ContentTypes/Markdown/TOC/Renderer.php | 1 + libs/Format/HTML/Generator.php | 22 +++----- libs/Format/HTML/HTMLUtils.php | 2 +- libs/Format/HTML/Template.php | 3 +- libs/Format/HTMLFile/Book.php | 9 ++- libs/Format/HTMLFile/ContentPage.php | 4 +- .../Markdown/CommonMarkConverter.php | 1 - .../ContentTypes/Markdown/LinkRenderer.php | 9 ++- libs/Format/HTMLFile/Generator.php | 10 ++-- libs/FormatDate.php | 2 +- libs/GeneratorHelper.php | 4 +- libs/Processor.php | 10 +--- libs/Server/ExtensionMimeTypeGuesser.php | 10 ++-- libs/Server/Server.php | 45 ++++++++------- libs/Tree/Builder.php | 22 ++++---- libs/Tree/Content.php | 21 ++----- libs/Tree/ContentAbstract.php | 6 -- libs/Tree/Directory.php | 56 +++++++++---------- libs/Tree/Entry.php | 19 +------ libs/Tree/Root.php | 8 +-- libs/bootstrap.php | 12 ++-- .../Markdown/LinkRendererTest.php | 9 ++- tests/DauxHelperTest.php | 4 +- tests/Format/HTML/ConfigTest.php | 9 ++- tests/Format/HTML/TableOfContentsTest.php | 18 +++--- tests/Format/Template/TranslateTest.php | 28 ++++------ tests/Server/ServerTest.php | 9 ++- tests/Tree/BuilderIntegrationTest.php | 3 +- tests/Tree/BuilderTest.php | 20 ++++--- tests/Tree/ContentTest.php | 6 +- tests/Tree/DirectoryTest.php | 6 +- 73 files changed, 362 insertions(+), 421 deletions(-) diff --git a/.php_cs b/.php_cs index 3c9f841..a4ed81f 100644 --- a/.php_cs +++ b/.php_cs @@ -2,13 +2,27 @@ $finder = PhpCsFixer\Finder::create() ->exclude('vendor') + ->exclude('templates') ->in(__DIR__) ; return PhpCsFixer\Config::create() ->setRules([ '@PSR2' => true, - 'array_syntax' => ['syntax' => 'short'], + '@PHP70Migration' => true, + '@PHP71Migration' => true, + '@PhpCsFixer' => true, + 'explicit_string_variable' => false, + 'single_blank_line_before_namespace' => false, + 'no_short_echo_tag' => false, + 'blank_line_after_opening_tag' => false, + 'yoda_style' => false, + 'concat_space' => ['spacing' => 'one'], + 'php_unit_internal_class' => false, + 'php_unit_test_class_requires_covers' => false, + 'phpdoc_align' => false, + 'multiline_whitespace_before_semicolons' => false, + 'ordered_class_elements' => ['use_trait', 'constant_public', 'constant_protected', 'constant_private', 'property_public', 'property_protected', 'property_private', 'construct', 'method'] ]) ->setFinder($finder) ; diff --git a/libs/BaseConfig.php b/libs/BaseConfig.php index be0d3ff..01a9601 100644 --- a/libs/BaseConfig.php +++ b/libs/BaseConfig.php @@ -5,7 +5,7 @@ use ArrayObject; class BaseConfig extends ArrayObject { /** - * Merge an array into the object + * Merge an array into the object. * * @param array $newValues * @param bool $override @@ -17,6 +17,7 @@ class BaseConfig extends ArrayObject // we can simply set it. if (!array_key_exists($key, (array) $this)) { $this[$key] = $value; + continue; } diff --git a/libs/Cache.php b/libs/Cache.php index 072833f..288d2a8 100644 --- a/libs/Cache.php +++ b/libs/Cache.php @@ -1,7 +1,6 @@ getBaseUrl(); } diff --git a/libs/ConfigBuilder.php b/libs/ConfigBuilder.php index 6182ede..b904efe 100644 --- a/libs/ConfigBuilder.php +++ b/libs/ConfigBuilder.php @@ -5,7 +5,7 @@ class ConfigBuilder /** @var Config */ private $config; - private $configuration_override_file = null; + private $configuration_override_file; private function __construct(string $mode) { @@ -23,12 +23,14 @@ class ConfigBuilder { $builder = new ConfigBuilder($mode); $builder->loadBaseConfiguration(); + return $builder; } public function with(array $values): ConfigBuilder { $this->config->merge($values); + return $this; } @@ -46,6 +48,7 @@ class ConfigBuilder $array = &$array[$key]; } $array[array_shift($keys)] = $value; + return $array; } @@ -54,60 +57,70 @@ class ConfigBuilder foreach ($values as $value) { $this->setValue($this->config, $value[0], $value[1]); } + return $this; } public function withDocumentationDirectory($dir): ConfigBuilder { $this->config['docs_directory'] = $dir; + return $this; } public function withValidContentExtensions(array $value): ConfigBuilder { $this->config['valid_content_extensions'] = $value; + return $this; } public function withThemesPath($themePath): ConfigBuilder { $this->config['themes_path'] = $themePath; + return $this; } public function withThemesDirectory($directory): ConfigBuilder { $this->config['themes_directory'] = $directory; + return $this; } public function withCache(bool $value): ConfigBuilder { $this->config['cache'] = $value; + return $this; } public function withFormat($format): ConfigBuilder { $this->config['format'] = $format; + return $this; } public function withConfigurationOverride($file): ConfigBuilder { $this->configuration_override_file = $file; + return $this; } public function withProcessor($value): ConfigBuilder { $this->config['processor'] = $value; + return $this; } public function withConfluenceDelete($value): ConfigBuilder { $this->config['confluence']['delete'] = $value; + return $this; } @@ -146,6 +159,7 @@ class ConfigBuilder /** * @param string $override_file + * * @throws Exception */ private function initializeConfiguration() @@ -207,7 +221,7 @@ class ConfigBuilder } /** - * Load and validate the global configuration + * Load and validate the global configuration. * * @throws Exception */ @@ -231,6 +245,7 @@ class ConfigBuilder /** * @param string $config_file * @param bool $optional + * * @throws Exception */ private function loadConfiguration($config_file, $optional = true) @@ -251,11 +266,13 @@ class ConfigBuilder } /** - * Get the file requested for configuration overrides + * Get the file requested for configuration overrides. + * + * @param null|string $path * - * @param string|null $path - * @return string|null the path to a file to load for configuration overrides * @throws Exception + * + * @return null|string the path to a file to load for configuration overrides */ private function getConfigurationOverride($path) { @@ -273,10 +290,11 @@ class ConfigBuilder } /** - * @param string|null $path + * @param null|string $path * @param string $basedir * @param string $type - * @return false|null|string + * + * @return null|false|string */ private function findLocation($path, $basedir, $type) { @@ -286,11 +304,10 @@ class ConfigBuilder } // VFS, used only in tests - if (substr($path, 0, 6) == "vfs://") { + if (substr($path, 0, 6) == 'vfs://') { return $path; } - // Check if it's relative to the current directory or an absolute path if (DauxHelper::is($path, $type)) { return DauxHelper::getAbsolutePath($path); diff --git a/libs/Console/Application.php b/libs/Console/Application.php index 3682361..073ca30 100644 --- a/libs/Console/Application.php +++ b/libs/Console/Application.php @@ -12,16 +12,16 @@ class Application extends SymfonyApplication $this->add(new Serve()); $this->add(new ClearCache()); - $app_name = "daux/daux.io"; + $app_name = 'daux/daux.io'; $up = '..' . DIRECTORY_SEPARATOR; $composer = __DIR__ . DIRECTORY_SEPARATOR . $up . $up . $up . $up . $up . 'composer.lock'; - $version = "unknown"; + $version = 'unknown'; if (file_exists($composer)) { $app = json_decode(file_get_contents($composer)); $packages = $app->packages; - + foreach ($packages as $package) { if ($package->name == $app_name) { $version = $package->version; diff --git a/libs/Console/ClearCache.php b/libs/Console/ClearCache.php index a8ab88b..dd73d50 100644 --- a/libs/Console/ClearCache.php +++ b/libs/Console/ClearCache.php @@ -18,7 +18,7 @@ class ClearCache extends SymfonyCommand { $output->writeln("Clearing cache at '" . Cache::getDirectory() . "'"); Cache::clear(); - $output->writeln("Cache cleared"); + $output->writeln('Cache cleared'); return 0; } diff --git a/libs/Console/DauxCommand.php b/libs/Console/DauxCommand.php index d9266c1..175177c 100644 --- a/libs/Console/DauxCommand.php +++ b/libs/Console/DauxCommand.php @@ -47,7 +47,7 @@ class DauxCommand extends SymfonyCommand if ($input->hasOption('value')) { $values = array_map( function ($value) { - return array_map("trim", explode('=', $value)); + return array_map('trim', explode('=', $value)); }, $input->getOption('value') ); diff --git a/libs/Console/Generate.php b/libs/Console/Generate.php index bdb514e..d12a695 100755 --- a/libs/Console/Generate.php +++ b/libs/Console/Generate.php @@ -6,8 +6,8 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Terminal; -use Todaymade\Daux\Daux; use Todaymade\Daux\ConfigBuilder; +use Todaymade\Daux\Daux; class Generate extends DauxCommand { @@ -61,7 +61,7 @@ class Generate extends DauxCommand $builder = $this->prepareConfig(Daux::STATIC_MODE, $input, $output); $daux = new Daux($builder->build(), $output); - $width = (new Terminal)->getWidth(); + $width = (new Terminal())->getWidth(); // Instiantiate the processor if one is defined $this->prepareProcessor($daux, $width); diff --git a/libs/Console/RunAction.php b/libs/Console/RunAction.php index 1ee0be3..1c58dd7 100644 --- a/libs/Console/RunAction.php +++ b/libs/Console/RunAction.php @@ -26,6 +26,7 @@ trait RunAction }); } catch (\Exception $e) { $this->status($padding, '[ FAIL ]'); + throw $e; } $this->status($padding, '[ OK ]'); diff --git a/libs/Console/Serve.php b/libs/Console/Serve.php index 0533015..94eb28e 100755 --- a/libs/Console/Serve.php +++ b/libs/Console/Serve.php @@ -1,14 +1,11 @@ build(), $output); - $width = (new Terminal)->getWidth(); + $width = (new Terminal())->getWidth(); // Instiantiate the processor if one is defined $this->prepareProcessor($daux, $width); @@ -45,7 +42,8 @@ class Serve extends DauxCommand $file = tmpfile(); if ($file === false) { - $output->writeln("Failed to create temporary file for configuration"); + $output->writeln('Failed to create temporary file for configuration'); + return 1; } @@ -59,7 +57,7 @@ class Serve extends DauxCommand putenv('DAUX_EXTENSION=' . DAUX_EXTENSION); $base = escapeshellarg(__DIR__ . '/../../'); - $binary = escapeshellarg((new PhpExecutableFinder)->find(false)); + $binary = escapeshellarg((new PhpExecutableFinder())->find(false)); echo "Daux development server started on http://{$host}:{$port}/\n"; diff --git a/libs/ContentTypes/ContentType.php b/libs/ContentTypes/ContentType.php index 3bb8244..188872c 100644 --- a/libs/ContentTypes/ContentType.php +++ b/libs/ContentTypes/ContentType.php @@ -8,7 +8,7 @@ interface ContentType public function __construct(Config $config); /** - * Get the file extensions supported by this Content Type + * Get the file extensions supported by this Content Type. * * @return string[] */ @@ -17,6 +17,7 @@ interface ContentType /** * @param string $raw The raw text to render * @param Content $node The original node we are converting + * * @return string The generated output */ public function convert($raw, Content $node); diff --git a/libs/ContentTypes/ContentTypeHandler.php b/libs/ContentTypes/ContentTypeHandler.php index 3234afc..fd73424 100644 --- a/libs/ContentTypes/ContentTypeHandler.php +++ b/libs/ContentTypes/ContentTypeHandler.php @@ -18,7 +18,7 @@ class ContentTypeHandler } /** - * Get all valid content file extensions + * Get all valid content file extensions. * * @return string[] */ @@ -33,9 +33,8 @@ class ContentTypeHandler } /** - * Get the ContentType able to handle this node + * Get the ContentType able to handle this node. * - * @param Content $node * @return ContentType */ public function getType(Content $node) diff --git a/libs/ContentTypes/Markdown/CommonMarkConverter.php b/libs/ContentTypes/Markdown/CommonMarkConverter.php index 30a7f65..ad24c53 100644 --- a/libs/ContentTypes/Markdown/CommonMarkConverter.php +++ b/libs/ContentTypes/Markdown/CommonMarkConverter.php @@ -12,8 +12,6 @@ class CommonMarkConverter extends \League\CommonMark\CommonMarkConverter { /** * Create a new commonmark converter instance. - * - * @param array $config */ public function __construct(array $config = []) { diff --git a/libs/ContentTypes/Markdown/ContentType.php b/libs/ContentTypes/Markdown/ContentType.php index 0f42bf6..9788c17 100644 --- a/libs/ContentTypes/Markdown/ContentType.php +++ b/libs/ContentTypes/Markdown/ContentType.php @@ -43,7 +43,8 @@ class ContentType implements \Todaymade\Daux\ContentTypes\ContentType protected function doConversion($raw) { - Daux::writeln("Running conversion", OutputInterface::VERBOSITY_VERBOSE); + Daux::writeln('Running conversion', OutputInterface::VERBOSITY_VERBOSE); + return $this->getConverter()->convertToHtml($raw); } @@ -59,11 +60,11 @@ class ContentType implements \Todaymade\Daux\ContentTypes\ContentType $payload = Cache::get($cacheKey); if ($can_cache && $payload) { - Daux::writeln("Using cached version", OutputInterface::VERBOSITY_VERBOSE); + Daux::writeln('Using cached version', OutputInterface::VERBOSITY_VERBOSE); } if (!$can_cache || !$payload) { - Daux::writeln($can_cache ? "Not found in the cache, generating..." : "Cache disabled, generating...", OutputInterface::VERBOSITY_VERBOSE); + Daux::writeln($can_cache ? 'Not found in the cache, generating...' : 'Cache disabled, generating...', OutputInterface::VERBOSITY_VERBOSE); $payload = $this->doConversion($raw); } diff --git a/libs/ContentTypes/Markdown/LinkRenderer.php b/libs/ContentTypes/Markdown/LinkRenderer.php index bff86b4..773e362 100644 --- a/libs/ContentTypes/Markdown/LinkRenderer.php +++ b/libs/ContentTypes/Markdown/LinkRenderer.php @@ -31,9 +31,10 @@ class LinkRenderer implements InlineRendererInterface, ConfigurationAwareInterfa /** * @param AbstractInline|Link $inline - * @param ElementRendererInterface $htmlRenderer - * @return HtmlElement + * * @throws LinkNotFoundException + * + * @return HtmlElement */ public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer) { @@ -72,7 +73,7 @@ class LinkRenderer implements InlineRendererInterface, ConfigurationAwareInterfa } catch (LinkNotFoundException $e) { // For some reason, the filename could contain a # and thus the link needs to resolve to that. try { - if (strlen($urlAndHash[1] ?? "") > 0) { + if (strlen($urlAndHash[1] ?? '') > 0) { $file = DauxHelper::resolveInternalFile($this->daux, $url . '#' . $urlAndHash[1]); $url = DauxHelper::getRelativePath($this->daux->getCurrentPage()->getUrl(), $file->getUrl()); $foundWithHash = true; @@ -101,9 +102,6 @@ class LinkRenderer implements InlineRendererInterface, ConfigurationAwareInterfa return $element; } - /** - * @param ConfigurationInterface $configuration - */ public function setConfiguration(ConfigurationInterface $configuration) { $this->parent->setConfiguration($configuration); diff --git a/libs/ContentTypes/Markdown/TableOfContents.php b/libs/ContentTypes/Markdown/TableOfContents.php index f52cf0c..69f5c88 100644 --- a/libs/ContentTypes/Markdown/TableOfContents.php +++ b/libs/ContentTypes/Markdown/TableOfContents.php @@ -6,11 +6,7 @@ use League\CommonMark\Cursor; class TableOfContents extends AbstractBlock { /** - * Returns true if this block can contain the given block as a child node - * - * @param AbstractBlock $block - * - * @return bool + * Returns true if this block can contain the given block as a child node. */ public function canContain(AbstractBlock $block): bool { @@ -18,20 +14,13 @@ class TableOfContents extends AbstractBlock } /** - * Whether this is a code block - * - * @return bool + * Whether this is a code block. */ public function isCode(): bool { return false; } - /** - * @param Cursor $cursor - * - * @return bool - */ public function matchesNextLine(Cursor $cursor): bool { return false; diff --git a/libs/ContentTypes/Markdown/TableOfContentsParser.php b/libs/ContentTypes/Markdown/TableOfContentsParser.php index f082492..5e822ec 100644 --- a/libs/ContentTypes/Markdown/TableOfContentsParser.php +++ b/libs/ContentTypes/Markdown/TableOfContentsParser.php @@ -6,12 +6,6 @@ use League\CommonMark\Cursor; class TableOfContentsParser implements BlockParserInterface { - /** - * @param ContextInterface $context - * @param Cursor $cursor - * - * @return bool - */ public function parse(ContextInterface $context, Cursor $cursor): bool { if ($cursor->isIndented()) { diff --git a/libs/Daux.php b/libs/Daux.php index b329a4f..799eebf 100644 --- a/libs/Daux.php +++ b/libs/Daux.php @@ -13,6 +13,12 @@ class Daux public static $output; + /** @var Tree\Root */ + public $tree; + + /** @var Config */ + public $config; + /** @var \Todaymade\Daux\Format\Base\Generator */ protected $generator; @@ -25,12 +31,6 @@ class Daux /** @var Processor */ protected $processor; - /** @var Tree\Root */ - public $tree; - - /** @var Config */ - public $config; - /** @var bool */ private $merged_tree = false; @@ -38,12 +38,11 @@ class Daux { Daux::$output = $output; - $this->config = $config; } /** - * Generate the tree that will be used + * Generate the tree that will be used. */ public function generateTree() { @@ -94,6 +93,7 @@ class Daux /** * @return Config + * * @deprecated Use getConfig instead */ public function getParams() @@ -113,9 +113,6 @@ class Daux return $this->processor; } - /** - * @param Processor $processor - */ public function setProcessor(Processor $processor) { $this->processor = $processor; @@ -232,7 +229,7 @@ class Daux } /** - * Get all content file extensions + * Get all content file extensions. * * @return string[] */ @@ -257,7 +254,7 @@ class Daux /** * Writes a message to the output. * - * @param string|array $messages The message as an array of lines or a single string + * @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 */ @@ -269,7 +266,7 @@ class Daux /** * Writes a message to the output and adds a newline at the end. * - * @param string|array $messages The message as an array of lines of a single string + * @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 */ public static function writeln($messages, $options = 0) diff --git a/libs/DauxHelper.php b/libs/DauxHelper.php index b6777aa..c429f00 100644 --- a/libs/DauxHelper.php +++ b/libs/DauxHelper.php @@ -8,9 +8,8 @@ use Todaymade\Daux\Tree\Entry; class DauxHelper { /** - * Set a new base_url for the configuration + * Set a new base_url for the configuration. * - * @param Config $config * @param string $base_url */ public static function rebaseConfiguration(Config $config, $base_url) @@ -27,8 +26,8 @@ class DauxHelper } /** - * @param Config $config * @param string $current_url + * * @return array */ protected static function getTheme(Config $config, $current_url) @@ -98,9 +97,10 @@ class DauxHelper } /** - * Remove all '/./' and '/../' in a path, without actually checking the path + * Remove all '/./' and '/../' in a path, without actually checking the path. * * @param string $path + * * @return string */ public static function getCleanPath($path) @@ -125,8 +125,8 @@ class DauxHelper /** * Get the possible output file names for a source file. * - * @param Config $config * @param string $part + * * @return string[] */ public static function getFilenames(Config $config, $part) @@ -140,11 +140,12 @@ class DauxHelper } /** - * Locate a file in the tree. Returns the file if found or false + * Locate a file in the tree. Returns the file if found or false. * * @param Directory $tree * @param string $request - * @return Tree\Content|Tree\Raw|false + * + * @return false|Tree\Content|Tree\Raw */ public static function getFile($tree, $request) { @@ -163,6 +164,7 @@ class DauxHelper if ($node == '..') { $tree = $tree->getParent(); + continue; } @@ -171,6 +173,7 @@ class DauxHelper // node and proceed to the next url part if (isset($tree->getEntries()[$node])) { $tree = $tree->getEntries()[$node]; + continue; } @@ -178,6 +181,7 @@ class DauxHelper $node = DauxHelper::slug(urldecode($node)); if (isset($tree->getEntries()[$node])) { $tree = $tree->getEntries()[$node]; + continue; } @@ -187,6 +191,7 @@ class DauxHelper foreach (static::getFilenames($tree->getConfig(), $node) as $filename) { if (isset($tree->getEntries()[$filename])) { $tree = $tree->getEntries()[$filename]; + continue 2; } } @@ -219,17 +224,18 @@ class DauxHelper * Taken from Stringy * * @param string $title + * * @return string */ public static function slug($title) { // Convert to ASCII - if (function_exists("transliterator_transliterate")) { - $title = transliterator_transliterate("Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC;", $title); + if (function_exists('transliterator_transliterate')) { + $title = transliterator_transliterate('Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC;', $title); } - - $title = iconv("utf-8", "ASCII//TRANSLIT//IGNORE", $title); - + + $title = iconv('utf-8', 'ASCII//TRANSLIT//IGNORE', $title); + // Remove unsupported characters $title = preg_replace('/[^\x20-\x7E]/u', '', $title); @@ -250,6 +256,7 @@ class DauxHelper /** * @param string $from * @param string $to + * * @return string */ public static function getRelativePath($from, $to) @@ -276,10 +283,10 @@ class DauxHelper // add traversals up to first matching dir $padLength = (count($relPath) + $remaining - 1) * -1; $relPath = array_pad($relPath, $padLength, '..'); + break; - } else { - //$relPath[0] = './' . $relPath[0]; } + //$relPath[0] = './' . $relPath[0]; } } @@ -290,11 +297,13 @@ class DauxHelper { if (!is_string($path)) { $mess = sprintf('String expected but was given %s', gettype($path)); + throw new \InvalidArgumentException($mess); } if (!ctype_print($path)) { $mess = 'Path can NOT have non-printable characters or be empty'; + throw new \DomainException($mess); } @@ -310,6 +319,7 @@ class DauxHelper $parts = []; if (!preg_match($regExp, $path, $parts)) { $mess = sprintf('Path is NOT valid, was given %s', $path); + throw new \DomainException($mess); } @@ -333,8 +343,10 @@ class DauxHelper /** * @param Config $config * @param string $url - * @return Entry + * * @throws LinkNotFoundException + * + * @return Entry */ public static function resolveInternalFile($config, $url) { diff --git a/libs/Format/Base/EmbedImages.php b/libs/Format/Base/EmbedImages.php index 8cc440d..ffef74b 100644 --- a/libs/Format/Base/EmbedImages.php +++ b/libs/Format/Base/EmbedImages.php @@ -3,7 +3,7 @@ * Created by IntelliJ IDEA. * User: onigoetz * Date: 06/11/15 - * Time: 20:27 + * Time: 20:27. */ namespace Todaymade\Daux\Format\Base; @@ -67,7 +67,6 @@ class EmbedImages //Get any file corresponding to the right one $file = DauxHelper::getFile($this->tree, $url); - if ($file === false) { return false; } diff --git a/libs/Format/Base/Generator.php b/libs/Format/Base/Generator.php index e499309..c29e426 100644 --- a/libs/Format/Base/Generator.php +++ b/libs/Format/Base/Generator.php @@ -6,15 +6,11 @@ use Todaymade\Daux\Daux; interface Generator { - /** - * @param Daux $daux - */ public function __construct(Daux $daux); /** - * @param InputInterface $input - * @param OutputInterface $output * @param int $width + * * @return mixed */ public function generateAll(InputInterface $input, OutputInterface $output, $width); diff --git a/libs/Format/Base/LiveGenerator.php b/libs/Format/Base/LiveGenerator.php index 0230719..4e364e3 100644 --- a/libs/Format/Base/LiveGenerator.php +++ b/libs/Format/Base/LiveGenerator.php @@ -6,8 +6,6 @@ use Todaymade\Daux\Tree\Entry; interface LiveGenerator extends Generator { /** - * @param Entry $node - * @param Config $config * @return \Todaymade\Daux\Format\Base\Page */ public function generateOne(Entry $node, Config $config); diff --git a/libs/Format/Base/Page.php b/libs/Format/Base/Page.php index a7fd4c9..130418f 100644 --- a/libs/Format/Base/Page.php +++ b/libs/Format/Base/Page.php @@ -3,14 +3,14 @@ interface Page { /** - * Get the converted content, without any template + * Get the converted content, without any template. * * @return string */ public function getPureContent(); /** - * Get the full content + * Get the full content. * * @return mixed */ diff --git a/libs/Format/Confluence/Api.php b/libs/Format/Confluence/Api.php index 9e70638..77f1b47 100644 --- a/libs/Format/Confluence/Api.php +++ b/libs/Format/Confluence/Api.php @@ -24,7 +24,8 @@ class Api } /** - * This method is public due to test purposes + * This method is public due to test purposes. + * * @return Client */ public function getClient() @@ -39,9 +40,8 @@ class Api /** * The standard error message from guzzle is quite poor in informations, - * this will give little bit more sense to it and return it + * this will give little bit more sense to it and return it. * - * @param BadResponseException $e * @return \Exception */ protected function handleError(BadResponseException $e) @@ -101,10 +101,11 @@ class Api } /** - * Get a list of pages + * Get a list of pages. * * @param int $rootPage * @param bool $recursive + * * @return array */ public function getList($rootPage, $recursive = false) @@ -153,6 +154,7 @@ class Api * @param int $parent_id * @param string $title * @param string $content + * * @return int */ public function createPage($parent_id, $title, $content) @@ -224,7 +226,7 @@ class Api } $start = max($lineNumber - 3, 0); - $end = min($lineNumber + 2, count($lines)); + $end = min($lineNumber + 2, count($lines)); $maxWidth = strlen("$end"); @@ -236,7 +238,7 @@ class Api $gutter = substr(' ' . (' ' . $number), -$maxWidth) . ' | '; if ($number == $lineNumber) { - $spacing = str_repeat(" ", strlen($gutter) + $column - 2); + $spacing = str_repeat(' ', strlen($gutter) + $column - 2); $prepared[] = '>' . $gutter . $line . "\n " . $spacing . '^'; } else { $prepared[] = ' ' . $gutter . $line; @@ -247,9 +249,10 @@ class Api } /** - * Delete a page + * Delete a page. * * @param int $page_id + * * @return mixed */ public function deletePage($page_id) @@ -267,6 +270,7 @@ class Api // this name is uploaded try { $url = "content/$id/child/attachment?filename=" . urlencode($attachment['filename']); + return json_decode($this->getClient()->get($url)->getBody(), true); } catch (BadResponseException $e) { throw $this->handleError($e); @@ -318,7 +322,8 @@ class Api // the update URL is different if (count($result['results'])) { if ($this->getFileSize($attachment) == $result['results'][0]['extensions']['fileSize']) { - $write(" ( An attachment of the same size already exists, skipping. )"); + $write(' ( An attachment of the same size already exists, skipping. )'); + return; } diff --git a/libs/Format/Confluence/ContentPage.php b/libs/Format/Confluence/ContentPage.php index ee55ad0..7a0ec9d 100644 --- a/libs/Format/Confluence/ContentPage.php +++ b/libs/Format/Confluence/ContentPage.php @@ -20,7 +20,6 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage $content, $this->file, function ($src, array $attributes, Entry $file) { - //Add the attachment for later upload if ($file instanceof Raw) { $filename = basename($file->getPath()); @@ -45,10 +44,11 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage } /** - * Create an image tag for the specified filename + * Create an image tag for the specified filename. * * @param string $filename * @param array $attributes + * * @return string */ private function createImageTag($filename, $attributes) @@ -60,7 +60,7 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage $re = '/float:\s*?(left|right);?/'; if (preg_match($re, $value, $matches)) { $img .= ' ac:align="' . $matches[1] . '"'; - $value = preg_replace($re, "", $value, 1); + $value = preg_replace($re, '', $value, 1); } } diff --git a/libs/Format/Confluence/ContentTypes/Markdown/CodeRenderer.php b/libs/Format/Confluence/ContentTypes/Markdown/CodeRenderer.php index 041bed6..d87c212 100644 --- a/libs/Format/Confluence/ContentTypes/Markdown/CodeRenderer.php +++ b/libs/Format/Confluence/ContentTypes/Markdown/CodeRenderer.php @@ -7,7 +7,7 @@ abstract class CodeRenderer implements BlockRendererInterface { public function escapeCDATA($content) { - return str_replace("]]>", "]]]]>", $content); + return str_replace(']]>', ']]]]>', $content); } public function getHTMLElement($body, $language) diff --git a/libs/Format/Confluence/ContentTypes/Markdown/CommonMarkConverter.php b/libs/Format/Confluence/ContentTypes/Markdown/CommonMarkConverter.php index 1c2f166..0a066da 100644 --- a/libs/Format/Confluence/ContentTypes/Markdown/CommonMarkConverter.php +++ b/libs/Format/Confluence/ContentTypes/Markdown/CommonMarkConverter.php @@ -1,7 +1,7 @@ 'html/xml', 'xml' => 'html/xml', 'js' => 'javascript']; /** - * @param AbstractBlock $block - * @param ElementRendererInterface $htmlRenderer * @param bool $inTightList * * @return HtmlElement|string diff --git a/libs/Format/Confluence/ContentTypes/Markdown/ImageRenderer.php b/libs/Format/Confluence/ContentTypes/Markdown/ImageRenderer.php index a63e193..67d523a 100644 --- a/libs/Format/Confluence/ContentTypes/Markdown/ImageRenderer.php +++ b/libs/Format/Confluence/ContentTypes/Markdown/ImageRenderer.php @@ -27,7 +27,6 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf /** * @param Image $inline - * @param ElementRendererInterface $htmlRenderer * * @return HtmlElement */ @@ -49,9 +48,6 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf return $this->parent->render($inline, $htmlRenderer); } - /** - * @param ConfigurationInterface $configuration - */ public function setConfiguration(ConfigurationInterface $configuration) { $this->parent->setConfiguration($configuration); diff --git a/libs/Format/Confluence/ContentTypes/Markdown/IndentedCodeRenderer.php b/libs/Format/Confluence/ContentTypes/Markdown/IndentedCodeRenderer.php index 3e04fb7..576fd6a 100644 --- a/libs/Format/Confluence/ContentTypes/Markdown/IndentedCodeRenderer.php +++ b/libs/Format/Confluence/ContentTypes/Markdown/IndentedCodeRenderer.php @@ -8,8 +8,6 @@ use League\CommonMark\HtmlElement; class IndentedCodeRenderer extends CodeRenderer { /** - * @param AbstractBlock $block - * @param ElementRendererInterface $htmlRenderer * @param bool $inTightList * * @return HtmlElement @@ -20,6 +18,6 @@ class IndentedCodeRenderer extends CodeRenderer throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block)); } - return $this->getHTMLElement($block->getStringContent(), ""); + return $this->getHTMLElement($block->getStringContent(), ''); } } diff --git a/libs/Format/Confluence/ContentTypes/Markdown/LinkRenderer.php b/libs/Format/Confluence/ContentTypes/Markdown/LinkRenderer.php index 8c0cf22..9bb662f 100644 --- a/libs/Format/Confluence/ContentTypes/Markdown/LinkRenderer.php +++ b/libs/Format/Confluence/ContentTypes/Markdown/LinkRenderer.php @@ -10,7 +10,6 @@ class LinkRenderer extends \Todaymade\Daux\ContentTypes\Markdown\LinkRenderer { /** * @param AbstractInline|Link $inline - * @param ElementRendererInterface $htmlRenderer * * @return HtmlElement */ diff --git a/libs/Format/Confluence/Generator.php b/libs/Format/Confluence/Generator.php index 035d58b..e425ac3 100644 --- a/libs/Format/Confluence/Generator.php +++ b/libs/Format/Confluence/Generator.php @@ -18,9 +18,6 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator /** @var Daux */ protected $daux; - /** - * @param Daux $daux - */ public function __construct(Daux $daux) { $this->daux = $daux; diff --git a/libs/Format/Confluence/Publisher.php b/libs/Format/Confluence/Publisher.php index 291440b..1c699c8 100644 --- a/libs/Format/Confluence/Publisher.php +++ b/libs/Format/Confluence/Publisher.php @@ -7,16 +7,6 @@ class Publisher { use RunAction; - /** - * @var Api - */ - protected $client; - - /** - * @var Config - */ - protected $confluence; - /** * @var int terminal width */ @@ -27,6 +17,16 @@ class Publisher */ public $output; + /** + * @var Api + */ + protected $client; + + /** + * @var Config + */ + protected $confluence; + /** * @param $confluence */ @@ -62,7 +62,7 @@ class Publisher ); $published = $this->run( - "Create placeholder pages...", + 'Create placeholder pages...', function () use ($tree, $published) { return $this->createRecursive($this->confluence->getAncestorId(), $tree, $published); } @@ -89,6 +89,7 @@ class Publisher if ($this->confluence->hasRootId()) { $published = $this->client->getPage($this->confluence->getRootId()); $this->confluence->setAncestorId($published['ancestor_id']); + return $published; } diff --git a/libs/Format/Confluence/PublisherDelete.php b/libs/Format/Confluence/PublisherDelete.php index 8d06fc3..5879cc3 100644 --- a/libs/Format/Confluence/PublisherDelete.php +++ b/libs/Format/Confluence/PublisherDelete.php @@ -13,7 +13,7 @@ class PublisherDelete protected $deletable; /** - * @var boolean should delete ? + * @var bool should delete ? */ protected $delete; @@ -28,7 +28,6 @@ class PublisherDelete $this->delete = $delete; $this->client = $client; - $this->deletable = []; } @@ -72,8 +71,8 @@ class PublisherDelete protected function displayDeletable() { $this->output->writeLn('Listing obsolete pages...'); - $this->output->writeLn("> The following pages will not be deleted, but just listed for information."); - $this->output->writeLn("> If you want to delete these pages, you need to set the --delete flag on the command."); + $this->output->writeLn('> The following pages will not be deleted, but just listed for information.'); + $this->output->writeLn('> If you want to delete these pages, you need to set the --delete flag on the command.'); foreach ($this->deletable as $id => $title) { $this->output->writeLn("- $title"); } diff --git a/libs/Format/HTML/Config.php b/libs/Format/HTML/Config.php index 477e0e2..caf0e55 100644 --- a/libs/Format/HTML/Config.php +++ b/libs/Format/HTML/Config.php @@ -10,7 +10,7 @@ class Config extends BaseConfig return [ 'name' => 'GitHub', - 'basepath' => (strpos($url, 'https://github.com/') === 0 ? '' : 'https://github.com/') . trim($url, '/') + 'basepath' => (strpos($url, 'https://github.com/') === 0 ? '' : 'https://github.com/') . trim($url, '/'), ]; } @@ -20,11 +20,10 @@ class Config extends BaseConfig $edit_on = $this->getValue('edit_on'); if (is_string($edit_on)) { return $this->prepareGithubUrl($edit_on); - } else { - $edit_on['basepath'] = rtrim($edit_on['basepath'], '/'); - - return $edit_on; } + $edit_on['basepath'] = rtrim($edit_on['basepath'], '/'); + + return $edit_on; } if ($this->hasValue('edit_on_github')) { diff --git a/libs/Format/HTML/ContentPage.php b/libs/Format/HTML/ContentPage.php index 4ee4829..aebab03 100644 --- a/libs/Format/HTML/ContentPage.php +++ b/libs/Format/HTML/ContentPage.php @@ -4,6 +4,10 @@ use Todaymade\Daux\Tree\Root; class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage { + /** + * @var Template + */ + public $templateRenderer; /** * @var string */ @@ -14,11 +18,6 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage */ private $homepage; - /** - * @var Template - */ - public $templateRenderer; - private function isHomepage(): bool { // If the current page isn't the index, no chance it is the landing page @@ -49,6 +48,7 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage /** * @param \Todaymade\Daux\Tree\Directory[] $parents * @param bool $multilanguage + * * @return array */ private function getBreadcrumbTrail($parents, $multilanguage) @@ -98,7 +98,7 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage 'breadcrumbs' => $config->getHTML()->hasBreadcrumbs(), 'prev' => $this->file->getPrevious(), 'next' => $this->file->getNext(), - 'attributes' => $this->file->getAttribute() + 'attributes' => $this->file->getAttribute(), ]; if ($page['breadcrumbs']) { @@ -112,13 +112,13 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage $context = ['page' => $page, 'config' => $config]; - $template = "theme::content"; + $template = 'theme::content'; if ($this->isLanding()) { - $template = "theme::home"; + $template = 'theme::home'; } if (array_key_exists('template', $page['attributes'])) { - $template = "theme::" . $page['attributes']['template']; + $template = 'theme::' . $page['attributes']['template']; } return $this->templateRenderer->render($template, $context); diff --git a/libs/Format/HTML/ContentTypes/Markdown/CommonMarkConverter.php b/libs/Format/HTML/ContentTypes/Markdown/CommonMarkConverter.php index 7ab3e13..df7ad5c 100644 --- a/libs/Format/HTML/ContentTypes/Markdown/CommonMarkConverter.php +++ b/libs/Format/HTML/ContentTypes/Markdown/CommonMarkConverter.php @@ -1,9 +1,9 @@ daux, $url); + return DauxHelper::getRelativePath($this->daux->getCurrentPage()->getUrl(), $file->getUrl()); } catch (LinkNotFoundException $e) { if ($this->daux->isStatic()) { @@ -67,11 +71,10 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf /** * @param Image $inline - * @param ElementRendererInterface $htmlRenderer - * - * @return HtmlElement * * @throws LinkNotFoundException + * + * @return HtmlElement */ public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer) { @@ -84,9 +87,6 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf return $this->parent->render($inline, $htmlRenderer); } - /** - * @param ConfigurationInterface $configuration - */ public function setConfiguration(ConfigurationInterface $configuration) { $this->config = $configuration; diff --git a/libs/Format/HTML/ContentTypes/Markdown/TOC/Entry.php b/libs/Format/HTML/ContentTypes/Markdown/TOC/Entry.php index ca2bbf4..cabce76 100644 --- a/libs/Format/HTML/ContentTypes/Markdown/TOC/Entry.php +++ b/libs/Format/HTML/ContentTypes/Markdown/TOC/Entry.php @@ -6,7 +6,7 @@ class Entry { protected $content; protected $level; - protected $parent = null; + protected $parent; protected $children = []; public function __construct(Heading $content) @@ -56,7 +56,6 @@ class Entry } /** - * @param Entry $parent * @param bool $addChild */ public function setParent(Entry $parent, $addChild = true) @@ -67,9 +66,6 @@ class Entry } } - /** - * @param Entry $child - */ public function addChild(Entry $child) { $child->setParent($this, false); diff --git a/libs/Format/HTML/ContentTypes/Markdown/TOC/Processor.php b/libs/Format/HTML/ContentTypes/Markdown/TOC/Processor.php index e95f6cf..a0265b5 100644 --- a/libs/Format/HTML/ContentTypes/Markdown/TOC/Processor.php +++ b/libs/Format/HTML/ContentTypes/Markdown/TOC/Processor.php @@ -28,11 +28,6 @@ class Processor $this->config = $config; } - /** - * @param DocumentParsedEvent $event - * - * @return void - */ public function onDocumentParsed(DocumentParsedEvent $event) { $document = $event->getDocument(); @@ -48,6 +43,7 @@ class Processor if ($node instanceof TableOfContents && !$event->isEntering()) { $tocs[] = $node; + continue; } @@ -74,27 +70,25 @@ class Processor protected function getUniqueId(Document $document, $proposed) { - if ($proposed == "page_") { - $proposed = "page_section_" . (count($document->heading_ids) + 1); + if ($proposed == 'page_') { + $proposed = 'page_section_' . (count($document->heading_ids) + 1); } // Quick path, it's a unique ID if (!in_array($proposed, $document->heading_ids)) { $document->heading_ids[] = $proposed; + return $proposed; } $extension = 1; // Initialize the variable at one, so on the first iteration we have 2 do { - $extension++; + ++$extension; } while (in_array("$proposed-$extension", $document->heading_ids)); return "$proposed-$extension"; } - /** - * @param Heading $node - */ protected function ensureHeadingHasId(Document $document, Heading $node) { // If the node has an ID, no need to generate it, just check it's unique @@ -129,9 +123,10 @@ class Processor } /** - * Make a tree of the list of headings + * Make a tree of the list of headings. * * @param Entry[] $headings + * * @return RootEntry */ public function generate($headings) @@ -147,19 +142,21 @@ class Processor $parent->addChild($heading); $previous = $heading; + continue; } - if ($heading->getLevel() > $previous->getLevel()) { $previous->addChild($heading); $previous = $heading; + continue; } //if ($heading->getLevel() == $previous->getLevel()) { $previous->getParent()->addChild($heading); $previous = $heading; + continue; //} } @@ -169,6 +166,7 @@ class Processor /** * @param Entry[] $entries + * * @return ListBlock */ protected function render(array $entries) @@ -220,7 +218,6 @@ class Processor } /** - * @param Heading $node * @return Node[] */ protected function cloneChildren(Heading $node) diff --git a/libs/Format/HTML/ContentTypes/Markdown/TOC/Renderer.php b/libs/Format/HTML/ContentTypes/Markdown/TOC/Renderer.php index 14853a0..6100779 100644 --- a/libs/Format/HTML/ContentTypes/Markdown/TOC/Renderer.php +++ b/libs/Format/HTML/ContentTypes/Markdown/TOC/Renderer.php @@ -25,6 +25,7 @@ class Renderer implements BlockRendererInterface } $content = $htmlRenderer->renderBlocks($block->children()); + return $this->config->templateRenderer ->getEngine($this->config) ->render('theme::partials/table_of_contents', ['content' => $content]); diff --git a/libs/Format/HTML/Generator.php b/libs/Format/HTML/Generator.php index 35e13cf..9feb99c 100755 --- a/libs/Format/HTML/Generator.php +++ b/libs/Format/HTML/Generator.php @@ -16,7 +16,8 @@ use Todaymade\Daux\Tree\Raw; class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator { - use RunAction, HTMLUtils; + use RunAction; + use HTMLUtils; /** @var Daux */ protected $daux; @@ -26,9 +27,6 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator protected $indexed_pages = []; - /** - * @param Daux $daux - */ public function __construct(Daux $daux) { $config = $daux->getConfig(); @@ -93,9 +91,10 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator * script code, and embedded objects. Add line breaks around * block-level tags to prevent word joining after tag removal. * Also collapse whitespace to single space and trim result. - * modified from: http://nadeausoftware.com/articles/2007/09/php_tip_how_strip_html_tags_web_page + * modified from: http://nadeausoftware.com/articles/2007/09/php_tip_how_strip_html_tags_web_page. * * @param string $text + * * @return string */ private function sanitize($text) @@ -133,21 +132,18 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator // Sometimes strings are detected as invalid UTF-8 and json_encode can't treat them // iconv can fix those strings - $text = iconv('UTF-8', 'UTF-8//IGNORE', $text); - - return $text; + return iconv('UTF-8', 'UTF-8//IGNORE', $text); } /** - * Recursively generate the documentation + * Recursively generate the documentation. * - * @param Directory $tree * @param string $output_dir - * @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, GlobalConfig $config, $output, $width, $index_pages, $base_url = '') @@ -185,7 +181,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator $this->indexed_pages[] = [ 'title' => $node->getTitle(), 'text' => $this->sanitize($generated->getPureContent()), - 'tags' => '', + 'tags' => '', 'url' => $node->getUrl(), ]; } @@ -196,8 +192,6 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator } /** - * @param Entry $node - * @param GlobalConfig $config * @return \Todaymade\Daux\Format\Base\Page */ public function generateOne(Entry $node, GlobalConfig $config) diff --git a/libs/Format/HTML/HTMLUtils.php b/libs/Format/HTML/HTMLUtils.php index 756ed7b..49664ad 100644 --- a/libs/Format/HTML/HTMLUtils.php +++ b/libs/Format/HTML/HTMLUtils.php @@ -14,7 +14,7 @@ trait HTMLUtils } /** - * Copy all files from $local to $destination + * Copy all files from $local to $destination. * * @param string $destination * @param string $local_base diff --git a/libs/Format/HTML/Template.php b/libs/Format/HTML/Template.php index b1ea48d..ab3318a 100644 --- a/libs/Format/HTML/Template.php +++ b/libs/Format/HTML/Template.php @@ -55,7 +55,7 @@ class Template /** * @param string $name - * @param array $data + * * @return string */ public function render($name, array $data = []) @@ -196,6 +196,7 @@ class Template /** * @param string $separator + * * @return string */ private function getSeparator($separator) diff --git a/libs/Format/HTMLFile/Book.php b/libs/Format/HTMLFile/Book.php index 8e0ed21..5023625 100644 --- a/libs/Format/HTMLFile/Book.php +++ b/libs/Format/HTMLFile/Book.php @@ -1,6 +1,5 @@ getUrl()); + return 'file_' . str_replace('/', '_', $page->getUrl()); } protected function buildNavigation(Directory $tree) @@ -38,7 +37,7 @@ class Book $nav[] = [ 'title' => $node->getTitle(), - 'href' => "#" . $this->getPageUrl($node), + 'href' => '#' . $this->getPageUrl($node), ]; } elseif ($node instanceof Directory) { if (!$node->hasContent()) { @@ -49,7 +48,7 @@ class Book $nav[] = [ 'title' => $node->getTitle(), - 'href' => "#" . $this->getPageUrl($page_index), + 'href' => '#' . $this->getPageUrl($page_index), 'children' => $this->buildNavigation($node), ]; } @@ -89,7 +88,7 @@ class Book protected function generateCover() { - return "
" . + return '
' . "

{$this->cover['title']}

" . "

{$this->cover['subject']} by {$this->cover['author']}

" . '
 
'; diff --git a/libs/Format/HTMLFile/ContentPage.php b/libs/Format/HTMLFile/ContentPage.php index ec86075..277579a 100644 --- a/libs/Format/HTMLFile/ContentPage.php +++ b/libs/Format/HTMLFile/ContentPage.php @@ -13,7 +13,7 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage // Embed images // We do it after generation so we can catch the images that were in html already - $content = (new EmbedImages($this->config->getTree())) + return (new EmbedImages($this->config->getTree())) ->embed( $content, $this->file, @@ -29,7 +29,5 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage return ""; } ); - - return $content; } } diff --git a/libs/Format/HTMLFile/ContentTypes/Markdown/CommonMarkConverter.php b/libs/Format/HTMLFile/ContentTypes/Markdown/CommonMarkConverter.php index 4f3dd3a..b362310 100644 --- a/libs/Format/HTMLFile/ContentTypes/Markdown/CommonMarkConverter.php +++ b/libs/Format/HTMLFile/ContentTypes/Markdown/CommonMarkConverter.php @@ -1,7 +1,6 @@ setAttribute('href', '#' . $urlAndHash[1]); - + return $element; } diff --git a/libs/Format/HTMLFile/Generator.php b/libs/Format/HTMLFile/Generator.php index 454b7ac..14bfaf0 100644 --- a/libs/Format/HTMLFile/Generator.php +++ b/libs/Format/HTMLFile/Generator.php @@ -4,13 +4,14 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Todaymade\Daux\Console\RunAction; use Todaymade\Daux\Daux; -use Todaymade\Daux\Format\HTML\Template; use Todaymade\Daux\Format\HTML\HTMLUtils; +use Todaymade\Daux\Format\HTML\Template; use Todaymade\Daux\Format\HTMLFile\ContentTypes\Markdown\ContentType; class Generator implements \Todaymade\Daux\Format\Base\Generator { - use RunAction, HTMLUtils; + use RunAction; + use HTMLUtils; /** @var Daux */ protected $daux; @@ -18,9 +19,6 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator /** @var Template */ protected $templateRenderer; - /** - * @param Daux $daux - */ public function __construct(Daux $daux) { $config = $daux->getConfig(); @@ -63,7 +61,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator $data = [ 'author' => $config->getAuthor(), 'title' => $config->getTitle(), - 'subject' => $config->getTagline() + 'subject' => $config->getTagline(), ]; $book = new Book($this->daux->tree, $data); diff --git a/libs/FormatDate.php b/libs/FormatDate.php index 00f5517..b853c78 100644 --- a/libs/FormatDate.php +++ b/libs/FormatDate.php @@ -11,7 +11,7 @@ class FormatDate $timetype = IntlDateFormatter::SHORT; $timezone = null; - if (!extension_loaded("intl")) { + if (!extension_loaded('intl')) { $locale = 'en'; $timezone = 'GMT'; } diff --git a/libs/GeneratorHelper.php b/libs/GeneratorHelper.php index 3eaf188..0b76fe7 100755 --- a/libs/GeneratorHelper.php +++ b/libs/GeneratorHelper.php @@ -5,7 +5,7 @@ use RuntimeException; class GeneratorHelper { /** - * Remove a directory recursively + * Remove a directory recursively. * * @param string $dir */ @@ -26,7 +26,7 @@ class GeneratorHelper } /** - * Copy files recursively + * Copy files recursively. * * @param string $source * @param string $destination diff --git a/libs/Processor.php b/libs/Processor.php index 122a732..96d006e 100644 --- a/libs/Processor.php +++ b/libs/Processor.php @@ -22,8 +22,6 @@ class Processor protected $width; /** - * @param Daux $daux - * @param OutputInterface $output * @param int $width */ public function __construct(Daux $daux, OutputInterface $output, $width) @@ -37,10 +35,8 @@ class Processor * With this connection point, you can transform * the tree as you want, move pages, modify * pages and even add new ones. - * - * @param Root $root */ - public function manipulateTree(/** @scrutinizer ignore-unused */ Root $root) + public function manipulateTree(/* @scrutinizer ignore-unused */ Root $root) { } @@ -48,10 +44,8 @@ class Processor * This connection point provides * a way to extend the Markdown * parser and renderer. - * - * @param Environment $environment */ - public function extendCommonMarkEnvironment(/** @scrutinizer ignore-unused */ Environment $environment) + public function extendCommonMarkEnvironment(/* @scrutinizer ignore-unused */ Environment $environment) { } diff --git a/libs/Server/ExtensionMimeTypeGuesser.php b/libs/Server/ExtensionMimeTypeGuesser.php index 30b8db4..e1de672 100644 --- a/libs/Server/ExtensionMimeTypeGuesser.php +++ b/libs/Server/ExtensionMimeTypeGuesser.php @@ -3,7 +3,7 @@ use Symfony\Component\Mime\MimeTypeGuesserInterface; /** - * Guesses the mime type using the file's extension + * Guesses the mime type using the file's extension. */ class ExtensionMimeTypeGuesser implements MimeTypeGuesserInterface { @@ -22,12 +22,12 @@ class ExtensionMimeTypeGuesser implements MimeTypeGuesserInterface { $extension = pathinfo($path, PATHINFO_EXTENSION); - if ($extension == "css") { - return "text/css"; + if ($extension == 'css') { + return 'text/css'; } - if ($extension == "js") { - return "application/javascript"; + if ($extension == 'js') { + return 'application/javascript'; } return null; diff --git a/libs/Server/Server.php b/libs/Server/Server.php index ee5d5ba..f6af68a 100755 --- a/libs/Server/Server.php +++ b/libs/Server/Server.php @@ -5,8 +5,8 @@ use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Mime\MimeTypes; -use Todaymade\Daux\Daux; use Todaymade\Daux\ConfigBuilder; +use Todaymade\Daux\Daux; use Todaymade\Daux\DauxHelper; use Todaymade\Daux\Exception; use Todaymade\Daux\Format\Base\ComputedRawPage; @@ -25,8 +25,16 @@ class Server */ private $request; + public function __construct(Daux $daux) + { + $this->daux = $daux; + + $this->request = Request::createFromGlobals(); + $this->base_url = $this->request->getHttpHost() . $this->request->getBaseUrl() . '/'; + } + /** - * Serve the documentation + * Serve the documentation. * * @throws Exception */ @@ -63,25 +71,18 @@ class Server $server->createResponse($page)->prepare($server->request)->send(); } - public function __construct(Daux $daux) - { - $this->daux = $daux; - - $this->request = Request::createFromGlobals(); - $this->base_url = $this->request->getHttpHost() . $this->request->getBaseUrl() . "/"; - } - /** * Create a temporary file with the file suffix, for mime type detection. * * @param string $postfix + * * @return string */ private function getTemporaryFile($postfix) { $sysFileName = tempnam(sys_get_temp_dir(), 'daux'); if ($sysFileName === false) { - throw new \RuntimeException("Could not create temporary file"); + throw new \RuntimeException('Could not create temporary file'); } $newFileName = $sysFileName . $postfix; @@ -93,11 +94,10 @@ class Server return $newFileName; } - throw new \RuntimeException("Could not create temporary file"); + throw new \RuntimeException('Could not create temporary file'); } /** - * @param Page $page * @return Response */ public function createResponse(Page $page) @@ -114,6 +114,7 @@ class Server if ($page instanceof ComputedRawPage) { $file = $this->getTemporaryFile($page->getFilename()); file_put_contents($file, $page->getContent()); + return new BinaryFileResponse($file); } @@ -129,16 +130,16 @@ class Server DauxHelper::rebaseConfiguration($config, '//' . $this->base_url); - return $config; } /** - * Handle an incoming request + * Handle an incoming request. * - * @return \Todaymade\Daux\Format\Base\Page * @throws Exception * @throws NotFoundException + * + * @return \Todaymade\Daux\Format\Base\Page */ public function handle() { @@ -158,11 +159,13 @@ class Server } /** - * Handle a request on custom themes + * Handle a request on custom themes. * * @param string $request - * @return \Todaymade\Daux\Format\Base\Page + * * @throws NotFoundException + * + * @return \Todaymade\Daux\Format\Base\Page */ public function serveTheme($request) { @@ -172,13 +175,15 @@ class Server return new RawPage($file); } - throw new NotFoundException; + throw new NotFoundException(); } /** * @param string $request - * @return \Todaymade\Daux\Format\Base\Page + * * @throws NotFoundException + * + * @return \Todaymade\Daux\Format\Base\Page */ private function getPage($request) { diff --git a/libs/Tree/Builder.php b/libs/Tree/Builder.php index 5d39c86..487122c 100644 --- a/libs/Tree/Builder.php +++ b/libs/Tree/Builder.php @@ -14,7 +14,7 @@ class Builder '.DS_Store', 'Thumbs.db', ]; - protected static function isIgnored(\SplFileInfo $file, $ignore) + protected static function isIgnored(SplFileInfo $file, $ignore) { $filename = $file->getFilename(); @@ -34,9 +34,10 @@ class Builder } /** - * Get name for a file + * Get name for a file. * * @param string $path + * * @return string */ protected static function getName($path) @@ -52,7 +53,7 @@ class Builder } /** - * Build the initial tree + * Build the initial tree. * * @param Directory $node * @param array $ignore @@ -96,8 +97,6 @@ class Builder } /** - * @param Directory $parent - * @param SplFileInfo $file * @return Content|Raw */ public static function createContent(Directory $parent, SplFileInfo $file) @@ -141,6 +140,7 @@ class Builder /** * @param string $filename + * * @return string */ public static function removeSortingInformations($filename) @@ -154,8 +154,8 @@ class Builder } /** - * @param Directory $parent * @param string $title + * * @return Directory */ public static function getOrCreateDir(Directory $parent, $title) @@ -173,8 +173,8 @@ class Builder } /** - * @param Directory $parent * @param string $path + * * @return ContentAbstract */ public static function getOrCreatePage(Directory $parent, $path) @@ -214,9 +214,7 @@ class Builder } /** - * Sort the tree recursively - * - * @param Directory $current + * Sort the tree recursively. */ public static function sortTree(Directory $current) { @@ -229,10 +227,10 @@ class Builder } /** - * Calculate next and previous for all pages + * Calculate next and previous for all pages. * - * @param Directory $current * @param null|Content $prev + * * @return null|Content */ public static function finalizeTree(Directory $current, $prev = null) diff --git a/libs/Tree/Content.php b/libs/Tree/Content.php index ab8aa69..762bc76 100644 --- a/libs/Tree/Content.php +++ b/libs/Tree/Content.php @@ -25,7 +25,7 @@ class Content extends ContentAbstract if ($this->manuallySetContent) { $content = $this->content; } elseif (!$this->getPath()) { - throw new RuntimeException("Empty content"); + throw new RuntimeException('Empty content'); } else { $content = file_get_contents($this->getPath()); } @@ -40,9 +40,6 @@ class Content extends ContentAbstract return $frontMatter->parse($content); } - /** - * @return string - */ public function getContent(): string { if ($this->attributes === null) { @@ -52,9 +49,6 @@ class Content extends ContentAbstract return $this->content; } - /** - * @param string $content - */ public function setContent(string $content): void { $this->manuallySetContent = true; @@ -69,9 +63,6 @@ class Content extends ContentAbstract return $this->previous; } - /** - * @param Content $previous - */ public function setPrevious(Content $previous) { $this->previous = $previous; @@ -85,9 +76,6 @@ class Content extends ContentAbstract return $this->next; } - /** - * @param Content $next - */ public function setNext(Content $next) { $this->next = $next; @@ -130,10 +118,11 @@ class Content extends ContentAbstract } /** - * Get one or all attributes for the content + * Get one or all attributes for the content. * - * @param string|null $key - * @return array|mixed|null + * @param null|string $key + * + * @return null|array|mixed */ public function getAttribute($key = null) { diff --git a/libs/Tree/ContentAbstract.php b/libs/Tree/ContentAbstract.php index 1571499..8c0590e 100644 --- a/libs/Tree/ContentAbstract.php +++ b/libs/Tree/ContentAbstract.php @@ -5,17 +5,11 @@ abstract class ContentAbstract extends Entry /** @var string */ protected $content; - /** - * @return string - */ public function getContent(): string { return $this->content; } - /** - * @param string $content - */ public function setContent(string $content): void { $this->content = $content; diff --git a/libs/Tree/Directory.php b/libs/Tree/Directory.php index 4af7072..aa10117 100644 --- a/libs/Tree/Directory.php +++ b/libs/Tree/Directory.php @@ -44,6 +44,7 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate if ($name == 'index' || $name == '_index') { $buckets['index'][$key] = $entry; + continue; } @@ -51,10 +52,12 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate if (is_numeric($name[1])) { $exploded = explode('_', $name); $buckets['down_numeric'][abs(substr($exploded[0], 1))][$key] = $entry; + continue; } $buckets['down'][$key] = $entry; + continue; } @@ -62,16 +65,19 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate if (is_numeric($name[1])) { $exploded = explode('_', $name); $buckets['up_numeric'][abs(substr($exploded[0], 1))][$key] = $entry; + continue; } $buckets['up'][$key] = $entry; + continue; } if (is_numeric($name[0])) { $exploded = explode('_', $name); $buckets['numeric'][abs($exploded[0])][$key] = $entry; + continue; } @@ -124,9 +130,6 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate unset($this->children[$entry->getUri()]); } - /** - * @return Config - */ public function getConfig(): Config { if (!$this->parent) { @@ -147,9 +150,6 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate return false; } - /** - * @return Content|null - */ public function getIndexPage(): ?Content { $indexPage = $this->getLocalIndexPage(); @@ -166,8 +166,7 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate } /** - * Seek the first available page from descendants - * @return Content|null + * Seek the first available page from descendants. */ public function seekFirstPage(): ?Content { @@ -191,9 +190,6 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate return null; } - /** - * @return Content|null - */ public function getFirstPage(): ?Content { if ($this->first_page) { @@ -226,9 +222,6 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate return null; } - /** - * @param Content $first_page - */ public function setFirstPage(Content $first_page) { $this->first_page = $first_page; @@ -236,16 +229,15 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate /** * Used when creating the navigation. - * Hides folders without showable content - * - * @return bool + * Hides folders without showable content. */ public function hasContent(): bool { foreach ($this->getEntries() as $node) { if ($node instanceof Content) { return true; - } elseif ($node instanceof self) { + } + if ($node instanceof self) { if ($node->hasContent()) { return true; } @@ -270,9 +262,11 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate } /** - * Whether a offset exists - * @param mixed $offset An offset to check for. - * @return bool true on success or false on failure. + * Whether a offset exists. + * + * @param mixed $offset an offset to check for + * + * @return bool true on success or false on failure */ public function offsetExists($offset): bool { @@ -280,9 +274,11 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate } /** - * Offset to retrieve - * @param mixed $offset The offset to retrieve. - * @return Entry Can return all value types. + * Offset to retrieve. + * + * @param mixed $offset the offset to retrieve + * + * @return Entry can return all value types */ public function offsetGet($offset) { @@ -290,10 +286,10 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate } /** - * Offset to set - * @param mixed $offset The offset to assign the value to. - * @param Entry $value The value to set. - * @return void + * Offset to set. + * + * @param mixed $offset the offset to assign the value to + * @param Entry $value the value to set */ public function offsetSet($offset, $value) { @@ -305,9 +301,9 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate } /** - * Offset to unset + * Offset to unset. + * * @param string $offset the offset to unset - * @return void */ public function offsetUnset($offset) { diff --git a/libs/Tree/Entry.php b/libs/Tree/Entry.php index 8ba569d..50a9060 100644 --- a/libs/Tree/Entry.php +++ b/libs/Tree/Entry.php @@ -23,7 +23,6 @@ abstract class Entry protected $path; /** - * @param Directory $parent * @param string $uri * @param SplFileInfo $info */ @@ -86,9 +85,6 @@ abstract class Entry return $this->title; } - /** - * @param string $title - */ public function setTitle(string $title) { $this->title = $title; @@ -103,7 +99,7 @@ abstract class Entry } /** - * Return all parents starting with the root + * Return all parents starting with the root. * * @return Directory[] */ @@ -118,9 +114,6 @@ abstract class Entry return $parents; } - /** - * @param Directory $parent - */ protected function setParent(Directory $parent) { if ($this->parent) { @@ -140,9 +133,7 @@ abstract class Entry } /** - * Get the path to the file from the root of the documentation - * - * @return string + * Get the path to the file from the root of the documentation. */ public function getRelativePath(): string { @@ -154,17 +145,11 @@ abstract class Entry return substr($this->path, strlen($root->getPath()) + 1); } - /** - * @return SplFileInfo - */ public function getFileinfo(): SplFileInfo { return $this->info; } - /** - * @return string - */ public function getUrl(): string { $url = ''; diff --git a/libs/Tree/Root.php b/libs/Tree/Root.php index c7abfce..7c2dc04 100644 --- a/libs/Tree/Root.php +++ b/libs/Tree/Root.php @@ -11,7 +11,7 @@ class Root extends Directory protected $activeNode; /** - * The root doesn't have a parent + * The root doesn't have a parent. */ public function __construct(Config $config) { @@ -21,17 +21,11 @@ class Root extends Directory $this->path = $config->getDocumentationDirectory(); } - /** - * @return Config - */ public function getConfig(): Config { return $this->config; } - /** - * @param Config $config - */ public function setConfig(Config $config) { $this->config = $config; diff --git a/libs/bootstrap.php b/libs/bootstrap.php index 3d0b9bd..26b020d 100644 --- a/libs/bootstrap.php +++ b/libs/bootstrap.php @@ -11,7 +11,7 @@ function loadApp() if (file_exists(__DIR__ . '/../vendor/autoload.php')) { return require_once __DIR__ . '/../vendor/autoload.php'; } - + throw new Exception('Impossible to load Daux, missing vendor/'); } @@ -21,16 +21,16 @@ $loader = loadApp(); // find the daux processor extensions if ($loader) { $ext = __DIR__ . '/../daux'; - if (is_dir(getcwd() . "/daux")) { - $ext = getcwd() . "/daux"; + if (is_dir(getcwd() . '/daux')) { + $ext = getcwd() . '/daux'; } - + $env = getenv('DAUX_EXTENSION'); if ($env && is_dir($env)) { $ext = $env; } - + define('DAUX_EXTENSION', $ext); - $loader->setPsr4("Todaymade\\Daux\\Extension\\", $ext); + $loader->setPsr4('Todaymade\\Daux\\Extension\\', $ext); } diff --git a/tests/ContentTypes/Markdown/LinkRendererTest.php b/tests/ContentTypes/Markdown/LinkRendererTest.php index 9b69c1d..9d5fe9d 100644 --- a/tests/ContentTypes/Markdown/LinkRendererTest.php +++ b/tests/ContentTypes/Markdown/LinkRendererTest.php @@ -1,12 +1,12 @@ withDocumentationDirectory($root->url()) ->withValidContentExtensions(['md']) ->with([ - 'base_url' => '' + 'base_url' => '', ]) ->build(); - $tree = new Root($config); Builder::build($tree, []); diff --git a/tests/DauxHelperTest.php b/tests/DauxHelperTest.php index 36c1fe3..36ccc73 100644 --- a/tests/DauxHelperTest.php +++ b/tests/DauxHelperTest.php @@ -1,7 +1,6 @@ ['name' => 'Bitbucket', 'basepath' => 'https://bitbucket.org/dauxio/daux.io/src/master/docs/']], - ['name' => 'Bitbucket', 'basepath' => 'https://bitbucket.org/dauxio/daux.io/src/master/docs'] - ] + ['name' => 'Bitbucket', 'basepath' => 'https://bitbucket.org/dauxio/daux.io/src/master/docs'], + ], ]; } /** * @dataProvider providerEditOn + * + * @param mixed $value + * @param mixed $expected */ public function testEditOn($value, $expected) { diff --git a/tests/Format/HTML/TableOfContentsTest.php b/tests/Format/HTML/TableOfContentsTest.php index 0be28f5..bd10282 100644 --- a/tests/Format/HTML/TableOfContentsTest.php +++ b/tests/Format/HTML/TableOfContentsTest.php @@ -1,8 +1,8 @@ templateRenderer = new Template; + $config = new MainConfig(); + $config->templateRenderer = new Template(); return ['daux' => $config]; } @@ -42,7 +42,7 @@ class TableOfContentsTest extends TestCase $converter = new CommonMarkConverter($this->getConfig()); $source = "[TOC]\n# Title"; - $expected = <<
  • Title

    @@ -60,7 +60,7 @@ EXPECTED; $converter = new CommonMarkConverter($this->getConfig()); $source = "[TOC]\n# 基础操作\n# 操作基础"; - $expected = <<
  • 基础操作

    @@ -82,7 +82,7 @@ EXPECTED; $converter = new CommonMarkConverter($this->getConfig()); $source = "[TOC]\n# Test\n# Test"; - $expected = <<
  • Test

    @@ -104,7 +104,7 @@ EXPECTED; $converter = new CommonMarkConverter($this->getConfig()); $source = "[TOC]\n# TEST : Test"; - $expected = <<
  • TEST : Test

    diff --git a/tests/Format/Template/TranslateTest.php b/tests/Format/Template/TranslateTest.php index 8262b6c..c82dd3e 100644 --- a/tests/Format/Template/TranslateTest.php +++ b/tests/Format/Template/TranslateTest.php @@ -2,20 +2,17 @@ namespace Todaymade\Daux\Format\Template; use org\bovigo\vfs\vfsStream; +use PHPUnit\Framework\TestCase; use Todaymade\Daux\Config; use Todaymade\Daux\ConfigBuilder; -use Todaymade\Daux\Daux; use Todaymade\Daux\DauxHelper; use Todaymade\Daux\Format\HTML\Template; use Todaymade\Daux\Tree\Builder; use Todaymade\Daux\Tree\Entry; use Todaymade\Daux\Tree\Root; -use PHPUnit\Framework\TestCase; /** - * Class TranslateTest - * - * @package Todaymade\Daux\Format\Template + * Class TranslateTest. */ class TranslateTest extends TestCase { @@ -36,7 +33,6 @@ class TranslateTest extends TestCase ->withValidContentExtensions(['md']) ->build(); - $tree = new Root($config); Builder::build($tree, []); @@ -74,22 +70,22 @@ class TranslateTest extends TestCase 'language' => $language, ], 'html' => [ - 'search' => '', - 'toggle_code' => false, - 'piwik_analytics' => '', + 'search' => '', + 'toggle_code' => false, + 'piwik_analytics' => '', 'google_analytics' => '', ], 'theme' => [ - 'js' => [''], - 'css' => [''], - 'fonts' => [''], - 'favicon' => '', + 'js' => [''], + 'css' => [''], + 'fonts' => [''], + 'favicon' => '', 'templates' => 'name', ], 'strings' => [ - 'en' => ['Link_previous' => 'Previous',], - 'it' => ['Link_previous' => 'Pagina precedente',], - ] + 'en' => ['Link_previous' => 'Previous'], + 'it' => ['Link_previous' => 'Pagina precedente'], + ], ]); $config->setCurrentPage(DauxHelper::getFile($config->getTree(), $current)); diff --git a/tests/Server/ServerTest.php b/tests/Server/ServerTest.php index e08ca3b..62dc4c5 100644 --- a/tests/Server/ServerTest.php +++ b/tests/Server/ServerTest.php @@ -1,12 +1,12 @@ 'first page', 'Page.md' => 'another page', 'somefile.css' => 'body {}', - '22.png' => '' + '22.png' => '', ]; $root = vfsStream::setup('root', null, $structure); - $config = ConfigBuilder::withMode(Daux::LIVE_MODE) ->withDocumentationDirectory($root->url()) ->build(); @@ -34,6 +33,6 @@ class ServerTest extends TestCase $server = new Server($daux); $response = $server->createResponse($page)->prepare(Request::createFromGlobals()); - $this->assertEquals("text/css", $response->headers->get('Content-Type')); + $this->assertEquals('text/css', $response->headers->get('Content-Type')); } } diff --git a/tests/Tree/BuilderIntegrationTest.php b/tests/Tree/BuilderIntegrationTest.php index dcbe6aa..0bd5286 100644 --- a/tests/Tree/BuilderIntegrationTest.php +++ b/tests/Tree/BuilderIntegrationTest.php @@ -3,9 +3,8 @@ namespace Todaymade\Daux\Tree; use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStreamDirectory; -use Todaymade\Daux\ConfigBuilder; -use Todaymade\Daux\Daux; use PHPUnit\Framework\TestCase; +use Todaymade\Daux\ConfigBuilder; class BuilderIntegrationTest extends TestCase { diff --git a/tests/Tree/BuilderTest.php b/tests/Tree/BuilderTest.php index ec5f682..b380c10 100644 --- a/tests/Tree/BuilderTest.php +++ b/tests/Tree/BuilderTest.php @@ -2,10 +2,8 @@ namespace Todaymade\Daux\Tree; use org\bovigo\vfs\vfsStream; -use Todaymade\Daux\Config; -use Todaymade\Daux\ConfigBuilder; -use Todaymade\Daux\Daux; use PHPUnit\Framework\TestCase; +use Todaymade\Daux\ConfigBuilder; class BuilderTest extends TestCase { @@ -37,6 +35,9 @@ class BuilderTest extends TestCase /** * @dataProvider providerRemoveSorting + * + * @param mixed $value + * @param mixed $expected */ public function testRemoveSorting($value, $expected) { @@ -85,12 +86,17 @@ class BuilderTest extends TestCase // File, Url, Uri, Title ['A Page.md', 'dir/A_Page.html', 'A_Page.html', 'A Page'], ['Page#1.md', 'dir/Page1.html', 'Page1.html', 'Page#1'], - ['你好世界.md', 'dir/ni_hao_shi_jie.html', 'ni_hao_shi_jie.html', '你好世界'] + ['你好世界.md', 'dir/ni_hao_shi_jie.html', 'ni_hao_shi_jie.html', '你好世界'], ]; } /** * @dataProvider providerCreatePage + * + * @param mixed $file + * @param mixed $url + * @param mixed $uri + * @param mixed $title */ public function testGetOrCreatePage($file, $url, $uri, $title) { @@ -164,7 +170,7 @@ class BuilderTest extends TestCase 'Page.md' => 'another page', 'Button.md' => 'another page', '你好世界.md' => 'another page', - '22.png' => '' + '22.png' => '', ]; $root = vfsStream::setup('root', null, $structure); @@ -188,8 +194,8 @@ class BuilderTest extends TestCase 'folder' => [ 'index.md' => "---\ntitle: new Title\n---\nThe content", 'Page.md' => 'another page', - 'Button.md' => 'another page' - ] + 'Button.md' => 'another page', + ], ]; $root = vfsStream::setup('root', null, $structure); diff --git a/tests/Tree/ContentTest.php b/tests/Tree/ContentTest.php index 1510510..7055854 100644 --- a/tests/Tree/ContentTest.php +++ b/tests/Tree/ContentTest.php @@ -1,8 +1,8 @@