Fix warnings and errors reported by Scrutinizer
This commit is contained in:
parent
abaf36bec6
commit
688de1d5b9
@ -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>';
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -18,12 +18,14 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
|
||||
$content,
|
||||
$this->file,
|
||||
function($src, array $attributes, Raw $file) {
|
||||
// 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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user