Test Failed
Pull Request — master (#20)
by
unknown
03:34
created

CompaniesBranches::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 16
ccs 0
cts 14
cp 0
crap 2
rs 9.9
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Gewaer\Models;
5
6
use Phalcon\Validation;
7
use Phalcon\Validation\Validator\PresenceOf;
8
9
/**
10
 * Class CompanyBranches
11
 *
12
 * @package Gewaer\Models
13
 *
14
 */
15
class CompaniesBranches extends AbstractModel
16
{
17
    /**
18
     *
19
     * @var integer
20
     */
21
    public $id;
22
23
    /**
24
     *
25
     * @var string
26
     */
27
    public $name;
28
29
    /**
30
     *
31
     * @var string
32
     */
33
    public $description;
34
35
    /**
36
     *
37
     * @var integer
38
     */
39
    public $companies_id;
40
41
    /**
42
     *
43
     * @var integer
44
     */
45
    public $users_id;
46
47
    /**
48
     *
49
     * @var integer
50
     */
51
    public $is_default;
52
53
    /**
54
     *
55
     * @var string
56
     */
57
    public $created_at;
58
59
    /**
60
     *
61
     * @var string
62
     */
63
    public $updated_at;
64
65
    /**
66
     *
67
     * @var integer
68
     */
69
    public $is_deleted;
70
71
    /**
72
     * Initialize method for model.
73
     */
74
    public function initialize()
75
    {
76
        $this->setSource('companies_branches');
77
78
        $this->belongsTo(
79
            'companies_id',
80
            'Gewaer\Models\Companies',
81
            'id',
82
            ['alias' => 'company']
83
        );
84
85
        $this->belongsTo(
86
            'users_id',
87
            'Gewaer\Models\Users',
88
            'id',
89
            ['alias' => 'id']
90
        );
91
    }
92
93
    /**
94
     * Model validation
95
     *
96
     * @return void
97
     */
98
    public function validation()
99
    {
100
        $validator = new Validation();
101
102
        $validator->add(
103
            'name',
104
            new PresenceOf([
105
                'model' => $this,
106
                'required' => true,
107
            ])
108
        );
109
110
        return $this->validate($validator);
111
    }
112
113
    /**
114
     * Returns table name mapped in the model.
115
     *
116
     * @return string
117
     */
118
    public function getSource() : string
119
    {
120
        return 'companies_branches';
121
    }
122
}
123