Ajde_Embed_Vimeo   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 49
Duplicated Lines 34.69 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A convertUrlToEmbed() 0 7 3
A getCode() 9 9 1
A _getVimeoId() 8 11 4
A getThumbnail() 0 16 3

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
3
class Ajde_Embed_Vimeo extends Ajde_Embed
4
{
5
    public function convertUrlToEmbed()
6
    {
7
        if (substr($this->_code, 0, 7) == 'http://' || substr($this->_code, 0, 8) == 'https://') {
8
            $vimid = $this->_getVimeoId();
9
            $this->_code = '<iframe id="player_'.$vimid.'" src="http://player.vimeo.com/video/'.$vimid.'?title=0&amp;byline=0&amp;portrait=0&amp;api=1&amp;player_id=player_'.$vimid.'" width="400" height="225" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
10
        }
11
    }
12
13 View Code Duplication
    public function getCode()
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...
14
    {
15
        $this->convertUrlToEmbed();
16
        $this->_setHeight();
17
        $this->_setWidth();
18
        $this->_code = str_replace('portrait=0', 'portrait=0', $this->_code);
19
20
        return $this->_code;
21
    }
22
23
    private function _getVimeoId()
24
    {
25 View Code Duplication
        if (substr($this->_code, 0, 7) == 'http://' || substr($this->_code, 0, 8) == 'https://') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
26
            return str_replace('/', '', parse_url($this->_code, PHP_URL_PATH));
27
        } else {
28
            $matches = [];
29
            preg_match('%video/([0-9]+?)[\/\?\"]%', $this->_code, $matches);
30
31
            return isset($matches[1]) ? $matches[1] : null;
32
        }
33
    }
34
35
    public function getThumbnail()
36
    {
37
        $vmid = $this->_getVimeoId();
38
        if ($vmid) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $vmid of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
39
            $response = Ajde_Http_Curl::get("http://vimeo.com/api/v2/video/$vmid.php");
40
            try {
41
                $hash = unserialize($response);
42
            } catch (Exception $e) {
43
                Ajde_Exception_Log::logException(new Ajde_Exception('Could not parse result from Vimeo'));
0 ignored issues
show
Documentation introduced by
new \Ajde_Exception('Cou...rse result from Vimeo') is of type object<Ajde_Exception>, but the function expects a object<Throwable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
44
45
                return;
46
            }
47
48
            return $hash[0]['thumbnail_large'];
49
        }
50
    }
51
}
52