ProviderSettings::validateAttribute()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 17
cp 0
rs 9.6666
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 12
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/patron/license
6
 * @link       https://www.flipboxfactory.com/software/patron/
7
 */
8
9
namespace flipbox\patron\validators;
10
11
use Craft;
12
use flipbox\patron\records\Provider;
13
use yii\base\InvalidArgumentException;
14
use yii\validators\Validator;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 1.0.0
19
 */
20
class ProviderSettings extends Validator
21
{
22
    /**
23
     * @inheritdoc
24
     * @throws \yii\base\InvalidConfigException
25
     */
26
    public function validateAttribute($model, $attribute)
27
    {
28
        if (!$model instanceof Provider) {
29
            throw new InvalidArgumentException(sprintf(
30
                "Model must be an instance of %s, %s given.",
31
                Provider::class,
32
                get_class($model)
33
            ));
34
        }
35
36
        if (!$model->getSettings()->validate()) {
37
            $message = Craft::t(
38
                'patron',
39
                'Invalid settings.'
40
            );
41
            $this->addError($model, $attribute, $message);
42
        }
43
    }
44
}
45