Completed
Push — master ( 8fe40e...b786a3 )
by Andrii
06:29
created

Model   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 114
ccs 0
cts 88
cp 0
rs 10
wmc 15
lcom 1
cbo 2

8 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 4 1
B defaultAttributeLabels() 0 39 1
A attributeLabels() 0 4 1
C mergeAttributeLabels() 0 25 8
A getClient() 0 4 1
A getClientId() 0 4 1
A getSeller() 0 4 1
A getSellerId() 0 4 1
1
<?php
2
3
/*
4
 * HiPanel core package
5
 *
6
 * @link      https://hipanel.com/
7
 * @package   hipanel-core
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hipanel\base;
13
14
use Yii;
15
16
class Model extends \hiqdev\hiart\ActiveRecord
17
{
18
    /**
19
     * @var string the i18n dictionary name that will be used to translate labels of Model
20
     */
21
    public static $i18nDictionary = 'hipanel';
22
23
    /**
24
     * No rules be default.
25
     */
26
    public function rules()
27
    {
28
        return [];
29
    }
30
31
    /**
32
     * return default labels for attribute.
33
     */
34
    public function defaultAttributeLabels()
35
    {
36
        return [
37
            'id'            => Yii::t('hipanel', 'ID'),
38
            'remoteid'      => Yii::t('hipanel', 'Remote ID'),
39
            'client'        => Yii::t('hipanel', 'Client'),
40
            'client_id'     => Yii::t('hipanel', 'Client'),
41
            'seller'        => Yii::t('hipanel', 'Reseller'),
42
            'seller_id'     => Yii::t('hipanel', 'Reseller'),
43
            'domain'        => Yii::t('hipanel', 'Domain name'),
44
            'hdomain'       => Yii::t('hipanel', 'Domain name'),
45
            'ns'            => Yii::t('hipanel', 'Name Server'),
46
            'nss'           => Yii::t('hipanel', 'Name Servers'),
47
            'server'        => Yii::t('hipanel', 'Server'),
48
            'account'       => Yii::t('hipanel', 'Account'),
49
            'service'       => Yii::t('hipanel', 'Service'),
50
            'tariff'        => Yii::t('hipanel', 'Tariff'),
51
            'contact'       => Yii::t('hipanel', 'Contact'),
52
            'article'       => Yii::t('hipanel', 'Article'),
53
            'host'          => Yii::t('hipanel', 'Host'),
54
            'bill'          => Yii::t('hipanel', 'Bill'),
55
            'backup'        => Yii::t('hipanel', 'Backup'),
56
            'backuping'     => Yii::t('hipanel', 'Backuping'),
57
            'crontab'       => Yii::t('hipanel', 'Crontab'),
58
            'ip'            => Yii::t('hipanel', 'IP'),
59
            'ips'           => Yii::t('hipanel', 'IPs'),
60
            'mail'          => Yii::t('hipanel', 'Mail'),
61
            'request'       => Yii::t('hipanel', 'Request'),
62
            'db'            => Yii::t('hipanel', 'Database'),
63
            'state'         => Yii::t('hipanel', 'Status'),
64
            'status'        => Yii::t('hipanel', 'Status'),
65
            'type'          => Yii::t('hipanel', 'Type'),
66
            'note'          => Yii::t('hipanel', 'Note'),
67
            'descr'         => Yii::t('hipanel', 'Description'),
68
            'comment'       => Yii::t('hipanel', 'Comment'),
69
            'created_date'  => Yii::t('hipanel', 'Registered'),
70
            'updated_date'  => Yii::t('hipanel', 'Last update'),
71
       ];
72
    }
73
74
    public function attributeLabels()
75
    {
76
        return $this->defaultAttributeLabels();
77
    }
78
79
    protected static $mergedLabels = [];
80
81
    /**
82
     * Merge Attribute labels for Model.
83
     */
84
    public function mergeAttributeLabels($labels)
85
    {
86
        if (!isset(static::$mergedLabels[static::class])) {
87
            $default = $this->defaultAttributeLabels();
88
            foreach ($this->attributes() as $k) {
89
                $label = $labels[$k] ?: $default[$k];
90
                if (!$label) {
91
                    if (preg_match('/(.+)_[a-z]+$/', $k, $m)) {
92
                        if (isset($labels[$m[1]])) {
93
                            $label = $labels[$m[1]];
94
                        }
95
                    }
96
                }
97
                if (!$label) {
98
                    $toTranslate = preg_replace(['/_id$/', '/_label$/', '/_ids$/', '/_like$/'], [' ID', '', ' IDs', ''], $k);
99
                    $toTranslate = preg_replace('/_/', ' ', $toTranslate);
100
                    $label = Yii::t(static::$i18nDictionary, ucfirst($toTranslate));
101
                }
102
                $labels[$k] = $label;
103
            }
104
            static::$mergedLabels[static::class] = $labels;
105
        }
106
107
        return static::$mergedLabels[static::class];
108
    }
109
110
    public function getClient()
111
    {
112
        return $this->client;
0 ignored issues
show
Documentation introduced by
The property client does not exist on object<hipanel\base\Model>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
113
    }
114
115
    public function getClientId()
116
    {
117
        return $this->client_id;
0 ignored issues
show
Documentation introduced by
The property client_id does not exist on object<hipanel\base\Model>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
118
    }
119
120
    public function getSeller()
121
    {
122
        return $this->seller;
0 ignored issues
show
Documentation introduced by
The property seller does not exist on object<hipanel\base\Model>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
123
    }
124
125
    public function getSellerId()
126
    {
127
        return $this->seller_id;
0 ignored issues
show
Documentation introduced by
The property seller_id does not exist on object<hipanel\base\Model>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
128
    }
129
}
130