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

AssetExistsViewHelper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 11 2
A initializeArguments() 0 5 1
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