Completed
Push — master ( 8d3e4d...0acf8f )
by Aske
25s queued 12s
created

AssetExistsViewHelper::initializeArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
namespace AE\History\ViewHelpers;
3
4
use Doctrine\ORM\EntityNotFoundException;
5
use Neos\Flow\Annotations as Flow;
6
use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper;
7
use Neos\Media\Domain\Model\AssetInterface;
8
9
class AssetExistsViewHelper extends AbstractViewHelper
10
{
11
    /**
12
     * @var boolean
13
     */
14
    protected $escapeOutput = false;
15
16
    /**
17
     * @throws \Neos\FluidAdaptor\Core\ViewHelper\Exception
18
     */
19
    public function initializeArguments()
20
    {
21
        parent::initializeArguments();
22
23
        $this->registerArgument('asset', AssetInterface::class, 'AssetInterface', true);
24
    }
25
26
    /**
27
     * Checks if an asset exists.
28
     *
29
     * @return string
30
     */
31
    public function render() : string
32
    {
33
        $asset = $this->arguments['asset'];
34
35
        try {
36
            $asset->getResource();
37
        } catch (EntityNotFoundException $e) {
38
            return '';
39
        }
40
41
        return $this->renderChildren();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->renderChildren() could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
42
    }
43
}
44