Passed
Push — master ( 682802...46670a )
by Maximo
05:00 queued 10s
created

CompanyBranches::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 16
ccs 12
cts 12
cp 1
crap 1
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 CompanyBranches 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 $company_id;
40
41
    /**
42
     *
43
     * @var integer
44
     */
45
    public $users_id;
46
47
    /**
48
     *
49
     * @var string
50
     */
51
    public $created_at;
52
53
    /**
54
     *
55
     * @var string
56
     */
57
    public $updated_at;
58
59
    /**
60
     *
61
     * @var integer
62
     */
63
    public $is_deleted;
64
65
    /**
66
     * Initialize method for model.
67
     */
68 1
    public function initialize()
69
    {
70 1
        $this->setSource('company_branches');
71
72 1
        $this->belongsTo(
73 1
            'company_id',
74 1
            'Gewaer\Models\Companies',
75 1
            'id',
76 1
            ['alias' => 'company']
77
        );
78
79 1
        $this->belongsTo(
80 1
            'users_id',
81 1
            'Gewaer\Models\Users',
82 1
            'id',
83 1
            ['alias' => 'id']
84
        );
85 1
    }
86
87
    /**
88
     * Model validation
89
     *
90
     * @return void
91
     */
92 1
    public function validation()
93
    {
94 1
        $validator = new Validation();
95
96 1
        $validator->add(
97 1
            'name',
98 1
            new PresenceOf([
99 1
                'model' => $this,
100
                'required' => true,
101
            ])
102
        );
103
104 1
        return $this->validate($validator);
105
    }
106
107
    /**
108
     * Returns table name mapped in the model.
109
     *
110
     * @return string
111
     */
112 1
    public function getSource() : string
113
    {
114 1
        return 'company_branches';
115
    }
116
}
117