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

CheckTrait::check_where_array()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 4
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 8
rs 10
1
<?php
2
3
namespace HnrAzevedo\Datamanager;
4
5
use Exception;
6
7
trait CheckTrait{
8
9
    protected function check_where_array(array $where)
10
    {
11
        if(count($where) != 3){
12
            throw new Exception("Condition where set incorrectly: ".implode(' ',$where));
13
        }
14
15
        if(!array_key_exists($where[0],$this->data) && $this->full){
16
            throw new Exception("{$where[0]} field does not exist in the table {$this->table}.");
17
        }
18
    }
19
20
    protected function isSettable(string $prop)
21
    {
22
        if($this->full && !array_key_exists($prop,$this->data)){
23
            throw new Exception("{$prop} field does not exist in the table {$this->table}.");
24
        }
25
    }
26
27
    protected function checkLimit()
28
    {
29
        if(is_null($this->limit)){
30
            throw new Exception("The limit must be set before the offset.");
31
        }
32
    }
33
34
    protected function checkMaxlength(string $field, $val , $max)
35
    {
36
        if(strlen($val) > $max){
37
            throw new Exception("The information provided for column {$field} of table {$this->table} exceeded that allowed.");
38
        }
39
    }
40
41
}
42