' . $exception->getMessage() . '
'; + return ''.$exception->getMessage().'
'; } } } diff --git a/src/Renderer/ImageRenderer.php b/src/Renderer/ImageRenderer.php index f862a0d..b5d54a2 100644 --- a/src/Renderer/ImageRenderer.php +++ b/src/Renderer/ImageRenderer.php @@ -12,8 +12,8 @@ class ImageRenderer extends AbstractImageRenderer { public function supports(DocumentInterface $document, array $options): bool { - return (!isset($options['picture']) || $options['picture'] === false) && - parent::supports($document, $options); + return (!isset($options['picture']) || false === $options['picture']) + && parent::supports($document, $options); } public function render(DocumentInterface $document, array $options): string @@ -24,9 +24,9 @@ public function render(DocumentInterface $document, array $options): string * Override image by its first thumbnail if existing */ if ( - !$options['no_thumbnail'] && - $document instanceof HasThumbnailInterface && - $thumbnail = $document->getThumbnails()->first() + !$options['no_thumbnail'] + && $document instanceof HasThumbnailInterface + && $thumbnail = $document->getThumbnails()->first() ) { if ($thumbnail instanceof DocumentInterface) { $document = $thumbnail; @@ -38,7 +38,7 @@ public function render(DocumentInterface $document, array $options): string [ 'mimetype' => $document->getMimeType(), 'url' => $this->getSource($document, $options), - 'media' => null + 'media' => null, ] ); $assignation['alt'] = !empty($options['alt']) ? $options['alt'] : $document->getAlternativeText(); diff --git a/src/Renderer/InlineSvgRenderer.php b/src/Renderer/InlineSvgRenderer.php index 13a39a0..b6497a0 100644 --- a/src/Renderer/InlineSvgRenderer.php +++ b/src/Renderer/InlineSvgRenderer.php @@ -23,13 +23,10 @@ public function __construct(FilesystemOperator $documentsStorage) public function supports(DocumentInterface $document, array $options): bool { - return $document->isLocal() && $document->isSvg() && (isset($options['inline']) && $options['inline'] === true); + return $document->isLocal() && $document->isSvg() && (isset($options['inline']) && true === $options['inline']); } /** - * @param DocumentInterface $document - * @param array $options - * @return string * @throws FilesystemException */ public function render(DocumentInterface $document, array $options): string @@ -43,9 +40,10 @@ public function render(DocumentInterface $document, array $options): string $document, $assignation ); + return trim($this->htmlTidy($viewer->getContent())); } catch (\Exception $e) { - return '' . $e->getMessage() . '
'; + return ''.$e->getMessage().'
'; } } diff --git a/src/Renderer/PdfRenderer.php b/src/Renderer/PdfRenderer.php index 4ab5de0..d61f685 100644 --- a/src/Renderer/PdfRenderer.php +++ b/src/Renderer/PdfRenderer.php @@ -10,9 +10,9 @@ class PdfRenderer extends AbstractRenderer { public function supports(DocumentInterface $document, array $options): bool { - return $document->isPdf() && - key_exists('embed', $options) && - $options['embed'] === true; + return $document->isPdf() + && key_exists('embed', $options) + && true === $options['embed']; } /** diff --git a/src/Renderer/PictureRenderer.php b/src/Renderer/PictureRenderer.php index 9ed7fa8..78dd663 100644 --- a/src/Renderer/PictureRenderer.php +++ b/src/Renderer/PictureRenderer.php @@ -11,9 +11,9 @@ class PictureRenderer extends AbstractImageRenderer { public function supports(DocumentInterface $document, array $options): bool { - return isset($options['picture']) && - $options['picture'] === true && - parent::supports($document, $options); + return isset($options['picture']) + && true === $options['picture'] + && parent::supports($document, $options); } /** @@ -29,9 +29,9 @@ public function render(DocumentInterface $document, array $options): string * Override image by its first thumbnail if existing */ if ( - !$options['no_thumbnail'] && - $document instanceof HasThumbnailInterface && - $thumbnail = $document->getThumbnails()->first() + !$options['no_thumbnail'] + && $document instanceof HasThumbnailInterface + && $thumbnail = $document->getThumbnails()->first() ) { if ($thumbnail instanceof DocumentInterface) { $document = $thumbnail; @@ -80,9 +80,10 @@ private function parseMedia(DocumentInterface $document, array $options = []): a $mediaList[] = [ 'srcset' => $this->parseSrcSetInner($document, $media['srcset'], false, $options['absolute']), 'webp_srcset' => !$document->isWebp() ? $this->parseSrcSetInner($document, $media['srcset'], true, $options['absolute']) : null, - 'rule' => $media['rule'] + 'rule' => $media['rule'], ]; } + return $mediaList; } } diff --git a/src/Renderer/RendererInterface.php b/src/Renderer/RendererInterface.php index 76e4402..f000463 100644 --- a/src/Renderer/RendererInterface.php +++ b/src/Renderer/RendererInterface.php @@ -8,19 +8,7 @@ interface RendererInterface { - /** - * @param DocumentInterface $document - * @param array $options - * - * @return bool - */ public function supports(DocumentInterface $document, array $options): bool; - /** - * @param DocumentInterface $document - * @param array $options - * - * @return string - */ public function render(DocumentInterface $document, array $options): string; } diff --git a/src/Renderer/SvgRenderer.php b/src/Renderer/SvgRenderer.php index 06eaef9..a5f26be 100644 --- a/src/Renderer/SvgRenderer.php +++ b/src/Renderer/SvgRenderer.php @@ -22,7 +22,7 @@ public function __construct(FilesystemOperator $documentsStorage) public function supports(DocumentInterface $document, array $options): bool { - return $document->isSvg() && (!isset($options['inline']) || $options['inline'] === false); + return $document->isSvg() && (!isset($options['inline']) || false === $options['inline']); } public function render(DocumentInterface $document, array $options): string @@ -41,17 +41,12 @@ public function render(DocumentInterface $document, array $options): string if (is_string($value)) { $value = htmlspecialchars($value); } - $attrs[] = $key . '="' . $value . '"'; + $attrs[] = $key.'="'.$value.'"'; } - return ''; + return ''; } - /** - * @param array $options - * - * @return array - */ protected function getAttributes(array $options): array { $attributes = []; @@ -59,18 +54,19 @@ protected function getAttributes(array $options): array SvgDocumentViewer::$allowedAttributes, [ 'loading', - 'alt' + 'alt', ] ); foreach ($options as $key => $value) { if (in_array($key, $allowedAttributes)) { - if ($key === 'identifier') { + if ('identifier' === $key) { $attributes['id'] = $value; } else { $attributes[$key] = $value; } } } + return $attributes; } } diff --git a/src/Renderer/ThumbnailRenderer.php b/src/Renderer/ThumbnailRenderer.php index 72bddca..157701b 100644 --- a/src/Renderer/ThumbnailRenderer.php +++ b/src/Renderer/ThumbnailRenderer.php @@ -14,47 +14,33 @@ class ThumbnailRenderer implements RendererInterface { protected ?ChainRenderer $chainRenderer = null; - /** - * @param ChainRenderer|null $chainRenderer - */ public function __construct(?ChainRenderer $chainRenderer = null) { $this->chainRenderer = $chainRenderer; } - /** - * @param DocumentInterface $document - * @param array $options - * - * @return bool - */ public function supports(DocumentInterface $document, array $options): bool { - return null !== $this->chainRenderer && - (!key_exists('embed', $options) || - $options['embed'] !== true) && - $document instanceof HasThumbnailInterface && - $document->hasThumbnails() && - false !== $document->getThumbnails()->first(); + return null !== $this->chainRenderer + && (!key_exists('embed', $options) + || true !== $options['embed']) + && $document instanceof HasThumbnailInterface + && $document->hasThumbnails() + && false !== $document->getThumbnails()->first(); } - /** - * @param DocumentInterface $document - * @param array $options - * - * @return string - */ public function render(DocumentInterface $document, array $options): string { if ( - null !== $this->chainRenderer && - $document instanceof HasThumbnailInterface + null !== $this->chainRenderer + && $document instanceof HasThumbnailInterface ) { $thumbnail = $document->getThumbnails()->first(); if ($thumbnail instanceof DocumentInterface) { return $this->chainRenderer->render($thumbnail, $options); } } + return ''; } } diff --git a/src/Renderer/VideoRenderer.php b/src/Renderer/VideoRenderer.php index 15a84e4..c979e35 100644 --- a/src/Renderer/VideoRenderer.php +++ b/src/Renderer/VideoRenderer.php @@ -20,7 +20,7 @@ public function __construct( DocumentFinderInterface $documentFinder, Environment $templating, DocumentUrlGeneratorInterface $documentUrlGenerator, - string $templateBasePath = 'documents' + string $templateBasePath = 'documents', ) { parent::__construct($documentsStorage, $templating, $documentUrlGenerator, $templateBasePath); $this->documentFinder = $documentFinder; @@ -54,33 +54,28 @@ public function render(DocumentInterface $document, array $options): string */ $assignation['poster'] = $this->getPosterUrl($document, $options, $options['absolute']); } + return $this->renderHtmlElement('video.html.twig', $assignation); } - /** - * @param DocumentInterface $document - * @param array $options - * @param bool $absolute - * - * @return string|null - */ protected function getPosterUrl( DocumentInterface $document, array $options = [], - bool $absolute = false + bool $absolute = false, ): ?string { /* * Use document thumbnail first */ if ( - !$options['no_thumbnail'] && - $document instanceof HasThumbnailInterface && - $document->hasThumbnails() + !$options['no_thumbnail'] + && $document instanceof HasThumbnailInterface + && $document->hasThumbnails() ) { $thumbnail = $document->getThumbnails()->first(); if (false !== $thumbnail) { $this->documentUrlGenerator->setOptions($options); $this->documentUrlGenerator->setDocument($thumbnail); + return $this->documentUrlGenerator->getUrl($absolute); } } @@ -96,6 +91,7 @@ protected function getPosterUrl( foreach ($sourcesDocs as $sourcesDoc) { $this->documentUrlGenerator->setOptions($options); $this->documentUrlGenerator->setDocument($sourcesDoc); + return $this->documentUrlGenerator->getUrl($absolute); } @@ -107,10 +103,6 @@ protected function getPosterUrl( * * This method will search for document which filename is the same * except the extension. If you choose an MP4 file, it will look for a OGV and WEBM file. - * - * @param DocumentInterface $document - * - * @return array */ protected function getSourcesFiles(DocumentInterface $document): array { diff --git a/src/Repository/DocumentRepositoryInterface.php b/src/Repository/DocumentRepositoryInterface.php index d6bd01c..1de60ae 100644 --- a/src/Repository/DocumentRepositoryInterface.php +++ b/src/Repository/DocumentRepositoryInterface.php @@ -8,7 +8,9 @@ /** * @template T of \RZ\Roadiz\Documents\Models\DocumentInterface + * * @template-extends ObjectRepository