Completed
Push — master ( 0edfe9...83485f )
by Dmitry
08:42
created

VdsTariffForm   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 7
c 2
b 0
f 1
lcom 3
cbo 4
dl 0
loc 56
ccs 0
cts 25
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 7 1
A rules() 0 7 1
A getHardwareResources() 0 7 1
A getBaseHardwareResource() 0 7 2
A getPackage() 0 10 2
1
<?php
2
3
namespace hipanel\modules\finance\forms;
4
5
use hipanel\modules\finance\models\DomainResource;
6
use hipanel\modules\finance\models\ServerResource;
7
use hipanel\modules\server\models\Package;
8
9
class VdsTariffForm extends AbstractTariffForm
10
{
11
    public $note;
12
    public $label;
13
14
    protected $package;
15
16
    public function load($data)
17
    {
18
        $this->setAttributes($data[$this->formName()]);
19
        $this->setResources($data[(new DomainResource())->formName()]);
20
21
        return true;
22
    }
23
24
    public function rules()
25
    {
26
        $rules = parent::rules();
27
        $rules[] = [['note', 'label'], 'safe', 'on' => ['create', 'update']];
28
29
        return $rules;
30
    }
31
32
    /**
33
     * @return \hipanel\modules\finance\models\ServerResource[]
34
     */
35
    public function getHardwareResources()
36
    {
37
        return array_filter($this->tariff->resources, function ($model) {
38
            /** @var ServerResource $model */
39
            return $model->isModelTypeCorrect();
40
        });
41
    }
42
43
    /**
44
     * @return \hipanel\modules\finance\models\ServerResource[]
45
     */
46
    public function getBaseHardwareResource($object_id)
47
    {
48
        return array_filter($this->baseTariff->resources, function ($resource) use ($object_id) {
49
            /** @var ServerResource $model */
50
            return $resource->object_id == $object_id && $resource->isModelTypeCorrect();
51
        });
52
    }
53
54
    public function getPackage()
55
    {
56
        if (!$this->package instanceof Package) {
0 ignored issues
show
Bug introduced by
The class hipanel\modules\server\models\Package does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
57
            $this->package = new Package([
58
                'tariff' => $this->tariff,
59
            ]);
60
        }
61
62
        return $this->package;
63
    }
64
}
65