Passed
Push — develop ( 9b9f45...8c504f )
by Портнов
04:28
created

SipHosts   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 20
c 1
b 0
f 0
dl 0
loc 54
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 13 1
A validation() 0 13 1
1
<?php
2
/*
3
 * MikoPBX - free phone system for small business
4
 * Copyright (C) 2017-2020 Alexey Portnov and Nikolay Beketov
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with this program.
17
 * If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
namespace MikoPBX\Common\Models;
21
22
use Phalcon\Mvc\Model\Relation;
23
use Phalcon\Validation;
24
use Phalcon\Validation\Validator\Uniqueness as UniquenessValidator;
25
26
/**
27
 * Class SipHosts
28
 *
29
 * @package MikoPBX\Common\Models
30
 */
31
class SipHosts extends ModelsBase
32
{
33
    /**
34
     * @Primary
35
     * @Identity
36
     * @Column(type="integer", nullable=false)
37
     */
38
    public $id;
39
40
    /**
41
     * @Column(type="string", nullable=true)
42
     */
43
    public ?string $provider_id = '';
44
45
    /**
46
     * @Column(type="string", nullable=true)
47
     */
48
    public ?string $address = '';
49
50
    /**
51
     *
52
     */
53
    public function initialize(): void
54
    {
55
        $this->setSource('m_SipHosts');
56
        parent::initialize();
57
        $this->belongsTo(
58
            'provider_id',
59
            Sip::class,
60
            'uniqid',
61
            [
62
                'alias'      => 'Sip',
63
                'foreignKey' => [
64
                    'allowNulls' => false,
65
                    'action'     => Relation::NO_ACTION,
66
                ],
67
            ]
68
69
        );
70
    }
71
72
    public function validation(): bool
73
    {
74
        $validation = new Validation();
75
        $validation->add(
76
            ['provider_id', 'address'],
77
            new UniquenessValidator(
78
                [
79
                    'message' => $this->t('mo_ThisQueueAndMemberMustBeUniqueForCallQueuesModels'),
80
                ]
81
            )
82
        );
83
84
        return $this->validate($validation);
85
    }
86
}