Passed
Branch master (8a7ad0)
by Henri
01:23 queued 10s
created

Datamanager   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 13
Bugs 0 Features 0
Metric Value
eloc 40
c 13
b 0
f 0
dl 0
loc 92
rs 10
wmc 21

6 Methods

Rating   Name   Duplication   Size   Complexity  
B mountSave() 0 15 7
A mountSelect() 0 5 1
A mountWhereExec() 0 23 5
A mountLimit() 0 4 2
A mountOffset() 0 4 2
A mountRemove() 0 16 4
1
<?php
2
3
namespace HnrAzevedo\Datamanager;
4
5
abstract class Datamanager
6
{
7
    use DataTrait, SynchronizeTrait;
8
9
    protected ?string $table = null;
10
    protected ?string $primary = null;
11
    protected array $data = [];
12
13
    
14
    private array $where = [''=> ["1",'=',"1"] ];
15
16
17
    private function mountRemove(): array
0 ignored issues
show
Unused Code introduced by
The method mountRemove() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
18
    {
19
        $return = ['data' => '', 'where' => ''];
20
        foreach($this->where as $clause => $condition){
21
            if(strlen($clause) === 0){
22
                $return['where'] .= " {$clause} {$condition[0]} {$condition[1]} :q_{$condition[0]} ";
23
                $return['data'] .= "q_{$condition[0]}={$condition[2]}&";
24
                continue;
25
            }
26
                
27
            foreach($condition as $value){
28
                $return['where'] .= " {$clause} {$value[0]} {$value[1]} :q_{$value[0]} ";
29
                $return['data'] .= "q_{$value[0]}={$value[2]}&";
30
            }
31
        }
32
        return $return;
33
    }   
34
35
    private function mountSave(): array
0 ignored issues
show
Unused Code introduced by
The method mountSave() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
36
    {
37
        $return = ['data' => []];
38
39
        foreach ($this->data as $key => $value) {
40
            if(strstr($this->data[$key]['extra'],'auto_increment') && $key !== $this->primary){
41
                continue;
42
            }
43
44
            if(($this->data[$key]['changed'] && $this->data[$key]['upgradeable']) || $this->primary === $key){
45
                $return['data'][$key] = $this->data[$key]['value'];
46
            }
47
        }
48
49
        return $return;
50
    }
51
52
    
53
54
    private function mountWhereExec(): array
0 ignored issues
show
Unused Code introduced by
The method mountWhereExec() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
55
    {
56
        $return = ['where' => '', 'data' => []];
57
58
        foreach ($this->where as $key => $value) {
59
60
            $key = (!$key) ? '' : " {$key} ";
61
62
            if(is_array($value[0])){
63
64
                foreach ($value as $k => $v) {
65
                    $return['where'] .= " {$key} {$v[0]} {$v[1]} :q_{$v[0]} ";
66
                    $return['data']["q_{$v[0]}"] = $v[2];
67
                }
68
69
                continue;
70
            }
71
             
72
            $return['where'] .= " {$key} {$value[0]} {$value[1]} :q_{$value[0]} ";
73
            $return['data']["q_{$value[0]}"] = $value[2];
74
75
        }
76
        return $return;
77
    }
78
79
    private function mountSelect()
0 ignored issues
show
Unused Code introduced by
The method mountSelect() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
80
    {
81
        $select = implode(',',array_keys($this->select));
82
83
        $this->query = str_replace('*', $select,$this->query);
84
    }
85
86
    private function mountLimit()
0 ignored issues
show
Unused Code introduced by
The method mountLimit() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
87
    {
88
        if(!is_null($this->limit)){
89
            $this->query .= " LIMIT {$this->limit}";
90
        }
91
    }
92
93
    private function mountOffset()
0 ignored issues
show
Unused Code introduced by
The method mountOffset() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
94
    {
95
        if(!is_null($this->offset)){
96
            $this->query .= " OFFSET {$this->offset}";
97
        }
98
    }
99
100
}
101