Javascript   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 23.4 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 11
loc 47
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getSource() 0 4 1
A afterUpdate() 0 6 1
A findCachedById() 11 11 1
A setText() 0 4 1
A getText() 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
/**
3
     * @copyright Copyright (c) 2011 - 2014 Aleksandr Torosh (http://wezoom.net)
4
     * @author Aleksandr Torosh <[email protected]>
5
     */
6
7
namespace Cms\Model;
8
9
use Phalcon\Mvc\Model;
10
11
class Javascript extends Model
12
{
13
14
    public function getSource()
15
    {
16
        return "cms_javascript";
17
    }
18
19
    public $id;
20
    public $text;
21
22
    public function afterUpdate()
23
    {
24
        $cache = $this->getDi()->get('cache');
0 ignored issues
show
Bug introduced by
The method get cannot be called on $this->getDi() (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
25
        $key = HOST_HASH . md5("Javascript::getCachedScript({$this->id})");
26
        $cache->delete($key);
27
    }
28
29 View Code Duplication
    public static function findCachedById($id)
30
    {
31
        $key = HOST_HASH . md5("Javascript::getCachedScript($id)");
32
        $result = self::findFirst(array("id ='{$id}'",
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as self::findFirst(array("i..., 'lifetime' => 1200))) (which targets Phalcon\Mvc\Model::findFirst()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
33
            'cache' => array(
34
                'key' => $key,
35
                'lifetime' => 1200, //20 min
36
            )
37
        ));
38
        return $result;
39
    }
40
41
    /**
42
     * @param mixed $text
43
     */
44
    public function setText($text)
45
    {
46
        $this->text = $text;
47
    }
48
49
    /**
50
     * @param mixed
51
     */
52
    public function getText()
53
    {
54
        return $this->text;
55
    }
56
57
}