Completed
Push — master ( 2b6e28...3d0129 )
by
unknown
10:26
created

GetVimeoIdViewHelper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 13
loc 13
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A render() 6 6 2

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

0 ignored issues
show
Coding Style introduced by
File has mixed line endings; this may cause incorrect results
Loading history...
2
namespace DCNGmbH\MooxCore\ViewHelpers;

3

4
/***************************************************************

5
 *  Copyright notice

6
 *

7
 *  (c) 2016 Jakub Czyz <[email protected]>, DCN GmbH

8
9
 *  All rights reserved

10
 *

11
 *  This script is part of the TYPO3 project. The TYPO3 project is

12
 *  free software; you can redistribute it and/or modify

13
 *  it under the terms of the GNU General Public License as published by

14
 *  the Free Software Foundation; either version 3 of the License, or

15
 *  (at your option) any later version.

16
 *

17
 *  The GNU General Public License can be found at

18
 *  http://www.gnu.org/copyleft/gpl.html.

19
 *

20
 *  This script is distributed in the hope that it will be useful,

21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of

22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

23
 *  GNU General Public License for more details.

24
 *

25
 *  This copyright notice MUST APPEAR in all copies of the script!

26
 ***************************************************************/

27

28
use \TYPO3\CMS\Core\Utility\GeneralUtility;

29

30
/**

31
 *

32
 *

33
 * @package moox_core

34
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later

35
 *

36
 */

37 View Code Duplication
class GetVimeoIdViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {

0 ignored issues
show
Duplication introduced by
This class 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...
38

39
    /**

40
     * @param string $url

41
     * @return string

42
     */

43
    public function render($url) {

44
        if (preg_match("/https?:\/\/(?:www\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|)(\d+)(?:$|\/|\?)/", $url, $match)) {

45
            $videoId = $match[3];

46
        }

47
        return $videoId;

0 ignored issues
show
Bug introduced by
The variable $videoId does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
48
    }

49
}

50