Insight   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
eloc 21
dl 0
loc 57
rs 10
c 1
b 0
f 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A insert() 0 8 1
A all() 0 4 1
A count() 0 4 1
A updateRemark() 0 8 1
1
<?php
2
namespace NirjharLo\Cgss\Models;
3
4
use wpdb;
0 ignored issues
show
Bug introduced by
The type wpdb was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
5
6
/**
7
 * Simple model for cgss_insight table.
8
 */
9
class Insight
10
{
11
    /** @var wpdb */
12
    protected $db;
13
14
    /** @var string */
15
    protected $table;
16
17
    public function __construct(?wpdb $db = null)
18
    {
19
        global $wpdb;
20
        $this->db = $db ?: $wpdb;
21
        $this->table = $this->db->prefix . 'cgss_insight';
22
    }
23
24
    /**
25
     * Get all rows from the insight table.
26
     */
27
    public function all(): array
28
    {
29
        $sql = "SELECT * FROM {$this->table}";
30
        return $this->db->get_results($sql, ARRAY_A);
0 ignored issues
show
Bug introduced by
The constant NirjharLo\Cgss\Models\ARRAY_A was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
31
    }
32
33
    /**
34
     * Count rows in the insight table.
35
     */
36
    public function count(): int
37
    {
38
        $sql = "SELECT COUNT(*) FROM {$this->table}";
39
        return (int) $this->db->get_var($sql);
40
    }
41
42
    /**
43
     * Insert an insight row.
44
     */
45
    public function insert(string $item, string $remark, int $id): bool
46
    {
47
        $result = $this->db->insert(
48
            $this->table,
49
            ['ID' => $id, 'item' => $item, 'remark' => $remark],
50
            ['%d', '%s', '%s']
51
        );
52
        return $result !== false;
53
    }
54
55
    /**
56
     * Update remark value by row id.
57
     */
58
    public function updateRemark(int $id, string $remark): int
59
    {
60
        return $this->db->update(
61
            $this->table,
62
            ['remark' => $remark],
63
            ['ID' => $id],
64
            ['%s'],
65
            ['%d']
66
        );
67
    }
68
}
69