Completed
Push — master ( 305f48...ad447f )
by Fabien
02:33
created

ExistsViewHelper::initializeArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Fab\Media\ViewHelpers\File;
3
4
/*
5
 * This file is part of the Fab/Media project under GPLv2 or later.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.md file that was distributed with this source code.
9
 */
10
11
use TYPO3\CMS\Core\Resource\File;
12
use TYPO3\CMS\Core\Utility\GeneralUtility;
13
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
14
use Fab\Vidi\Domain\Model\Content;
15
16
/**
17
 * View helper which tell whether a file exists.
18
 */
19
class ExistsViewHelper extends AbstractViewHelper
20
{
21
22
    /**
23
     * @return void
24
     */
25
    public function initializeArguments()
26
    {
27
        $this->registerArgument('file', 'mixed', '', true);
28
    }
29
30
    /**
31
     * Returns a property value of a file given by the context.
32
     *
33
     * @return bool
34
     */
35 View Code Duplication
    public function render()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        /** @var File|Content|int $file $file */
38
        $file = $this->arguments['file'];
39
40
        if (!$file instanceof File) {
0 ignored issues
show
Bug introduced by
The class TYPO3\CMS\Core\Resource\File does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
41
            $file = $this->getFileConverter()->convert($file);
42
        }
43
44
        return $file->exists();
45
    }
46
47
    /**
48
     * @return \Fab\Media\TypeConverter\ContentToFileConverter|object
49
     */
50
    protected function getFileConverter()
51
    {
52
        return GeneralUtility::makeInstance(\Fab\Media\TypeConverter\ContentToFileConverter::class);
53
    }
54
}
55