diff --git a/.gitignore b/.gitignore index d36b05e..12bb51f 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ static /vendor /build .phpunit.result.cache +.php_cs.cache /prettier.config.js /.eslintrc.js diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..3c9f841 --- /dev/null +++ b/.php_cs @@ -0,0 +1,14 @@ +exclude('vendor') + ->in(__DIR__) +; + +return PhpCsFixer\Config::create() + ->setRules([ + '@PSR2' => true, + 'array_syntax' => ['syntax' => 'short'], + ]) + ->setFinder($finder) +; diff --git a/composer.json b/composer.json index f3af1b4..eb7e6ac 100644 --- a/composer.json +++ b/composer.json @@ -46,6 +46,8 @@ "mikey179/vfsstream": "^1.6" }, "scripts": { - "test": "build/phpunit" + "test": "build/phpunit", + "lint": "build/php-cs-fixer fix --config=.php_cs --dry-run -v", + "lint:fix": "build/php-cs-fixer fix --config=.php_cs" } } diff --git a/libs/Cache.php b/libs/Cache.php index 4fc7eb3..072833f 100644 --- a/libs/Cache.php +++ b/libs/Cache.php @@ -5,7 +5,7 @@ use Todaymade\Daux\Daux; class Cache { - static $printed = false; + public static $printed = false; public static function getDirectory(): string { @@ -109,7 +109,6 @@ class Cache } else { unlink($dir . "/" . $object); } - } } rmdir($dir); diff --git a/libs/Config.php b/libs/Config.php index eaa92b2..adba9b1 100644 --- a/libs/Config.php +++ b/libs/Config.php @@ -8,91 +8,113 @@ use Todaymade\Daux\Format\Confluence\Config as ConfluenceConfig; class Config extends BaseConfig { - public function getTitle() { + public function getTitle() + { return $this->getValue('title'); } - public function hasAuthor(): bool { + public function hasAuthor(): bool + { return $this->hasValue('author'); } - public function getAuthor() { + public function getAuthor() + { return $this->getValue('author'); } - public function hasTagline(): bool { + public function hasTagline(): bool + { return $this->hasValue('tagline'); } - public function getTagline() { + public function getTagline() + { return $this->getValue('tagline'); } - public function getCurrentPage() { + public function getCurrentPage() + { return $this->getValue('current_page'); } - public function setCurrentPage(Content $entry) { + public function setCurrentPage(Content $entry) + { $this->setValue('current_page', $entry); } - public function getDocumentationDirectory() { + public function getDocumentationDirectory() + { return $this->getValue('docs_directory'); } - public function getThemesDirectory() { + public function getThemesDirectory() + { return $this->getValue('themes_directory'); } - public function getThemesPath() { + public function getThemesPath() + { return $this->getValue('themes_path'); } - public function getFormat() { + public function getFormat() + { return $this->getValue('format'); } - public function hasTimezone(): bool { + public function hasTimezone(): bool + { return isset($this['timezone']); } - public function getTimezone() { + public function getTimezone() + { return $this->getValue('timezone'); } - public function getTree() { + public function getTree() + { return $this->getValue('tree'); } - public function setTree($tree) { + public function setTree($tree) + { $this->setValue('tree', $tree); } - public function isMultilanguage(): bool { + public function isMultilanguage(): bool + { return $this->hasValue('languages') && !empty($this->getValue('languages')); } - public function getLanguages(): array { + public function getLanguages(): array + { return $this->getValue('languages'); } - public function getLanguage(): string { + public function getLanguage(): string + { return $this->getValue('language'); } - public function getMode() { + public function getMode() + { return $this->getValue('mode'); } - public function isLive() { + public function isLive() + { return $this->getValue('mode') == Daux::LIVE_MODE; } - public function isStatic() { + public function isStatic() + { return $this->getValue('mode') == Daux::STATIC_MODE; } - public function shouldInheritIndex() { + public function shouldInheritIndex() + { // As the global configuration is always present, we // need to test for the existence of the legacy value // first. Then use the current value. @@ -103,35 +125,43 @@ class Config extends BaseConfig return $this['html']['inherit_index']; } - public function getIndexKey() { + public function getIndexKey() + { return $this->getValue('mode') == Daux::STATIC_MODE ? 'index.html' : 'index'; } - public function getProcessor() { + public function getProcessor() + { return $this->getValue('processor'); } - public function getConfluenceConfiguration(): ConfluenceConfig { + public function getConfluenceConfiguration(): ConfluenceConfig + { return new ConfluenceConfig($this->hasValue('confluence') ? $this->getValue('confluence') : []); } - public function getHTML(): HTMLConfig { + public function getHTML(): HTMLConfig + { return new HTMLConfig($this->hasValue('html') ? $this->getValue('html') : []); } - public function getTheme(): ?Theme { + public function getTheme(): ?Theme + { return $this->hasValue('theme') ? new Theme($this->getValue('theme')) : null; } - public function getValidContentExtensions() { + public function getValidContentExtensions() + { return $this->getValue('valid_content_extensions'); } - public function setValidContentExtensions(array $value) { + public function setValidContentExtensions(array $value) + { $this->setValue('valid_content_extensions', $value); } - public function canCache() { + public function canCache() + { if ($this->hasValue('cache')) { return $this->getValue('cache'); } @@ -139,7 +169,8 @@ class Config extends BaseConfig return false; } - public function getCacheKey() { + public function getCacheKey() + { $cloned = []; foreach ($this as $key => $value) { $cloned[$key] = ($value instanceof Entry) ? $value->dump() : $value; @@ -148,40 +179,48 @@ class Config extends BaseConfig return sha1(json_encode($cloned)); } - public function hasTranslationKey($language, $key): bool { + public function hasTranslationKey($language, $key): bool + { return array_key_exists($language, $this['strings']) && array_key_exists($key, $this['strings'][$language]); } - public function getTranslationKey($language, $key) { + public function getTranslationKey($language, $key) + { return $this['strings'][$language][$key]; } - public function hasImage(): bool { + public function hasImage(): bool + { return $this->hasValue('image'); } - public function getImage() { + public function getImage() + { return $this->getValue('image'); } - public function setImage($value) { + public function setImage($value) + { $this->setValue('image', $value); } - public function getLocalBase() { + public function getLocalBase() + { return $this->getValue('local_base'); } - public function getTemplates() { + public function getTemplates() + { return $this->getValue('templates'); } - public function getBaseUrl() { + public function getBaseUrl() + { return $this->getValue('base_url'); } - public function getBasePage() { - + public function getBasePage() + { if ($this->isLive()) { $value = '//' . $this->getBaseUrl(); if (!$this['live']['clean_urls']) { @@ -193,59 +232,73 @@ class Config extends BaseConfig return $this->getBaseUrl(); } - public function hasEntryPage(): bool { + public function hasEntryPage(): bool + { return $this->hasValue('entry_page') && !empty($this->getValue('entry_page')); } - public function getEntryPage() { + public function getEntryPage() + { return $this->getValue('entry_page'); } - public function setEntryPage($value) { + public function setEntryPage($value) + { $this->setValue('entry_page', $value); } - public function hasRequest(): bool { + public function hasRequest(): bool + { return $this->hasValue('request') && !empty($this->getValue('request')); } - public function getRequest() { + public function getRequest() + { return $this->getValue('request'); } - public function setRequest($value) { + public function setRequest($value) + { $this->setValue('request', $value); } - public function getIndex() { + public function getIndex() + { return $this->getValue('index'); } - public function setIndex($value) { + public function setIndex($value) + { $this->setValue('index', $value); } - public function hasProcessorInstance() { + public function hasProcessorInstance() + { return $this->hasValue('processor_instance'); } - public function getProcessorInstance() { + public function getProcessorInstance() + { return $this->getValue('processor_instance'); } - public function setProcessorInstance($value) { + public function setProcessorInstance($value) + { $this->setValue('processor_instance', $value); } - public function getIgnore() { + public function getIgnore() + { return $this->getValue('ignore'); } - public function hasHost() { + public function hasHost() + { return $this->hasValue('host'); } - public function getHost() { + public function getHost() + { return $this->getValue('host'); } } diff --git a/libs/ConfigBuilder.php b/libs/ConfigBuilder.php index 018b5ce..6182ede 100644 --- a/libs/ConfigBuilder.php +++ b/libs/ConfigBuilder.php @@ -7,28 +7,33 @@ class ConfigBuilder private $configuration_override_file = null; - private function __construct(string $mode) { + private function __construct(string $mode) + { $this->config = new Config(); $this->config['mode'] = $mode; $this->config['local_base'] = dirname(__DIR__); } - public static function fromFile($file): Config { + public static function fromFile($file): Config + { return unserialize(file_get_contents($file)); } - public 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; } - public function with(array $values): ConfigBuilder { + public function with(array $values): ConfigBuilder + { $this->config->merge($values); return $this; } - private function setValue(&$array, $key, $value) { + private function setValue(&$array, $key, $value) + { if (is_null($key)) { return $array = $value; } @@ -44,65 +49,77 @@ class ConfigBuilder return $array; } - public function withValues(array $values): ConfigBuilder { + public function withValues(array $values): ConfigBuilder + { foreach ($values as $value) { $this->setValue($this->config, $value[0], $value[1]); } return $this; } - public function withDocumentationDirectory($dir): ConfigBuilder { + public function withDocumentationDirectory($dir): ConfigBuilder + { $this->config['docs_directory'] = $dir; return $this; } - public function withValidContentExtensions(array $value): ConfigBuilder { + public function withValidContentExtensions(array $value): ConfigBuilder + { $this->config['valid_content_extensions'] = $value; return $this; } - public function withThemesPath($themePath): ConfigBuilder { + public function withThemesPath($themePath): ConfigBuilder + { $this->config['themes_path'] = $themePath; return $this; } - public function withThemesDirectory($directory): ConfigBuilder { + public function withThemesDirectory($directory): ConfigBuilder + { $this->config['themes_directory'] = $directory; return $this; } - public function withCache(bool $value): ConfigBuilder { + public function withCache(bool $value): ConfigBuilder + { $this->config['cache'] = $value; return $this; } - public function withFormat($format): ConfigBuilder { + public function withFormat($format): ConfigBuilder + { $this->config['format'] = $format; return $this; } - public function withConfigurationOverride($file): ConfigBuilder { + public function withConfigurationOverride($file): ConfigBuilder + { $this->configuration_override_file = $file; return $this; } - public function withProcessor($value): ConfigBuilder { + public function withProcessor($value): ConfigBuilder + { $this->config['processor'] = $value; return $this; } - public function withConfluenceDelete($value): ConfigBuilder { + public function withConfluenceDelete($value): ConfigBuilder + { $this->config['confluence']['delete'] = $value; return $this; } - public function build(): Config { + public function build(): Config + { $this->initializeConfiguration(); return $this->config; } - private function resolveThemeVariant() { + private function resolveThemeVariant() + { $theme = $this->config->getHTML()->getTheme(); $themesPath = $this->config->getThemesPath() . DIRECTORY_SEPARATOR; @@ -131,7 +148,8 @@ class ConfigBuilder * @param string $override_file * @throws Exception */ - private function initializeConfiguration() { + private function initializeConfiguration() + { // Validate and set theme path $docs_path = $this->normalizeDocumentationPath($this->config->getDocumentationDirectory()); $this->config['docs_directory'] = $docs_path; @@ -163,10 +181,11 @@ class ConfigBuilder // Text search would be too slow on live server if ($this->config->isLive()) { $this->config['html']['search'] = false; - } + } } - private function normalizeThemePath($path) { + private function normalizeThemePath($path) + { $validPath = $this->findLocation($path, $this->config->getLocalBase(), 'dir'); if (!$validPath) { @@ -176,7 +195,8 @@ class ConfigBuilder return $validPath; } - private function normalizeDocumentationPath($path) { + private function normalizeDocumentationPath($path) + { $validPath = $this->findLocation($path, $this->config->getLocalBase(), 'dir'); if (!$validPath) { @@ -191,7 +211,8 @@ class ConfigBuilder * * @throws Exception */ - private function loadBaseConfiguration() { + private function loadBaseConfiguration() + { // Set the default configuration $this->config->merge([ 'docs_directory' => 'docs', @@ -212,7 +233,8 @@ class ConfigBuilder * @param bool $optional * @throws Exception */ - private function loadConfiguration($config_file, $optional = true) { + private function loadConfiguration($config_file, $optional = true) + { if (!file_exists($config_file)) { if ($optional) { return; @@ -235,7 +257,8 @@ class ConfigBuilder * @return string|null the path to a file to load for configuration overrides * @throws Exception */ - private function getConfigurationOverride($path) { + private function getConfigurationOverride($path) + { $validPath = $this->findLocation($path, $this->config->getLocalBase(), 'file'); if ($validPath === null) { @@ -255,7 +278,8 @@ class ConfigBuilder * @param string $type * @return false|null|string */ - private function findLocation($path, $basedir, $type) { + private function findLocation($path, $basedir, $type) + { // If Path is explicitly null, it's useless to go further if ($path === null) { return null; @@ -280,4 +304,4 @@ class ConfigBuilder return false; } -} \ No newline at end of file +} diff --git a/libs/Console/DauxCommand.php b/libs/Console/DauxCommand.php index e1ad986..d9266c1 100644 --- a/libs/Console/DauxCommand.php +++ b/libs/Console/DauxCommand.php @@ -9,7 +9,7 @@ use Todaymade\Daux\Daux; class DauxCommand extends SymfonyCommand { - protected function configure() + protected function configure() { $this ->addOption('configuration', 'c', InputOption::VALUE_REQUIRED, 'Configuration file') @@ -46,7 +46,7 @@ class DauxCommand extends SymfonyCommand if ($input->hasOption('value')) { $values = array_map( - function($value) { + function ($value) { return array_map("trim", explode('=', $value)); }, $input->getOption('value') diff --git a/libs/Console/RunAction.php b/libs/Console/RunAction.php index 26e3a2b..1ee0be3 100644 --- a/libs/Console/RunAction.php +++ b/libs/Console/RunAction.php @@ -5,7 +5,8 @@ use Todaymade\Daux\Daux; trait RunAction { - protected function getLength($content) { + protected function getLength($content) + { return function_exists('mb_strlen') ? mb_strlen($content) : strlen($content); } @@ -19,7 +20,7 @@ trait RunAction $padding = $width - $this->getLength($title) - 10; try { - $response = $closure(function($content) use (&$padding, $verbose) { + $response = $closure(function ($content) use (&$padding, $verbose) { $padding -= $this->getLength($content); Daux::write($content, $verbose); }); diff --git a/libs/Console/Serve.php b/libs/Console/Serve.php index 65dd270..0533015 100755 --- a/libs/Console/Serve.php +++ b/libs/Console/Serve.php @@ -49,7 +49,7 @@ class Serve extends DauxCommand return 1; } - $path = stream_get_meta_data($file)['uri']; + $path = stream_get_meta_data($file)['uri']; fwrite($file, serialize($daux->getConfig())); chdir(__DIR__ . '/../../'); diff --git a/libs/ContentTypes/Markdown/ContentType.php b/libs/ContentTypes/Markdown/ContentType.php index c1fb2db..0f42bf6 100644 --- a/libs/ContentTypes/Markdown/ContentType.php +++ b/libs/ContentTypes/Markdown/ContentType.php @@ -19,11 +19,13 @@ class ContentType implements \Todaymade\Daux\ContentTypes\ContentType $this->config = $config; } - protected function createConverter() { + protected function createConverter() + { return new CommonMarkConverter(['daux' => $this->config]); } - protected function getConverter() { + protected function getConverter() + { if (!$this->converter) { $this->converter = $this->createConverter(); } @@ -67,7 +69,7 @@ class ContentType implements \Todaymade\Daux\ContentTypes\ContentType if ($can_cache) { Cache::put($cacheKey, $payload); - } + } return $payload; } diff --git a/libs/Daux.php b/libs/Daux.php index 7c7a99a..b329a4f 100644 --- a/libs/Daux.php +++ b/libs/Daux.php @@ -4,8 +4,6 @@ use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\OutputInterface; use Todaymade\Daux\ContentTypes\ContentTypeHandler; use Todaymade\Daux\Tree\Builder; -use Todaymade\Daux\Tree\Content; -use Todaymade\Daux\Tree\Directory; use Todaymade\Daux\Tree\Root; class Daux @@ -40,7 +38,7 @@ class Daux { Daux::$output = $output; - + $this->config = $config; } @@ -161,7 +159,8 @@ class Daux return $class; } - protected function findAlternatives($input, $words) { + protected function findAlternatives($input, $words) + { $alternatives = []; foreach ($words as $word) { @@ -246,7 +245,8 @@ class Daux return $this->validExtensions = $this->getContentTypeHandler()->getContentExtensions(); } - public static function getOutput() { + public static function getOutput() + { if (!Daux::$output) { Daux::$output = new NullOutput(); } @@ -261,7 +261,8 @@ class Daux * @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 */ - public static function write($messages, $newline = false, $options = 0) { + public static function write($messages, $newline = false, $options = 0) + { Daux::getOutput()->write($messages, $newline, $options); } @@ -271,11 +272,13 @@ class Daux * @param string|array $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) { + public static function writeln($messages, $options = 0) + { Daux::getOutput()->write($messages, true, $options); } - public static function getVerbosity() { + public static function getVerbosity() + { return Daux::getOutput()->getVerbosity(); } } diff --git a/libs/DauxHelper.php b/libs/DauxHelper.php index 9c50f79..b6777aa 100644 --- a/libs/DauxHelper.php +++ b/libs/DauxHelper.php @@ -237,7 +237,7 @@ class DauxHelper // Convert all dashes into underscores $title = preg_replace('![' . preg_quote('-') . ']+!u', $separator, $title); - // Remove all characters that are not valid in a URL: + // Remove all characters that are not valid in a URL: // $-_.+!*'(), separator, letters, numbers, or whitespace. $title = preg_replace('![^-' . preg_quote($separator) . '\!\'\(\),\.\+\*\$\pL\pN\s]+!u', '', $title); @@ -316,7 +316,8 @@ class DauxHelper return '' !== $parts['root']; } - public static function getAbsolutePath($path) { + public static function getAbsolutePath($path) + { if (DauxHelper::isAbsolutePath($path)) { return $path; } @@ -324,7 +325,8 @@ class DauxHelper return getcwd() . '/' . $path; } - public static function is($path, $type) { + public static function is($path, $type) + { return ($type == 'dir') ? is_dir($path) : file_exists($path); } diff --git a/libs/Format/Base/EmbedImages.php b/libs/Format/Base/EmbedImages.php index f729e7e..8cc440d 100644 --- a/libs/Format/Base/EmbedImages.php +++ b/libs/Format/Base/EmbedImages.php @@ -25,7 +25,7 @@ class EmbedImages { return preg_replace_callback( "/]*src=['\"]([^\"]*)['\"][^>]*>/", - function($matches) use ($file, $callback) { + function ($matches) use ($file, $callback) { if ($result = $this->findImage($matches[1], $matches[0], $file, $callback)) { return $result; } diff --git a/libs/Format/Confluence/Api.php b/libs/Format/Confluence/Api.php index d3e26af..9e70638 100644 --- a/libs/Format/Confluence/Api.php +++ b/libs/Format/Confluence/Api.php @@ -232,7 +232,6 @@ class Api $prepared = []; foreach ($filtered as $index => $line) { - $number = $start + 1 + $index; $gutter = substr(' ' . (' ' . $number), -$maxWidth) . ' | '; @@ -318,7 +317,6 @@ class Api // If the attachment is already uploaded, // 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. )"); return; diff --git a/libs/Format/Confluence/Config.php b/libs/Format/Confluence/Config.php index 907b4d6..351a03d 100644 --- a/libs/Format/Confluence/Config.php +++ b/libs/Format/Confluence/Config.php @@ -4,7 +4,8 @@ use Todaymade\Daux\BaseConfig; class Config extends BaseConfig { - public function shouldAutoDeleteOrphanedPages() { + public function shouldAutoDeleteOrphanedPages() + { if ($this->hasValue('delete')) { return $this->getValue('delete'); } @@ -12,55 +13,68 @@ class Config extends BaseConfig return false; } - public function getUpdateThreshold() { + public function getUpdateThreshold() + { return $this->hasValue('update_threshold') ? $this->getValue('update_threshold') : 2; } - public function getPrefix() { + public function getPrefix() + { return $this->getValue('prefix'); } - public function getBaseUrl() { + public function getBaseUrl() + { return $this->getValue('base_url'); } - public function getUser() { + public function getUser() + { return $this->getValue('user'); } - public function getPassword() { + public function getPassword() + { return $this->getValue('pass'); } - public function getSpaceId() { + public function getSpaceId() + { return $this->getValue('space_id'); } - public function hasAncestorId() { + public function hasAncestorId() + { return $this->hasValue('ancestor_id'); } - public function getAncestorId() { + public function getAncestorId() + { return $this->getValue('ancestor_id'); } - public function setAncestorId($value) { + public function setAncestorId($value) + { $this->setValue('ancestor_id', $value); } - public function hasRootId() { + public function hasRootId() + { return $this->hasValue('root_id'); } - public function getRootId() { + public function getRootId() + { return $this->getValue('root_id'); } - public function hasHeader() { + public function hasHeader() + { return $this->hasValue('header'); } - public function getHeader() { + public function getHeader() + { return $this->getValue('header'); } } diff --git a/libs/Format/Confluence/ContentPage.php b/libs/Format/Confluence/ContentPage.php index f0b2e55..ee55ad0 100644 --- a/libs/Format/Confluence/ContentPage.php +++ b/libs/Format/Confluence/ContentPage.php @@ -19,13 +19,13 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage ->embed( $content, $this->file, - function($src, array $attributes, Entry $file) { + function ($src, array $attributes, Entry $file) { //Add the attachment for later upload if ($file instanceof Raw) { $filename = basename($file->getPath()); $this->attachments[$filename] = ['filename' => $filename, 'file' => $file]; - } else if ($file instanceof ComputedRaw) { + } elseif ($file instanceof ComputedRaw) { $filename = $file->getUri(); $this->attachments[$filename] = ['filename' => $filename, 'content' => $file->getContent()]; } else { diff --git a/libs/Format/Confluence/ContentTypes/Markdown/CodeRenderer.php b/libs/Format/Confluence/ContentTypes/Markdown/CodeRenderer.php index 2e738f2..041bed6 100644 --- a/libs/Format/Confluence/ContentTypes/Markdown/CodeRenderer.php +++ b/libs/Format/Confluence/ContentTypes/Markdown/CodeRenderer.php @@ -5,7 +5,6 @@ use League\CommonMark\HtmlElement; abstract class CodeRenderer implements BlockRendererInterface { - public function escapeCDATA($content) { return str_replace("]]>", "]]]]>", $content); diff --git a/libs/Format/Confluence/ContentTypes/Markdown/ContentType.php b/libs/Format/Confluence/ContentTypes/Markdown/ContentType.php index 0ff703a..d671938 100644 --- a/libs/Format/Confluence/ContentTypes/Markdown/ContentType.php +++ b/libs/Format/Confluence/ContentTypes/Markdown/ContentType.php @@ -1,10 +1,9 @@ $this->config]); } } diff --git a/libs/Format/Confluence/ContentTypes/Markdown/ImageRenderer.php b/libs/Format/Confluence/ContentTypes/Markdown/ImageRenderer.php index 52e8c3b..a63e193 100644 --- a/libs/Format/Confluence/ContentTypes/Markdown/ImageRenderer.php +++ b/libs/Format/Confluence/ContentTypes/Markdown/ImageRenderer.php @@ -20,7 +20,8 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf */ protected $parent; - public function __construct() { + public function __construct() + { $this->parent = new \League\CommonMark\Inline\Renderer\ImageRenderer(); } diff --git a/libs/Format/Confluence/Generator.php b/libs/Format/Confluence/Generator.php index 7ff54eb..035d58b 100644 --- a/libs/Format/Confluence/Generator.php +++ b/libs/Format/Confluence/Generator.php @@ -80,7 +80,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator $tree = $this->runAction( 'Generating Tree ...', $width, - function() use ($config) { + function () use ($config) { $tree = $this->generateRecursive($this->daux->tree, $config); $tree['title'] = $this->prefix . $config->getTitle(); diff --git a/libs/Format/Confluence/Publisher.php b/libs/Format/Confluence/Publisher.php index f5abe20..291440b 100644 --- a/libs/Format/Confluence/Publisher.php +++ b/libs/Format/Confluence/Publisher.php @@ -54,7 +54,7 @@ class Publisher $this->run( 'Getting already published pages...', - function() use (&$published) { + function () use (&$published) { if ($published != null) { $published['children'] = $this->client->getList($published['id'], true); } @@ -63,7 +63,7 @@ class Publisher $published = $this->run( "Create placeholder pages...", - function() use ($tree, $published) { + function () use ($tree, $published) { return $this->createRecursive($this->confluence->getAncestorId(), $tree, $published); } ); @@ -142,7 +142,7 @@ class Publisher protected function createRecursive($parent_id, $entry, $published) { - $callback = function($parent_id, $entry, $published) { + $callback = function ($parent_id, $entry, $published) { // nothing to do if the ID already exists if (array_key_exists('id', $published)) { return $published; @@ -163,7 +163,7 @@ class Publisher protected function updateRecursive($parent_id, $entry, $published) { - $callback = function($parent_id, $entry, $published) { + $callback = function ($parent_id, $entry, $published) { if (array_key_exists('id', $published) && array_key_exists('page', $entry)) { $this->updatePage($parent_id, $entry, $published); } @@ -181,7 +181,7 @@ class Publisher $this->run( '- ' . PublisherUtilities::niceTitle($entry['file']->getUrl()), - function() use ($entry, $published, $parent_id, $updateThreshold) { + function () use ($entry, $published, $parent_id, $updateThreshold) { $generated_content = $entry['page']->getContent(); if (PublisherUtilities::shouldUpdate($entry['page'], $generated_content, $published, $updateThreshold)) { $this->client->updatePage( @@ -199,7 +199,7 @@ class Publisher foreach ($entry['page']->attachments as $attachment) { $this->run( " With attachment: $attachment[filename]", - function($write) use ($published, $attachment) { + function ($write) use ($published, $attachment) { $this->client->uploadAttachment($published['id'], $attachment, $write); } ); diff --git a/libs/Format/Confluence/PublisherDelete.php b/libs/Format/Confluence/PublisherDelete.php index 6c5a0b5..8d06fc3 100644 --- a/libs/Format/Confluence/PublisherDelete.php +++ b/libs/Format/Confluence/PublisherDelete.php @@ -60,7 +60,8 @@ class PublisherDelete } } - protected function doDelete() { + protected function doDelete() + { $this->output->writeLn('Deleting obsolete pages...'); foreach ($this->deletable as $id => $title) { $this->output->writeLn("- $title"); @@ -68,7 +69,8 @@ class PublisherDelete } } - protected function displayDeletable() { + 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."); diff --git a/libs/Format/HTML/Config.php b/libs/Format/HTML/Config.php index 559eaa6..477e0e2 100644 --- a/libs/Format/HTML/Config.php +++ b/libs/Format/HTML/Config.php @@ -34,7 +34,8 @@ class Config extends BaseConfig return null; } - public function hasSearch() { + public function hasSearch() + { return $this->hasValue('search') && $this->getValue('search'); } diff --git a/libs/Format/HTML/ContentPage.php b/libs/Format/HTML/ContentPage.php index 72d8a11..4ee4829 100644 --- a/libs/Format/HTML/ContentPage.php +++ b/libs/Format/HTML/ContentPage.php @@ -30,7 +30,8 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage return $this->file->getParent() instanceof Root; } - private function isLanding(): bool { + private function isLanding(): bool + { return $this->config->getHTML()->hasLandingPage() && $this->homepage; } diff --git a/libs/Format/HTML/ContentTypes/Markdown/ContentType.php b/libs/Format/HTML/ContentTypes/Markdown/ContentType.php index 037106e..e25f1cc 100644 --- a/libs/Format/HTML/ContentTypes/Markdown/ContentType.php +++ b/libs/Format/HTML/ContentTypes/Markdown/ContentType.php @@ -1,10 +1,9 @@ $this->config]); } } diff --git a/libs/Format/HTML/ContentTypes/Markdown/FencedCodeRenderer.php b/libs/Format/HTML/ContentTypes/Markdown/FencedCodeRenderer.php index e1710e1..d952f92 100644 --- a/libs/Format/HTML/ContentTypes/Markdown/FencedCodeRenderer.php +++ b/libs/Format/HTML/ContentTypes/Markdown/FencedCodeRenderer.php @@ -15,7 +15,8 @@ class FencedCodeRenderer implements BlockRendererInterface */ private $hl; - public function __construct() { + public function __construct() + { $this->hl = new Highlighter(); } diff --git a/libs/Format/HTML/ContentTypes/Markdown/ImageRenderer.php b/libs/Format/HTML/ContentTypes/Markdown/ImageRenderer.php index 79181aa..9ae1d75 100644 --- a/libs/Format/HTML/ContentTypes/Markdown/ImageRenderer.php +++ b/libs/Format/HTML/ContentTypes/Markdown/ImageRenderer.php @@ -35,7 +35,7 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf } /** - * Relative URLs can be done using either the folder with + * Relative URLs can be done using either the folder with * number prefix or the final name (with prefix stripped). * This ensures that we always use the final name when generating. * @throws LinkNotFoundException @@ -70,7 +70,7 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf * @param ElementRendererInterface $htmlRenderer * * @return HtmlElement - * + * * @throws LinkNotFoundException */ public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer) diff --git a/libs/Format/HTML/ContentTypes/Markdown/TOC/Processor.php b/libs/Format/HTML/ContentTypes/Markdown/TOC/Processor.php index 0abc9ec..e95f6cf 100644 --- a/libs/Format/HTML/ContentTypes/Markdown/TOC/Processor.php +++ b/libs/Format/HTML/ContentTypes/Markdown/TOC/Processor.php @@ -72,7 +72,8 @@ class Processor } } - protected function getUniqueId(Document $document, $proposed) { + protected function getUniqueId(Document $document, $proposed) + { if ($proposed == "page_") { $proposed = "page_section_" . (count($document->heading_ids) + 1); } diff --git a/libs/Format/HTML/Generator.php b/libs/Format/HTML/Generator.php index 9b66d32..35e13cf 100755 --- a/libs/Format/HTML/Generator.php +++ b/libs/Format/HTML/Generator.php @@ -60,7 +60,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator $this->runAction( 'Copying Static assets ...', $width, - function() use ($destination, $config) { + function () use ($destination, $config) { $this->ensureEmptyDestination($destination); $this->copyThemes($destination, $config->getThemesPath()); @@ -170,7 +170,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator $this->runAction( '- ' . $node->getUrl(), $width, - function() use ($node, $output_dir, $key, $config, $index_pages) { + function () use ($node, $output_dir, $key, $config, $index_pages) { if ($node instanceof Raw) { copy($node->getPath(), $output_dir . DIRECTORY_SEPARATOR . $key); diff --git a/libs/Format/HTML/HTMLUtils.php b/libs/Format/HTML/HTMLUtils.php index 0c960be..756ed7b 100644 --- a/libs/Format/HTML/HTMLUtils.php +++ b/libs/Format/HTML/HTMLUtils.php @@ -2,7 +2,8 @@ use Todaymade\Daux\GeneratorHelper; -trait HTMLUtils { +trait HTMLUtils +{ public function ensureEmptyDestination($destination) { if (is_dir($destination)) { @@ -26,4 +27,4 @@ trait HTMLUtils { $destination . DIRECTORY_SEPARATOR . 'themes' ); } -} \ No newline at end of file +} diff --git a/libs/Format/HTML/Template.php b/libs/Format/HTML/Template.php index d8fdc63..b1ea48d 100644 --- a/libs/Format/HTML/Template.php +++ b/libs/Format/HTML/Template.php @@ -78,13 +78,13 @@ class Template protected function registerFunctions($engine) { - $engine->registerFunction('get_navigation', function($tree, $path, $current_url, $base_page, $mode) { + $engine->registerFunction('get_navigation', function ($tree, $path, $current_url, $base_page, $mode) { $nav = $this->buildNavigation($tree, $path, $current_url, $base_page, $mode); return $this->renderNavigation($nav); }); - $engine->registerFunction('translate', function($key) { + $engine->registerFunction('translate', function ($key) { $language = $this->config->getLanguage(); if (isset($this->engine->getData('page')['page'])) { @@ -105,7 +105,7 @@ class Template return "Unknown key $key"; }); - $engine->registerFunction('get_breadcrumb_title', function($page, $base_page) { + $engine->registerFunction('get_breadcrumb_title', function ($page, $base_page) { $title = ''; $breadcrumb_trail = $page['breadcrumb_trail']; $separator = $this->getSeparator($page['breadcrumb_separator']); diff --git a/libs/Format/HTML/Theme.php b/libs/Format/HTML/Theme.php index f2a9e9e..6060921 100644 --- a/libs/Format/HTML/Theme.php +++ b/libs/Format/HTML/Theme.php @@ -4,23 +4,28 @@ use Todaymade\Daux\BaseConfig; class Theme extends BaseConfig { - public function getFonts() { + public function getFonts() + { return $this->getValue('fonts'); } - public function getCSS() { + public function getCSS() + { return $this->getValue('css'); } - public function getJS() { + public function getJS() + { return $this->getValue('js'); } - public function getFavicon() { + public function getFavicon() + { return $this->getValue('favicon'); } - public function getTemplates() { + public function getTemplates() + { return $this->getValue('templates'); } } diff --git a/libs/Format/HTMLFile/ContentPage.php b/libs/Format/HTMLFile/ContentPage.php index ceb1f12..ec86075 100644 --- a/libs/Format/HTMLFile/ContentPage.php +++ b/libs/Format/HTMLFile/ContentPage.php @@ -17,7 +17,7 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage ->embed( $content, $this->file, - function($src, array $attributes, Raw $file) { + function ($src, array $attributes, Raw $file) { // TODO :: ignore absolute paths $content = base64_encode(file_get_contents($file->getPath())); $attr = ''; diff --git a/libs/Format/HTMLFile/ContentTypes/Markdown/ContentType.php b/libs/Format/HTMLFile/ContentTypes/Markdown/ContentType.php index 934d84a..e66eb03 100644 --- a/libs/Format/HTMLFile/ContentTypes/Markdown/ContentType.php +++ b/libs/Format/HTMLFile/ContentTypes/Markdown/ContentType.php @@ -1,10 +1,9 @@ $this->config]); } } diff --git a/libs/Format/HTMLFile/ContentTypes/Markdown/LinkRenderer.php b/libs/Format/HTMLFile/ContentTypes/Markdown/LinkRenderer.php index 3685f82..aa2b148 100644 --- a/libs/Format/HTMLFile/ContentTypes/Markdown/LinkRenderer.php +++ b/libs/Format/HTMLFile/ContentTypes/Markdown/LinkRenderer.php @@ -64,4 +64,4 @@ class LinkRenderer extends \Todaymade\Daux\ContentTypes\Markdown\LinkRenderer return $element; } -} \ No newline at end of file +} diff --git a/libs/Format/HTMLFile/Generator.php b/libs/Format/HTMLFile/Generator.php index 0982cbb..454b7ac 100644 --- a/libs/Format/HTMLFile/Generator.php +++ b/libs/Format/HTMLFile/Generator.php @@ -55,7 +55,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator $this->runAction( 'Cleaning destination folder ...', $width, - function() use ($destination) { + function () use ($destination) { $this->ensureEmptyDestination($destination); } ); @@ -73,7 +73,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator $this->runAction( 'Generating ' . $current->getTitle(), $width, - function() use ($book, $current, $config) { + function () use ($book, $current, $config) { $contentType = $this->daux->getContentTypeHandler()->getType($current); $content = ContentPage::fromFile($current, $config, $contentType); $content->templateRenderer = $this->templateRenderer; diff --git a/libs/FormatDate.php b/libs/FormatDate.php index 3b09dd9..00f5517 100644 --- a/libs/FormatDate.php +++ b/libs/FormatDate.php @@ -4,7 +4,8 @@ use IntlDateFormatter; class FormatDate { - public static function format($config, $date) { + public static function format($config, $date) + { $locale = $config->getLanguage(); $datetype = IntlDateFormatter::LONG; $timetype = IntlDateFormatter::SHORT; @@ -19,4 +20,4 @@ class FormatDate return $formatter->format($date); } -} \ No newline at end of file +} diff --git a/libs/Server/Server.php b/libs/Server/Server.php index 144edda..ee5d5ba 100755 --- a/libs/Server/Server.php +++ b/libs/Server/Server.php @@ -77,7 +77,8 @@ class Server * @param string $postfix * @return string */ - private function getTemporaryFile($postfix) { + private function getTemporaryFile($postfix) + { $sysFileName = tempnam(sys_get_temp_dir(), 'daux'); if ($sysFileName === false) { throw new \RuntimeException("Could not create temporary file"); @@ -99,7 +100,8 @@ class Server * @param Page $page * @return Response */ - public function createResponse(Page $page) { + public function createResponse(Page $page) + { // Add a custom MimeType guesser in case the default ones are not available // This makes sure that at least CSS and JS work fine. $mimeTypes = MimeTypes::getDefault(); diff --git a/libs/Tree/Builder.php b/libs/Tree/Builder.php index 51e058a..5d39c86 100644 --- a/libs/Tree/Builder.php +++ b/libs/Tree/Builder.php @@ -218,7 +218,8 @@ class Builder * * @param Directory $current */ - public static function sortTree(Directory $current) { + public static function sortTree(Directory $current) + { $current->sort(); foreach ($current->getEntries() as $entry) { if ($entry instanceof Directory) { @@ -251,5 +252,4 @@ class Builder return $prev; } - } diff --git a/libs/Tree/Content.php b/libs/Tree/Content.php index b02073d..ab8aa69 100644 --- a/libs/Tree/Content.php +++ b/libs/Tree/Content.php @@ -24,7 +24,7 @@ class Content extends ContentAbstract { if ($this->manuallySetContent) { $content = $this->content; - } else if (!$this->getPath()) { + } elseif (!$this->getPath()) { throw new RuntimeException("Empty content"); } else { $content = file_get_contents($this->getPath()); diff --git a/libs/Tree/Directory.php b/libs/Tree/Directory.php index 1534c4a..4af7072 100644 --- a/libs/Tree/Directory.php +++ b/libs/Tree/Directory.php @@ -95,7 +95,7 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate private function sortBucket($bucket, $final) { - uasort($bucket, function(Entry $a, Entry $b) { + uasort($bucket, function (Entry $a, Entry $b) { return strcasecmp($a->getName(), $b->getName()); }); @@ -136,7 +136,8 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate return $this->parent->getConfig(); } - public function getLocalIndexPage() { + public function getLocalIndexPage() + { $index_key = $this->getConfig()->getIndexKey(); if (isset($this->children[$index_key])) { diff --git a/libs/Tree/Entry.php b/libs/Tree/Entry.php index f02e0cf..8ba569d 100644 --- a/libs/Tree/Entry.php +++ b/libs/Tree/Entry.php @@ -190,7 +190,8 @@ abstract class Entry ]; } - public function isHotPath(Entry $node = null) { + public function isHotPath(Entry $node = null) + { return $this->parent->isHotPath($node ?: $this); } } diff --git a/libs/Tree/Root.php b/libs/Tree/Root.php index d0235a9..c7abfce 100644 --- a/libs/Tree/Root.php +++ b/libs/Tree/Root.php @@ -37,7 +37,8 @@ class Root extends Directory $this->config = $config; } - public function isHotPath(Entry $node = null): bool { + public function isHotPath(Entry $node = null): bool + { if ($node == null) { return true; } @@ -59,7 +60,8 @@ class Root extends Directory return false; } - public function setActiveNode(Entry $node) { + public function setActiveNode(Entry $node) + { $this->activeNode = $node; } } diff --git a/libs/bootstrap.php b/libs/bootstrap.php index 07734fe..3d0b9bd 100644 --- a/libs/bootstrap.php +++ b/libs/bootstrap.php @@ -1,6 +1,7 @@ getHTML()->showPreviousNextLinks()) { - ?> + ?> + } ?> diff --git a/templates/home.php b/templates/home.php index e814528..fad390f 100755 --- a/templates/home.php +++ b/templates/home.php @@ -53,8 +53,8 @@ getHTML()->hasLinks()) { ?> diff --git a/templates/layout/00_layout.php b/templates/layout/00_layout.php index f715949..80de567 100755 --- a/templates/layout/00_layout.php +++ b/templates/layout/00_layout.php @@ -34,13 +34,13 @@ getTheme()->getFonts() as $font) { - echo ""; - } ?> + echo ""; +} ?> getTheme()->getCSS() as $css) { - echo ""; - } ?> + echo ""; +} ?> getHTML()->hasSearch()) { ?> diff --git a/templates/partials/navbar_content.php b/templates/partials/navbar_content.php index 0636ae1..ba3a107 100755 --- a/templates/partials/navbar_content.php +++ b/templates/partials/navbar_content.php @@ -1,4 +1,4 @@ - ['edit_on' => 'test']]); $this->assertInstanceOf(Config::class, $config->getHTML()); diff --git a/tests/Format/HTML/TableOfContentsTest.php b/tests/Format/HTML/TableOfContentsTest.php index e425efd..0be28f5 100644 --- a/tests/Format/HTML/TableOfContentsTest.php +++ b/tests/Format/HTML/TableOfContentsTest.php @@ -1,39 +1,44 @@ -templateRenderer = new Template; - + return ['daux' => $config]; } - function testNoTOCByDefault() { + public function testNoTOCByDefault() + { $converter = new CommonMarkConverter($this->getConfig()); $this->assertEquals("

Test

\n", $converter->convertToHtml('# Test')); } - function testTOCToken() { + public function testTOCToken() + { $converter = new CommonMarkConverter($this->getConfig()); $source = "[TOC]\n# Title"; @@ -50,7 +55,8 @@ EXPECTED; $this->assertEquals($expected, $converter->convertToHtml($source)); } - function testUnicodeTOC() { + public function testUnicodeTOC() + { $converter = new CommonMarkConverter($this->getConfig()); $source = "[TOC]\n# 基础操作\n# 操作基础"; @@ -71,7 +77,8 @@ EXPECTED; $this->assertEquals($expected, $converter->convertToHtml($source)); } - function testDuplicatedTOC() { + public function testDuplicatedTOC() + { $converter = new CommonMarkConverter($this->getConfig()); $source = "[TOC]\n# Test\n# Test"; @@ -92,7 +99,8 @@ EXPECTED; $this->assertEquals($expected, $converter->convertToHtml($source)); } - function testEscapedTOC() { + public function testEscapedTOC() + { $converter = new CommonMarkConverter($this->getConfig()); $source = "[TOC]\n# TEST : Test"; diff --git a/tests/Server/ServerTest.php b/tests/Server/ServerTest.php index 53eef48..e08ca3b 100644 --- a/tests/Server/ServerTest.php +++ b/tests/Server/ServerTest.php @@ -4,16 +4,14 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\HttpFoundation\Request; use Todaymade\Daux\Format\HTML\RawPage; -use Todaymade\Daux\Config; use Todaymade\Daux\ConfigBuilder; use Todaymade\Daux\Daux; -use Todaymade\Daux\Server\Server; use org\bovigo\vfs\vfsStream; class ServerTest extends TestCase { - function testCreateResponse() { - + public function testCreateResponse() + { $structure = [ 'index.md' => 'first page', 'Page.md' => 'another page', @@ -39,4 +37,3 @@ class ServerTest extends TestCase $this->assertEquals("text/css", $response->headers->get('Content-Type')); } } -