From 13be1805826630301fa2d83d88cbfb4edff2f6c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Goetz?= Date: Thu, 28 Nov 2019 23:32:33 +0100 Subject: [PATCH] Fix lots of scrutinizer warnings, remove Travis --- .github/workflows/php.yml | 30 +++++++++++-------- .travis.yml | 15 ---------- README.md | 2 +- libs/Cache.php | 21 +++++++------ libs/ContentTypes/Markdown/LinkRenderer.php | 6 +++- .../Markdown/FencedCodeRenderer.php | 4 +-- .../ContentTypes/Markdown/ImageRenderer.php | 6 +++- .../Markdown/IndentedCodeRenderer.php | 2 +- libs/Format/HTML/ContentPage.php | 5 ++++ .../Markdown/FencedCodeRenderer.php | 13 +++++--- .../ContentTypes/Markdown/TOC/Renderer.php | 5 ++++ libs/Format/HTML/Generator.php | 3 ++ .../Markdown/CommonMarkConverter.php | 1 - libs/Format/HTMLFile/Generator.php | 5 +++- libs/Tree/Content.php | 14 ++++----- libs/Tree/ContentAbstract.php | 4 +-- libs/Tree/Directory.php | 21 ++++++------- libs/Tree/Entry.php | 14 ++++----- libs/Tree/Root.php | 6 ++-- 19 files changed, 97 insertions(+), 80 deletions(-) delete mode 100644 .travis.yml diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 4f31803..9e439fc 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -23,27 +23,16 @@ jobs: php-version: ${{ matrix.php-versions }} extension-csv: mbstring, dom - - name: Get Composer Cache Directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: Validate composer.json and composer.lock run: composer validate - - name: Cache vendor - uses: actions/cache@v1 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: ${{ runner.os }}-composer- - - name: Install dependencies run: composer install --prefer-dist --no-progress --no-suggest - name: Run test suite run: composer run-script test - sonarcloud: + scrutinizer-ci: runs-on: ubuntu-latest if: github.event_name != 'pull_request' steps: @@ -63,4 +52,19 @@ jobs: - run: wget https://scrutinizer-ci.com/ocular.phar - name: Upload code coverage - run: php ocular.phar code-coverage:upload --format=php-clover coverage.clover \ No newline at end of file + run: php ocular.phar code-coverage:upload --format=php-clover coverage.clover + + documentation: + runs-on: ubuntu-latest + if: github.repository == 'dauxio/daux.io' && github.event_name != 'pull_request' && github.ref == 'refs/heads/master' + steps: + - uses: actions/checkout@v1 + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest + - name: Generate documentation + run: vendor/bin/daux generate + - uses: JamesIves/github-pages-deploy-action@2.0.3 + env: + FOLDER: "static" + BRANCH: gh-pages + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 71fbe79..0000000 --- a/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -language: php - -php: - - '7.4' - - nightly - -matrix: - allow_failures: - - php: nightly - -before_script: - - composer install --prefer-dist --no-progress --no-suggest - -script: - - vendor/bin/phpunit diff --git a/README.md b/README.md index fab2957..42f639c 100755 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Latest Version](https://img.shields.io/github/release/dauxio/daux.io.svg?style=flat-square)](https://github.com/dauxio/daux.io/releases) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://github.com/dauxio/daux.io/blob/master/LICENSE.md) -[![Build Status](https://img.shields.io/travis/dauxio/daux.io/master.svg?style=flat-square)](https://travis-ci.org/dauxio/daux.io) +[![Build Status](https://github.com/dauxio/daux.io/workflows/CI/badge.svg)](https://github.com/dauxio/daux.io/actions) [![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/dauxio/daux.io.svg?style=flat-square)](https://scrutinizer-ci.com/g/dauxio/daux.io/code-structure) [![Quality Score](https://img.shields.io/scrutinizer/g/dauxio/daux.io.svg?style=flat-square)](https://scrutinizer-ci.com/g/dauxio/daux.io) [![Total Downloads](https://img.shields.io/packagist/dt/daux/daux.io.svg?style=flat-square)](https://packagist.org/packages/daux/daux.io) diff --git a/libs/Cache.php b/libs/Cache.php index e1f88bc..4fc7eb3 100644 --- a/libs/Cache.php +++ b/libs/Cache.php @@ -5,10 +5,9 @@ use Todaymade\Daux\Daux; class Cache { - static $printed = false; - public static function getDirectory() + public static function getDirectory(): string { $dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "dauxio" . DIRECTORY_SEPARATOR; @@ -24,10 +23,10 @@ class Cache * Store an item in the cache for a given number of minutes. * * @param string $key - * @param mixed $value + * @param string $value * @return void */ - public static function put($key, $value) + public static function put(string $key, string $value): void { Cache::ensureCacheDirectoryExists($path = Cache::path($key)); file_put_contents($path, $value); @@ -39,7 +38,7 @@ class Cache * @param string $path * @return void */ - protected static function ensureCacheDirectoryExists($path) + protected static function ensureCacheDirectoryExists(string $path): void { $parent = dirname($path); @@ -54,7 +53,7 @@ class Cache * @param string $key * @return bool */ - public static function forget($key) + public static function forget(string $key): bool { $path = Cache::path($key); @@ -68,10 +67,10 @@ class Cache /** * Retrieve an item from the cache by key. * - * @param string|array $key + * @param string $key * @return mixed */ - public static function get($key) + public static function get(string $key): ?string { $path = Cache::path($key); @@ -88,18 +87,18 @@ class Cache * @param string $key * @return string */ - protected static function path($key) + protected static function path(string $key): string { $parts = array_slice(str_split($hash = sha1($key), 2), 0, 2); return Cache::getDirectory() . '/' . implode('/', $parts) . '/' . $hash; } - public static function clear() + public static function clear(): void { Cache::rrmdir(Cache::getDirectory()); } - protected static function rrmdir($dir) + protected static function rrmdir(string $dir): void { if (is_dir($dir)) { $objects = scandir($dir); diff --git a/libs/ContentTypes/Markdown/LinkRenderer.php b/libs/ContentTypes/Markdown/LinkRenderer.php index 2cf6f21..b5bc7d9 100644 --- a/libs/ContentTypes/Markdown/LinkRenderer.php +++ b/libs/ContentTypes/Markdown/LinkRenderer.php @@ -19,6 +19,11 @@ class LinkRenderer implements InlineRendererInterface, ConfigurationAwareInterfa */ protected $daux; + /** + * @var \League\CommonMark\Inline\Renderer\LinkRenderer + */ + protected $parent; + public function __construct($daux) { $this->daux = $daux; @@ -158,7 +163,6 @@ class LinkRenderer implements InlineRendererInterface, ConfigurationAwareInterfa */ public function setConfiguration(ConfigurationInterface $configuration) { - $this->config = $configuration; $this->parent->setConfiguration($configuration); } } diff --git a/libs/Format/Confluence/ContentTypes/Markdown/FencedCodeRenderer.php b/libs/Format/Confluence/ContentTypes/Markdown/FencedCodeRenderer.php index 5d50682..b39d5aa 100644 --- a/libs/Format/Confluence/ContentTypes/Markdown/FencedCodeRenderer.php +++ b/libs/Format/Confluence/ContentTypes/Markdown/FencedCodeRenderer.php @@ -37,7 +37,7 @@ class FencedCodeRenderer extends CodeRenderer /** * @param AbstractBlock $block - * @param HtmlRendererInterface $htmlRenderer + * @param ElementRendererInterface $htmlRenderer * @param bool $inTightList * * @return HtmlElement|string @@ -59,7 +59,7 @@ class FencedCodeRenderer extends CodeRenderer return false; } - $language = Xml::escape($infoWords[0], true); + $language = Xml::escape($infoWords[0]); if (array_key_exists($language, $this->known_conversions)) { $language = $this->known_conversions[$language]; diff --git a/libs/Format/Confluence/ContentTypes/Markdown/ImageRenderer.php b/libs/Format/Confluence/ContentTypes/Markdown/ImageRenderer.php index 288670e..8d994d1 100644 --- a/libs/Format/Confluence/ContentTypes/Markdown/ImageRenderer.php +++ b/libs/Format/Confluence/ContentTypes/Markdown/ImageRenderer.php @@ -14,6 +14,11 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf */ protected $config; + /** + * @var \League\CommonMark\Inline\Renderer\LinkRenderer + */ + protected $parent; + public function __construct() { $this->parent = new \League\CommonMark\Inline\Renderer\ImageRenderer(); } @@ -47,7 +52,6 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf */ public function setConfiguration(ConfigurationInterface $configuration) { - $this->config = $configuration; $this->parent->setConfiguration($configuration); } } diff --git a/libs/Format/Confluence/ContentTypes/Markdown/IndentedCodeRenderer.php b/libs/Format/Confluence/ContentTypes/Markdown/IndentedCodeRenderer.php index 5e3cb09..3e04fb7 100644 --- a/libs/Format/Confluence/ContentTypes/Markdown/IndentedCodeRenderer.php +++ b/libs/Format/Confluence/ContentTypes/Markdown/IndentedCodeRenderer.php @@ -9,7 +9,7 @@ class IndentedCodeRenderer extends CodeRenderer { /** * @param AbstractBlock $block - * @param HtmlRendererInterface $htmlRenderer + * @param ElementRendererInterface $htmlRenderer * @param bool $inTightList * * @return HtmlElement diff --git a/libs/Format/HTML/ContentPage.php b/libs/Format/HTML/ContentPage.php index 5ad705b..79e9da1 100644 --- a/libs/Format/HTML/ContentPage.php +++ b/libs/Format/HTML/ContentPage.php @@ -7,6 +7,11 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage private $language; private $homepage; + /** + * @var Template + */ + public $templateRenderer; + private function isHomepage() { // If the current page isn't the index, no chance it is the landing page diff --git a/libs/Format/HTML/ContentTypes/Markdown/FencedCodeRenderer.php b/libs/Format/HTML/ContentTypes/Markdown/FencedCodeRenderer.php index 44f0d0a..e1710e1 100644 --- a/libs/Format/HTML/ContentTypes/Markdown/FencedCodeRenderer.php +++ b/libs/Format/HTML/ContentTypes/Markdown/FencedCodeRenderer.php @@ -10,13 +10,18 @@ use League\CommonMark\Util\Xml; class FencedCodeRenderer implements BlockRendererInterface { - function __construct() { + /** + * @var Highlighter + */ + private $hl; + + public function __construct() { $this->hl = new Highlighter(); } /** * @param AbstractBlock $block - * @param HtmlRendererInterface $htmlRenderer + * @param ElementRendererInterface $htmlRenderer * @param bool $inTightList * * @return HtmlElement|string @@ -43,7 +48,7 @@ class FencedCodeRenderer implements BlockRendererInterface $highlighted = $this->hl->highlight($language, $content); $content = $highlighted->value; $attrs['class'] .= 'hljs ' . $highlighted->language; - } catch (Exception $e) { + } catch (\Exception $e) { $attrs['class'] .= 'language-' . $language; } } @@ -65,6 +70,6 @@ class FencedCodeRenderer implements BlockRendererInterface return false; } - return Xml::escape($infoWords[0], true); + return Xml::escape($infoWords[0]); } } diff --git a/libs/Format/HTML/ContentTypes/Markdown/TOC/Renderer.php b/libs/Format/HTML/ContentTypes/Markdown/TOC/Renderer.php index 7ad8c98..e9b348d 100644 --- a/libs/Format/HTML/ContentTypes/Markdown/TOC/Renderer.php +++ b/libs/Format/HTML/ContentTypes/Markdown/TOC/Renderer.php @@ -7,6 +7,11 @@ use Todaymade\Daux\Config; class Renderer implements BlockRendererInterface { + /** + * @var Config + */ + private $config; + public function __construct(Config $config) { $this->config = $config; diff --git a/libs/Format/HTML/Generator.php b/libs/Format/HTML/Generator.php index 3a8c14e..dbf46c0 100755 --- a/libs/Format/HTML/Generator.php +++ b/libs/Format/HTML/Generator.php @@ -21,6 +21,9 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator /** @var Daux */ protected $daux; + /** @var Template */ + protected $templateRenderer; + protected $indexed_pages = []; /** diff --git a/libs/Format/HTMLFile/ContentTypes/Markdown/CommonMarkConverter.php b/libs/Format/HTMLFile/ContentTypes/Markdown/CommonMarkConverter.php index cf97727..4f3dd3a 100644 --- a/libs/Format/HTMLFile/ContentTypes/Markdown/CommonMarkConverter.php +++ b/libs/Format/HTMLFile/ContentTypes/Markdown/CommonMarkConverter.php @@ -7,7 +7,6 @@ class CommonMarkConverter extends \Todaymade\Daux\Format\HTML\ContentTypes\Markd { protected function getLinkRenderer(Environment $environment) { - var_dump(LinkRenderer::class); return new LinkRenderer($environment->getConfig('daux')); } } diff --git a/libs/Format/HTMLFile/Generator.php b/libs/Format/HTMLFile/Generator.php index 4d4f27b..77d7110 100644 --- a/libs/Format/HTMLFile/Generator.php +++ b/libs/Format/HTMLFile/Generator.php @@ -15,6 +15,9 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator /** @var Daux */ protected $daux; + /** @var Template */ + protected $templateRenderer; + /** * @param Daux $daux */ @@ -52,7 +55,7 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator $this->runAction( 'Cleaning destination folder ...', $width, - function() use ($destination, $params) { + function() use ($destination) { $this->ensureEmptyDestination($destination); } ); diff --git a/libs/Tree/Content.php b/libs/Tree/Content.php index 7259e16..b02073d 100644 --- a/libs/Tree/Content.php +++ b/libs/Tree/Content.php @@ -43,7 +43,7 @@ class Content extends ContentAbstract /** * @return string */ - public function getContent() + public function getContent(): string { if ($this->attributes === null) { $this->parseAttributes(); @@ -55,7 +55,7 @@ class Content extends ContentAbstract /** * @param string $content */ - public function setContent($content) + public function setContent(string $content): void { $this->manuallySetContent = true; $this->content = $content; @@ -64,7 +64,7 @@ class Content extends ContentAbstract /** * @return Content */ - public function getPrevious() + public function getPrevious(): ?Content { return $this->previous; } @@ -72,7 +72,7 @@ class Content extends ContentAbstract /** * @param Content $previous */ - public function setPrevious($previous) + public function setPrevious(Content $previous) { $this->previous = $previous; } @@ -80,7 +80,7 @@ class Content extends ContentAbstract /** * @return Content */ - public function getNext() + public function getNext(): ?Content { return $this->next; } @@ -88,7 +88,7 @@ class Content extends ContentAbstract /** * @param Content $next */ - public function setNext($next) + public function setNext(Content $next) { $this->next = $next; } @@ -102,7 +102,7 @@ class Content extends ContentAbstract return $this->name == 'index' || $this->name == '_index'; } - public function getTitle() + public function getTitle(): string { if ($title = $this->getAttribute('title')) { return $title; diff --git a/libs/Tree/ContentAbstract.php b/libs/Tree/ContentAbstract.php index 6636645..1571499 100644 --- a/libs/Tree/ContentAbstract.php +++ b/libs/Tree/ContentAbstract.php @@ -8,7 +8,7 @@ abstract class ContentAbstract extends Entry /** * @return string */ - public function getContent() + public function getContent(): string { return $this->content; } @@ -16,7 +16,7 @@ abstract class ContentAbstract extends Entry /** * @param string $content */ - public function setContent($content) + public function setContent(string $content): void { $this->content = $content; } diff --git a/libs/Tree/Directory.php b/libs/Tree/Directory.php index 958f1d6..86955d1 100644 --- a/libs/Tree/Directory.php +++ b/libs/Tree/Directory.php @@ -2,6 +2,7 @@ use ArrayIterator; use RuntimeException; +use Todaymade\Daux\Config; class Directory extends Entry implements \ArrayAccess, \IteratorAggregate { @@ -103,20 +104,20 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate return $this->children; } - public function addChild(Entry $entry) + public function addChild(Entry $entry): void { $this->children[$entry->getUri()] = $entry; } - public function removeChild(Entry $entry) + public function removeChild(Entry $entry): void { unset($this->children[$entry->getUri()]); } /** - * @return \Todaymade\Daux\Config + * @return Config */ - public function getConfig() + public function getConfig(): Config { if (!$this->parent) { throw new \RuntimeException('Could not retrieve configuration. Are you sure that your tree has a Root ?'); @@ -138,7 +139,7 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate /** * @return Content|null */ - public function getIndexPage() + public function getIndexPage(): ?Content { $index_key = $this->getConfig()['index_key']; @@ -157,7 +158,7 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate * Seek the first available page from descendants * @return Content|null */ - public function seekFirstPage() + public function seekFirstPage(): ?Content { if ($this instanceof self) { $index_key = $this->getConfig()['index_key']; @@ -182,7 +183,7 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate /** * @return Content|null */ - public function getFirstPage() + public function getFirstPage(): ?Content { if ($this->first_page) { return $this->first_page; @@ -217,7 +218,7 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate /** * @param Content $first_page */ - public function setFirstPage($first_page) + public function setFirstPage(Content $first_page) { $this->first_page = $first_page; } @@ -228,7 +229,7 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate * * @return bool */ - public function hasContent() + public function hasContent(): bool { foreach ($this->getEntries() as $node) { if ($node instanceof Content) { @@ -262,7 +263,7 @@ class Directory extends Entry implements \ArrayAccess, \IteratorAggregate * @param mixed $offset An offset to check for. * @return bool true on success or false on failure. */ - public function offsetExists($offset) + public function offsetExists($offset): bool { return array_key_exists($offset, $this->children); } diff --git a/libs/Tree/Entry.php b/libs/Tree/Entry.php index 7543041..5821f50 100644 --- a/libs/Tree/Entry.php +++ b/libs/Tree/Entry.php @@ -81,7 +81,7 @@ abstract class Entry /** * @return string */ - public function getTitle() + public function getTitle(): string { return $this->title; } @@ -89,7 +89,7 @@ abstract class Entry /** * @param string $title */ - public function setTitle($title) + public function setTitle(string $title) { $this->title = $title; } @@ -97,7 +97,7 @@ abstract class Entry /** * @return Directory */ - public function getParent() + public function getParent(): ?Directory { return $this->parent; } @@ -134,7 +134,7 @@ abstract class Entry /** * @return string */ - public function getPath() + public function getPath(): string { return $this->path; } @@ -144,7 +144,7 @@ abstract class Entry * * @return string */ - public function getRelativePath() + public function getRelativePath(): string { $root = $this; while ($root->getParent() != null) { @@ -157,7 +157,7 @@ abstract class Entry /** * @return SplFileInfo */ - public function getFileinfo() + public function getFileinfo(): SplFileInfo { return $this->info; } @@ -165,7 +165,7 @@ abstract class Entry /** * @return string */ - public function getUrl() + public function getUrl(): string { $url = ''; diff --git a/libs/Tree/Root.php b/libs/Tree/Root.php index b286ade..4148987 100644 --- a/libs/Tree/Root.php +++ b/libs/Tree/Root.php @@ -24,7 +24,7 @@ class Root extends Directory /** * @return Config */ - public function getConfig() + public function getConfig(): Config { return $this->config; } @@ -32,12 +32,12 @@ class Root extends Directory /** * @param Config $config */ - public function setConfig($config) + public function setConfig(Config $config) { $this->config = $config; } - public function isHotPath(Entry $node = null) { + public function isHotPath(Entry $node = null): bool { if ($node == null) { return true; }