Completed
Push — master ( 0012a2...099852 )
by Dmitry
08:38
created

Tariff::find()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
/*
4
 * Finance module for HiPanel
5
 *
6
 * @link      https://github.com/hiqdev/hipanel-module-finance
7
 * @package   hipanel-module-finance
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hipanel\modules\finance\models;
13
14
use hipanel\modules\finance\models\query\TariffQuery;
15
16
/**
17
 * Class Tariff
18
 * @package hipanel\modules\finance\models
19
 * @property Resource[]|DomainResource[] $resources
20
 */
21
class Tariff extends \hipanel\base\Model
22
{
23
    use \hipanel\base\ModelTrait;
24
25
    const TYPE_DOMAIN = 'domain';
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 View Code Duplication
    public function rules()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
    {
32
        return [
33
            [['client_id', 'seller_id', 'id'],      'integer'],
34
            [['client', 'seller', 'bill', 'name'],  'safe'],
35
            [['domain', 'server'],                  'safe'],
36
            [['tariff', 'tariff_id'],               'safe'],
37
            [['type_id', 'state_id'],               'integer'],
38
            [['type', 'state'],                     'safe'],
39
            [['used'],                              'integer'],
40
            [['note', 'label'],                     'safe'],
41
        ];
42
    }
43
44
    public function getResources()
45
    {
46
        if ($this->type === self::TYPE_DOMAIN) {
0 ignored issues
show
Documentation introduced by
The property type does not exist on object<hipanel\modules\finance\models\Tariff>. 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...
47
            return $this->hasMany(DomainResource::class, ['tariff_id' => 'id']);
48
        }
49
50
        return $this->hasMany(Resource::class, ['tariff_id' => 'id']);
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function attributeLabels()
57
    {
58
        return $this->mergeAttributeLabels([
59
        ]);
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     * @return TariffQuery
65
     */
66
    public static function find($options = [])
67
    {
68
        return new TariffQuery(get_called_class(), [
69
            'options' => $options,
70
        ]);
71
    }
72
}
73