Javascript::setText()   A
last analyzed

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 1
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
}