Fix warnings and errors reported by Scrutinizer
This commit is contained in:
parent
abaf36bec6
commit
688de1d5b9
@ -19,7 +19,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);
|
||||
});
|
||||
|
@ -38,15 +38,8 @@ class LinkRenderer implements InlineRendererInterface, ConfigurationAwareInterfa
|
||||
*/
|
||||
public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
|
||||
{
|
||||
// This can't be in the method type as
|
||||
// the method is an abstract and should
|
||||
// have the same interface
|
||||
if (!$inline instanceof Link) {
|
||||
throw new \RuntimeException(
|
||||
'Wrong type passed to ' . __CLASS__ . '::' . __METHOD__ .
|
||||
" the expected type was 'League\\CommonMark\\Inline\\Element\\Link' but '" .
|
||||
get_class($inline) . "' was provided"
|
||||
);
|
||||
if (!($inline instanceof Link)) {
|
||||
throw new \InvalidArgumentException('Incompatible inline type: ' . \get_class($inline));
|
||||
}
|
||||
|
||||
$element = $this->parent->render($inline, $htmlRenderer);
|
||||
|
@ -3,6 +3,7 @@
|
||||
use Todaymade\Daux\Exception\LinkNotFoundException;
|
||||
use Todaymade\Daux\Tree\Builder;
|
||||
use Todaymade\Daux\Tree\Directory;
|
||||
use Todaymade\Daux\Tree\Entry;
|
||||
|
||||
class DauxHelper
|
||||
{
|
||||
|
@ -16,15 +16,8 @@ class LinkRenderer extends \Todaymade\Daux\ContentTypes\Markdown\LinkRenderer
|
||||
*/
|
||||
public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
|
||||
{
|
||||
// This can't be in the method type as
|
||||
// the method is an abstract and should
|
||||
// have the same interface
|
||||
if (!$inline instanceof Link) {
|
||||
throw new \RuntimeException(
|
||||
'Wrong type passed to ' . __CLASS__ . '::' . __METHOD__ .
|
||||
" the expected type was 'League\\CommonMark\\Inline\\Element\\Link' but '" .
|
||||
get_class($inline) . "' was provided"
|
||||
);
|
||||
if (!($inline instanceof Link)) {
|
||||
throw new \InvalidArgumentException('Incompatible inline type: ' . \get_class($inline));
|
||||
}
|
||||
|
||||
// Default handling
|
||||
@ -34,7 +27,7 @@ class LinkRenderer extends \Todaymade\Daux\ContentTypes\Markdown\LinkRenderer
|
||||
|
||||
// empty urls, anchors and absolute urls
|
||||
// should not go through the url resolver
|
||||
if (!$this->isValidUrl($url) || $this->isExternalUrl($url)) {
|
||||
if (!DauxHelper::isValidUrl($url) || DauxHelper::isExternalUrl($url)) {
|
||||
return $element;
|
||||
}
|
||||
|
||||
|
@ -3,11 +3,16 @@
|
||||
use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\Block\Renderer\BlockRendererInterface;
|
||||
use League\CommonMark\ElementRendererInterface;
|
||||
use Todaymade\Daux\ContentTypes\Markdown\TableOfContents;
|
||||
|
||||
class TOCRenderer implements BlockRendererInterface
|
||||
{
|
||||
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
|
||||
{
|
||||
if (!($block instanceof TableOfContents)) {
|
||||
throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
|
||||
}
|
||||
|
||||
return '<ac:structured-macro ac:name="toc"></ac:structured-macro>';
|
||||
}
|
||||
}
|
||||
|
@ -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['ancestor_id'], $tree, $published);
|
||||
}
|
||||
);
|
||||
@ -143,7 +143,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;
|
||||
@ -164,7 +164,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);
|
||||
}
|
||||
@ -182,7 +182,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(
|
||||
@ -200,7 +200,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);
|
||||
}
|
||||
);
|
||||
|
@ -9,6 +9,7 @@ use League\CommonMark\Util\ConfigurationAwareInterface;
|
||||
use League\CommonMark\Util\ConfigurationInterface;
|
||||
use Todaymade\Daux\Config;
|
||||
use Todaymade\Daux\DauxHelper;
|
||||
use Todaymade\Daux\Exception\LinkNotFoundException;
|
||||
|
||||
class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterface
|
||||
{
|
||||
@ -22,6 +23,11 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var \League\CommonMark\Inline\Renderer\ImageRenderer
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
public function __construct($daux)
|
||||
{
|
||||
$this->daux = $daux;
|
||||
@ -32,11 +38,10 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf
|
||||
* 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
|
||||
*/
|
||||
protected function getCleanUrl(Image $element)
|
||||
protected function getCleanUrl($url)
|
||||
{
|
||||
$url = $element->getUrl();
|
||||
|
||||
// empty urls and anchors should
|
||||
// not go through the url resolver
|
||||
if (!DauxHelper::isValidUrl($url)) {
|
||||
@ -55,8 +60,6 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf
|
||||
if ($this->daux->isStatic()) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$element->setAttribute('class', 'Link--broken');
|
||||
}
|
||||
|
||||
return $url;
|
||||
@ -67,11 +70,16 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf
|
||||
* @param ElementRendererInterface $htmlRenderer
|
||||
*
|
||||
* @return HtmlElement
|
||||
*
|
||||
* @throws LinkNotFoundException
|
||||
*/
|
||||
public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
|
||||
{
|
||||
$original = $inline->getUrl();
|
||||
$inline->setUrl($this->getCleanUrl($inline));
|
||||
if (!($inline instanceof Image)) {
|
||||
throw new \InvalidArgumentException('Incompatible inline type: ' . \get_class($inline));
|
||||
}
|
||||
|
||||
$inline->setUrl($this->getCleanUrl($inline->getUrl()));
|
||||
|
||||
return $this->parent->render($inline, $htmlRenderer);
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ class Processor
|
||||
}
|
||||
}
|
||||
|
||||
$node->data['attributes']['id'] = $this->getUniqueId($document,'page_'. $this->escaped($text));
|
||||
$node->data['attributes']['id'] = $this->getUniqueId($document, 'page_'. $this->escaped($text));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,6 +4,7 @@ use League\CommonMark\Block\Element\AbstractBlock;
|
||||
use League\CommonMark\Block\Renderer\BlockRendererInterface;
|
||||
use League\CommonMark\ElementRendererInterface;
|
||||
use Todaymade\Daux\Config;
|
||||
use Todaymade\Daux\ContentTypes\Markdown\TableOfContents;
|
||||
|
||||
class Renderer implements BlockRendererInterface
|
||||
{
|
||||
@ -19,6 +20,10 @@ class Renderer implements BlockRendererInterface
|
||||
|
||||
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
|
||||
{
|
||||
if (!($block instanceof TableOfContents)) {
|
||||
throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
|
||||
}
|
||||
|
||||
$content = $htmlRenderer->renderBlocks($block->children());
|
||||
return $this->config->templateRenderer
|
||||
->getEngine($this->config)
|
||||
|
@ -77,13 +77,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->params['language'];
|
||||
|
||||
if (isset($this->engine->getData('page')['page'])) {
|
||||
@ -106,7 +106,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']);
|
||||
|
@ -11,19 +11,21 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
|
||||
{
|
||||
$content = parent::generatePage();
|
||||
|
||||
//Embed images
|
||||
// Embed images
|
||||
// We do it after generation so we can catch the images that were in html already
|
||||
$content = (new EmbedImages($this->params['tree']))
|
||||
->embed(
|
||||
$content,
|
||||
$this->file,
|
||||
function($src, array $attributes, Raw $file) {
|
||||
$content = base64_encode(file_get_contents($file->getPath()));
|
||||
// TODO :: ignore absolute paths
|
||||
$content = base64_encode(file_get_contents($file->getPath()));
|
||||
$attr = '';
|
||||
foreach ($attributes as $name => $value) {
|
||||
$attr .= ' ' . $name . '="' . htmlentities($value, ENT_QUOTES, 'UTF-8', false) . '"';
|
||||
}
|
||||
|
||||
// TODO :: handle other formats than PNG as well
|
||||
return "<img $attr src=\"data:image/png;base64,$content\"/>";
|
||||
}
|
||||
);
|
||||
|
@ -19,15 +19,8 @@ class LinkRenderer extends \Todaymade\Daux\ContentTypes\Markdown\LinkRenderer
|
||||
*/
|
||||
public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
|
||||
{
|
||||
// This can't be in the method type as
|
||||
// the method is an abstract and should
|
||||
// have the same interface
|
||||
if (!$inline instanceof Link) {
|
||||
throw new \RuntimeException(
|
||||
'Wrong type passed to ' . __CLASS__ . '::' . __METHOD__ .
|
||||
" the expected type was 'League\\CommonMark\\Inline\\Element\\Link' but '" .
|
||||
get_class($inline) . "' was provided"
|
||||
);
|
||||
if (!($inline instanceof Link)) {
|
||||
throw new \InvalidArgumentException('Incompatible inline type: ' . \get_class($inline));
|
||||
}
|
||||
|
||||
$element = parent::render($inline, $htmlRenderer);
|
||||
@ -36,12 +29,12 @@ class LinkRenderer extends \Todaymade\Daux\ContentTypes\Markdown\LinkRenderer
|
||||
|
||||
// empty urls and anchors should
|
||||
// not go through the url resolver
|
||||
if (!$this->isValidUrl($url)) {
|
||||
if (!DauxHelper::isValidUrl($url)) {
|
||||
return $element;
|
||||
}
|
||||
|
||||
// Absolute urls, shouldn't either
|
||||
if ($this->isExternalUrl($url)) {
|
||||
if (DauxHelper::isExternalUrl($url)) {
|
||||
$element->setAttribute('class', 'Link--external');
|
||||
|
||||
return $element;
|
||||
|
@ -10,11 +10,11 @@
|
||||
|
||||
<div class="Homepage">
|
||||
<div class="HomepageTitle Container">
|
||||
<?= ($params['tagline'])? '<h2>' . $params['tagline'] . '</h2>' : '' ?>
|
||||
<?= ($params['tagline']) ? '<h2>' . $params['tagline'] . '</h2>' : '' ?>
|
||||
</div>
|
||||
|
||||
<div class="HomepageImage Container">
|
||||
<?= ($params['image'])? '<img class="homepage-image img-responsive" src="' . $params['image'] . '" alt="' . $params['title'] . '">' : '' ?>
|
||||
<?= ($params['image']) ? '<img class="homepage-image img-responsive" src="' . $params['image'] . '" alt="' . $params['title'] . '">' : '' ?>
|
||||
</div>
|
||||
|
||||
<div class="HomepageButtons">
|
||||
@ -27,8 +27,8 @@
|
||||
foreach ($page['entry_page'] as $key => $node) {
|
||||
echo '<a href="' . $node . '" class="Button Button--primary Button--hero">' . str_replace("__VIEW_DOCUMENTATION__", $view_doc, $key) . '</a>';
|
||||
}
|
||||
if(isset($params['html']['buttons']) && is_array($params['html']['buttons'])) {
|
||||
foreach ($params['html']['buttons'] as $name => $link ) {
|
||||
if (isset($params['html']['buttons']) && is_array($params['html']['buttons'])) {
|
||||
foreach ($params['html']['buttons'] as $name => $link) {
|
||||
echo '<a href="' . $link . '" class="Button Button--secondary Button--hero">' . $name . '</a>';
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html class="no-js" lang="<?=$params['language'] ?>">
|
||||
<head>
|
||||
<title><?= $page['title']; ?> <?= ($page['title'] != $params['title'])? '- ' . $params['title'] : "" ?></title>
|
||||
<title><?= $page['title']; ?> <?= ($page['title'] != $params['title']) ? '- ' . $params['title'] : "" ?></title>
|
||||
<?php //SEO meta tags...
|
||||
if (array_key_exists('attributes', $page) && array_key_exists('description', $page['attributes'])) {
|
||||
echo " <meta name=\"description\" content=\"{$page['attributes']['description']}\">\n";
|
||||
|
@ -13,7 +13,7 @@
|
||||
"Link_next",
|
||||
];
|
||||
$search_translations = [];
|
||||
foreach($search_strings as $key) {
|
||||
foreach ($search_strings as $key) {
|
||||
$search_translations[$key] = $this->translate($key);
|
||||
}
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user