GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 1b9783...a1719c )
by James Ekow Abaka
01:39
created

DefaultValidator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace ntentan\nibii;
4
5
use ntentan\nibii\RecordWrapper;
6
use ntentan\utils\Validator;
7
8
class DefaultValidator extends Validator
9
{
10
11
    private $model;
12
13
    /**
14
     * 
15
     * @param RecordWrapper
16
     */
17
    public function __construct(RecordWrapper $model, $mode)
18
    {
19
        $this->model = $model;   
20
        $this->registerValidation('unique', '\ntentan\nibii\UniqueValidation', ['model' => $model, 'mode' => $mode]);
21
    }
22
    
23
    public function extractRules()
24
    {
25
        $pk = null;
26
        $rules = [];
27
        $description = $this->model->getDescription();
28
29
        if ($description->getAutoPrimaryKey()) {
30
            $pk = $description->getPrimaryKey()[0];
31
        }
32
33
        $fields = $description->getFields();
34
        foreach ($fields as $field) {
35
            $this->getFieldRules($rules, $field, $pk);
36
        }
37
38
        $unique = $description->getUniqueKeys();
39
        foreach ($unique as $constraints) {
40
            $rules['unique'][] = [$constraints['fields']];
41
        }
42
43
        $this->setRules($rules);
44
    }
45
46
    private function getFieldRules(&$rules, $field, $pk)
47
    {
48
        if ($field['required'] && $field['name'] != $pk && $field['default'] === null) {
49
            $rules['required'][] = $field['name'];
50
        }
51
        if ($field['type'] === 'integer' || $field['type'] === 'double') {
52
            $rules['numeric'][] = $field['name'];
53
        }
54
    }
55
56
}
57