Update   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 24
c 1
b 0
f 0
dl 0
loc 84
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getResult() 0 3 1
A update() 0 24 3
1
<?php
2
3
4
namespace database;
5
6
7
/**
8
 * Class Update
9
 * @package src
10
 */
11
class Update
12
{
13
    /**
14
     * @var
15
     */
16
    private $table;
17
    /**
18
     * @var
19
     */
20
    private $update;
21
    /**
22
     * @var
23
     */
24
    private $statements;
25
    /**
26
     * @var
27
     */
28
    private $result;
29
    /**
30
     * @var
31
     */
32
    private $error;
33
    /**
34
     * @var
35
     */
36
    private $terms;
37
    /**
38
     * @var
39
     */
40
    private $places;
41
    /**
42
     * @var
43
     */
44
    private $data;
45
46
47
    /**
48
     * Update constructor.
49
     */
50
    public function __construct()
51
    {
52
53
    }
54
55
    /**
56
     * @return mixed
57
     */
58
    public function getResult()
59
    {
60
        return $this->result;
61
    }
62
63
64
65
    /**
66
     * @param string $table
67
     * @param array $data
68
     * @param string $terms
69
     * @param string $parse
70
     */
71
    public function update(string $table, array $data, string $terms, string $parse)
72
    {
73
        $this->table = $table;
74
        $this->terms = $terms;
75
        $this->data = $data;
76
        parse_str($parse, $this->statements);
77
78
        foreach ($data as $key => $value){
79
            $this->places[] = $key.' = :'.$key;
80
81
        }
82
83
        $this->places = implode(', ', $this->places);
84
85
        $this->update = "UPDATE {$this->table} SET {$this->places} {$this->terms}";
86
87
        try{
88
            $this->result = DB::connect()->prepare($this->update);
89
            $this->result->execute(array_merge($this->data, $this->statements));
90
            $this->error = true;
91
92
93
        }catch (\PDOException $e){
94
            echo $e->getMessage();
95
96
        }
97
98
99
    }
100
101
}