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)
|
public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
|
||||||
{
|
{
|
||||||
// This can't be in the method type as
|
if (!($inline instanceof Link)) {
|
||||||
// the method is an abstract and should
|
throw new \InvalidArgumentException('Incompatible inline type: ' . \get_class($inline));
|
||||||
// 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"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$element = $this->parent->render($inline, $htmlRenderer);
|
$element = $this->parent->render($inline, $htmlRenderer);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
use Todaymade\Daux\Exception\LinkNotFoundException;
|
use Todaymade\Daux\Exception\LinkNotFoundException;
|
||||||
use Todaymade\Daux\Tree\Builder;
|
use Todaymade\Daux\Tree\Builder;
|
||||||
use Todaymade\Daux\Tree\Directory;
|
use Todaymade\Daux\Tree\Directory;
|
||||||
|
use Todaymade\Daux\Tree\Entry;
|
||||||
|
|
||||||
class DauxHelper
|
class DauxHelper
|
||||||
{
|
{
|
||||||
|
@ -16,15 +16,8 @@ class LinkRenderer extends \Todaymade\Daux\ContentTypes\Markdown\LinkRenderer
|
|||||||
*/
|
*/
|
||||||
public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
|
public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
|
||||||
{
|
{
|
||||||
// This can't be in the method type as
|
if (!($inline instanceof Link)) {
|
||||||
// the method is an abstract and should
|
throw new \InvalidArgumentException('Incompatible inline type: ' . \get_class($inline));
|
||||||
// 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"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default handling
|
// Default handling
|
||||||
@ -34,7 +27,7 @@ class LinkRenderer extends \Todaymade\Daux\ContentTypes\Markdown\LinkRenderer
|
|||||||
|
|
||||||
// empty urls, anchors and absolute urls
|
// empty urls, anchors and absolute urls
|
||||||
// should not go through the url resolver
|
// should not go through the url resolver
|
||||||
if (!$this->isValidUrl($url) || $this->isExternalUrl($url)) {
|
if (!DauxHelper::isValidUrl($url) || DauxHelper::isExternalUrl($url)) {
|
||||||
return $element;
|
return $element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,11 +3,16 @@
|
|||||||
use League\CommonMark\Block\Element\AbstractBlock;
|
use League\CommonMark\Block\Element\AbstractBlock;
|
||||||
use League\CommonMark\Block\Renderer\BlockRendererInterface;
|
use League\CommonMark\Block\Renderer\BlockRendererInterface;
|
||||||
use League\CommonMark\ElementRendererInterface;
|
use League\CommonMark\ElementRendererInterface;
|
||||||
|
use Todaymade\Daux\ContentTypes\Markdown\TableOfContents;
|
||||||
|
|
||||||
class TOCRenderer implements BlockRendererInterface
|
class TOCRenderer implements BlockRendererInterface
|
||||||
{
|
{
|
||||||
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
|
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>';
|
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 League\CommonMark\Util\ConfigurationInterface;
|
||||||
use Todaymade\Daux\Config;
|
use Todaymade\Daux\Config;
|
||||||
use Todaymade\Daux\DauxHelper;
|
use Todaymade\Daux\DauxHelper;
|
||||||
|
use Todaymade\Daux\Exception\LinkNotFoundException;
|
||||||
|
|
||||||
class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterface
|
class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterface
|
||||||
{
|
{
|
||||||
@ -22,6 +23,11 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf
|
|||||||
*/
|
*/
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \League\CommonMark\Inline\Renderer\ImageRenderer
|
||||||
|
*/
|
||||||
|
protected $parent;
|
||||||
|
|
||||||
public function __construct($daux)
|
public function __construct($daux)
|
||||||
{
|
{
|
||||||
$this->daux = $daux;
|
$this->daux = $daux;
|
||||||
@ -32,11 +38,10 @@ 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).
|
* number prefix or the final name (with prefix stripped).
|
||||||
* This ensures that we always use the final name when generating.
|
* 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
|
// empty urls and anchors should
|
||||||
// not go through the url resolver
|
// not go through the url resolver
|
||||||
if (!DauxHelper::isValidUrl($url)) {
|
if (!DauxHelper::isValidUrl($url)) {
|
||||||
@ -55,8 +60,6 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf
|
|||||||
if ($this->daux->isStatic()) {
|
if ($this->daux->isStatic()) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
$element->setAttribute('class', 'Link--broken');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $url;
|
return $url;
|
||||||
@ -67,11 +70,16 @@ class ImageRenderer implements InlineRendererInterface, ConfigurationAwareInterf
|
|||||||
* @param ElementRendererInterface $htmlRenderer
|
* @param ElementRendererInterface $htmlRenderer
|
||||||
*
|
*
|
||||||
* @return HtmlElement
|
* @return HtmlElement
|
||||||
|
*
|
||||||
|
* @throws LinkNotFoundException
|
||||||
*/
|
*/
|
||||||
public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
|
public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
|
||||||
{
|
{
|
||||||
$original = $inline->getUrl();
|
if (!($inline instanceof Image)) {
|
||||||
$inline->setUrl($this->getCleanUrl($inline));
|
throw new \InvalidArgumentException('Incompatible inline type: ' . \get_class($inline));
|
||||||
|
}
|
||||||
|
|
||||||
|
$inline->setUrl($this->getCleanUrl($inline->getUrl()));
|
||||||
|
|
||||||
return $this->parent->render($inline, $htmlRenderer);
|
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\Block\Renderer\BlockRendererInterface;
|
||||||
use League\CommonMark\ElementRendererInterface;
|
use League\CommonMark\ElementRendererInterface;
|
||||||
use Todaymade\Daux\Config;
|
use Todaymade\Daux\Config;
|
||||||
|
use Todaymade\Daux\ContentTypes\Markdown\TableOfContents;
|
||||||
|
|
||||||
class Renderer implements BlockRendererInterface
|
class Renderer implements BlockRendererInterface
|
||||||
{
|
{
|
||||||
@ -19,6 +20,10 @@ class Renderer implements BlockRendererInterface
|
|||||||
|
|
||||||
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
|
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());
|
$content = $htmlRenderer->renderBlocks($block->children());
|
||||||
return $this->config->templateRenderer
|
return $this->config->templateRenderer
|
||||||
->getEngine($this->config)
|
->getEngine($this->config)
|
||||||
|
@ -18,12 +18,14 @@ class ContentPage extends \Todaymade\Daux\Format\Base\ContentPage
|
|||||||
$content,
|
$content,
|
||||||
$this->file,
|
$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()));
|
$content = base64_encode(file_get_contents($file->getPath()));
|
||||||
$attr = '';
|
$attr = '';
|
||||||
foreach ($attributes as $name => $value) {
|
foreach ($attributes as $name => $value) {
|
||||||
$attr .= ' ' . $name . '="' . htmlentities($value, ENT_QUOTES, 'UTF-8', false) . '"';
|
$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\"/>";
|
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)
|
public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
|
||||||
{
|
{
|
||||||
// This can't be in the method type as
|
if (!($inline instanceof Link)) {
|
||||||
// the method is an abstract and should
|
throw new \InvalidArgumentException('Incompatible inline type: ' . \get_class($inline));
|
||||||
// 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"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$element = parent::render($inline, $htmlRenderer);
|
$element = parent::render($inline, $htmlRenderer);
|
||||||
@ -36,12 +29,12 @@ class LinkRenderer extends \Todaymade\Daux\ContentTypes\Markdown\LinkRenderer
|
|||||||
|
|
||||||
// empty urls and anchors should
|
// empty urls and anchors should
|
||||||
// not go through the url resolver
|
// not go through the url resolver
|
||||||
if (!$this->isValidUrl($url)) {
|
if (!DauxHelper::isValidUrl($url)) {
|
||||||
return $element;
|
return $element;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Absolute urls, shouldn't either
|
// Absolute urls, shouldn't either
|
||||||
if ($this->isExternalUrl($url)) {
|
if (DauxHelper::isExternalUrl($url)) {
|
||||||
$element->setAttribute('class', 'Link--external');
|
$element->setAttribute('class', 'Link--external');
|
||||||
|
|
||||||
return $element;
|
return $element;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user