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

ConfigPrice::getFirstAvailable()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 12
ccs 0
cts 11
cp 0
rs 9.6111
c 0
b 0
f 0
cc 5
nc 3
nop 0
crap 30
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