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

EnabledValidator::validateAttribute()   B

Complexity

Conditions 9
Paths 7

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 9
eloc 8
nc 7
nop 2
dl 0
loc 13
rs 8.0555
c 2
b 0
f 0
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