Completed
Push — development ( ef9e73...b2c3e4 )
by Andrij
20:27
created

GalleryMetaManipulator   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 63
rs 10
wmc 10
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 9 2
A getCategory() 0 13 4
A getName() 0 7 2
A get_category_by_id() 0 13 2
1
<?php
2
3
namespace CMSFactory\MetaManipulator;
4
5
use CI;
6
use CI_DB_result;
7
8
/**
9
 * Class GalleryMetaManipulator
10
 * @package CMSFactory\MetaManipulator
11
 */
12
class GalleryMetaManipulator extends MetaManipulator
13
{
0 ignored issues
show
introduced by
Opening brace of a class must be on the same line as the definition
Loading history...
14
15
    /**
16
     * @return string
17
     */
18
    public function getDescription() {
19
20
        if (!$this->description) {
21
            $desc = $this->getModel()['description'];
22
            $this->setDescription($desc);
23
        }
24
25
        return $this->description;
26
    }
27
28
    /**
29
     * @return string
30
     */
31
    public function getCategory() {
32
33
        if (!$this->category) {
34
35
            $category_id = $this->getModel()['category_id'] ?: $this->getModel()['id'];
36
            $categoryName = $this->get_category_by_id($category_id);
37
38
            if ($categoryName) {
39
                $this->setCategory($categoryName);
0 ignored issues
show
Documentation introduced by
$categoryName is of type boolean, but the function expects a string.

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...
40
            }
41
        }
42
        return $this->category;
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function getName() {
49
50
        if (!$this->name) {
51
            $this->setName($this->getModel()['name']);
52
        }
53
        return $this->name;
54
    }
55
56
    /**
57
     * @param int $id
58
     * @return bool
59
     */
60
    private function get_category_by_id($id) {
61
        $locale = \MY_Controller::getCurrentLocale();
62
        /** @var CI_DB_result $data */
63
        $data = CI::$APP->db->get_where('gallery_category_i18n', ['id' => $id, 'locale' => $locale]);
64
65
        if ($data->num_rows() > 0) {
66
67
            $data = $data->row_array();
68
            return $data['name'];
69
        }
70
71
        return false;
72
    }
73
74
}