Conditions | 3 |
Paths | 4 |
Total Lines | 20 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 3.2621 |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
61 | 1 | public function setValue($key, $value) |
|
62 | { |
||
63 | 1 | $exists = (new Query()) |
|
64 | 1 | ->from($this->tableName) |
|
65 | 1 | ->where(['id' => $key]) |
|
66 | 1 | ->exists($this->db); |
|
67 | |||
68 | 1 | $query = (new Query())->createCommand($this->db); |
|
69 | |||
70 | try { |
||
71 | 1 | if ($exists) { |
|
72 | $query->update($this->tableName, ['data' => $value], ['id' => $key])->execute(); |
||
73 | } else { |
||
74 | 1 | $query->insert($this->tableName, ['id' => $key, 'data' => $value])->execute(); |
|
75 | } |
||
76 | } catch (\Exception $e) { |
||
77 | Yii::error(get_class($e) . '[' . $e->getCode() . '] ' . $e->getMessage()); |
||
78 | return false; |
||
79 | } |
||
80 | 1 | return true; |
|
81 | } |
||
96 |