Fix lots of scrutinizer warnings, remove Travis

This commit is contained in:
Stéphane Goetz 2019-11-28 23:32:33 +01:00
parent 56efd83f2c
commit 13be180582
19 changed files with 97 additions and 80 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,7 +9,7 @@ class IndentedCodeRenderer extends CodeRenderer
{
/**
* @param AbstractBlock $block
* @param HtmlRendererInterface $htmlRenderer
* @param ElementRendererInterface $htmlRenderer
* @param bool $inTightList
*
* @return HtmlElement

View File

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

View File

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

View File

@ -7,6 +7,11 @@ use Todaymade\Daux\Config;
class Renderer implements BlockRendererInterface
{
/**
* @var Config
*/
private $config;
public function __construct(Config $config)
{
$this->config = $config;

View File

@ -21,6 +21,9 @@ class Generator implements \Todaymade\Daux\Format\Base\Generator, LiveGenerator
/** @var Daux */
protected $daux;
/** @var Template */
protected $templateRenderer;
protected $indexed_pages = [];
/**

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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