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

UriViewHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 29.73 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 11
loc 37
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeArguments() 0 5 1
A render() 11 11 2
A getFileConverter() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 returns the File Uri.
18
 */
19
class UriViewHelper extends AbstractViewHelper
20
{
21
22
    /**
23
     * @return void
24
     */
25
    public function initializeArguments()
26
    {
27
        $this->registerArgument('file', 'mixed', '', true);
28
        $this->registerArgument('relative', 'bool', '', false, false);
29
    }
30
31
    /**
32
     * Returns a property value of a file given by the context.
33
     *
34
     * @return string
35
     */
36 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...
37
    {
38
        /** @var File|Content|int $file $file */
39
        $file = $this->arguments['file'];
40
        $relative = $this->arguments['relative'];
41
42
        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...
43
            $file = $this->getFileConverter()->convert($file);
44
        }
45
        return $file->getPublicUrl($relative);
46
    }
47
48
    /**
49
     * @return \Fab\Media\TypeConverter\ContentToFileConverter|object
50
     */
51
    protected function getFileConverter()
52
    {
53
        return GeneralUtility::makeInstance(\Fab\Media\TypeConverter\ContentToFileConverter::class);
54
    }
55
}
56