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

Datamanager::save()   A

Complexity

Conditions 2
Paths 4

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
cc 2
eloc 12
c 6
b 0
f 0
nc 4
nop 0
dl 0
loc 20
rs 9.8666
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