Passed
Push — master ( aba784...c39888 )
by Andre
09:06 queued 11s
created

EnabledValidator   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 23
rs 10
c 2
b 0
f 0
wmc 9

1 Method

Rating   Name   Duplication   Size   Complexity  
B validateAttribute() 0 13 9
1
<?php
2
/**
3
 * Socializer plugin for Craft CMS 3.x
4
 *
5
 * @link      https://enupal.com/
6
 * @copyright Copyright (c) 2019 Enupal LLC
7
 */
8
9
namespace enupal\socializer\validators;
10
11
use enupal\socializer\Socializer;
12
use Hybridauth\Provider\Apple;
13
use yii\validators\Validator;
14
15
use Craft;
16
17
class EnabledValidator extends Validator
18
{
19
    public $skipOnEmpty = false;
20
21
    /**
22
     * Enabled Provider validation
23
     *
24
     * @param $object
25
     * @param $attribute
26
     */
27
    public function validateAttribute($object, $attribute)
28
    {
29
        if ($object->type != Apple::class) {
30
            if ($object->enabled && !$object->clientId) {
31
                $this->addError($object, $attribute, Craft::t('enupal-socializer','Client ID cannot be blank'));
32
            }
33
34
            if ($object->enabled && !$object->clientSecret) {
35
                $this->addError($object, 'clientSecret', Craft::t('enupal-socializer','Client Secret cannot be blank'));
36
            }
37
        }else if ($object->type === Apple::class && $object->enabled) {
38
            if (!Socializer::$app->settings->validateAppleSettings()) {
39
                $this->addError($object, 'enabled', Craft::t('enupal-socializer','Unable to process the Apple settings from the config file'));
40
            }
41
        }
42
43
    }
44
}
45