Completed
Push — master ( 27dc7b...6de725 )
by Andrii
05:04
created

ConfigPrice   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
eloc 10
dl 0
loc 25
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 5 1
A getFirstAvailable() 0 12 5
1
<?php
2
3
namespace hipanel\modules\server\models;
4
5
use hipanel\base\Model;
6
7
class ConfigPrice extends Model
8
{
9
    /**
10
     * {@inheritdoc}
11
     */
12
    public function rules()
13
    {
14
        return array_merge(parent::rules(), [
15
            [['location', 'currency', 'value', 'price', 'discounted_price'], 'string'],
16
            [['eur', 'usd'], 'string'],
17
        ]);
18
    }
19
20
    public function getFirstAvailable()
21
    {
22
        foreach (['eur', 'usd'] as $attribute) {
23
            if ($this->hasProperty($attribute) && !empty($this->{$attribute})) {
24
                foreach ($this->{$attribute} as $field => $value) {
25
                    $this->{$field} = $value;
26
                }
27
                break;
28
            }
29
        }
30
31
        return $this;
32
    }
33
}
34