Completed
Push — master ( 922be9...285e65 )
by Nick
41s queued 31s
created

Banner   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 52.17%

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 51
ccs 12
cts 23
cp 0.5217
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A set_text() 0 15 3
A get_text() 0 16 4
1
<?php
2
/**
3
 * Banner Model
4
 *
5
 * @package TheyWorkForYou
6
 */
7
8
namespace MySociety\TheyWorkForYou\Model;
9
10
class Banner {
11
12
    /**
13
     * DB handle
14
     */
15
    private $db;
16
17
    /*
18
     * Memcache handle
19
     */
20
    private $mem;
21
22 1
    public function __construct()
23
    {
24 1
        $this->db = new \ParlDB;
25 1
        $this->mem = new \MySociety\TheyWorkForYou\Memcache();
26 1
    }
27
28
    public function get_text() {
29
        $text = $this->mem->get('banner');
30
31
        if ( $text === false ) {
0 ignored issues
show
introduced by
The condition $text === false is always true.
Loading history...
32
            $q = $this->db->query("SELECT value FROM editorial WHERE item = 'banner'")->first();
33
34
            if ($q) {
35
                $text = $q['value'];
36
                if ( trim($text) == '' ) {
37
                    $text = NULL;
38
                }
39
                $this->mem->set('banner', $text, 86400);
40
            }
41
        }
42
43
        return $text;
44
    }
45
46 1
    public function set_text($text) {
47 1
        $q = $this->db->query("REPLACE INTO editorial set item = 'banner', value = :banner_text",
48
            array(
49 1
                ':banner_text' => $text
50
            )
51
        );
52
53 1
        if ( $q->success() ) {
54 1
            if ( trim($text) == '' ) {
55 1
                $text = NULL;
56
            }
57 1
            $this->mem->set('banner', $text, 86400);
58 1
            return true;
59
        }
60
        return false;
61
    }
62
}
63