Completed
Push — master ( 04ac75...81967b )
by Nate
17:06
created

ProviderSettings   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 0
loc 25
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateAttribute() 0 18 3
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\ProviderInstance as ProviderSettingsRecord;
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 ProviderSettingsRecord) {
29
            throw new InvalidArgumentException(sprintf(
30
                "Model must be an instance of %s, %s given.",
31
                ProviderSettingsRecord::class,
32
                get_class($model)
33
            ));
34
        }
35
36
        if (!$model->getProviderSettings()->validate()) {
37
            $message = Craft::t(
38
                'patron',
39
                'Invalid settings.'
40
            );
41
            $this->addError($model, $attribute, $message);
42
        }
43
    }
44
}
45