Completed
Branch develop (6195ed)
by Nate
06:16
created

LinkValidator::validateAttribute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 0
cts 13
cp 0
rs 9.584
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/link/license
6
 * @link       https://www.flipboxfactory.com/software/link/
7
 */
8
9
namespace flipbox\craft\link\validators;
10
11
use craft\base\Element;
12
use flipbox\craft\link\types\TypeInterface;
13
use yii\validators\Validator;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
class LinkValidator extends Validator
20
{
21
    /**
22
     * @inheritdoc
23
     */
24
    public function validateAttribute($element, $attribute)
25
    {
26
        /**
27
 * @var Element $element
28
*/
29
30
        /**
31
 * @var TypeInterface $value
32
*/
33
        $value = $element->$attribute;
34
35
        if ($value instanceof TypeInterface) {
36
            if (!$value->validateinput()) {
37
                $this->addError(
38
                    $element,
39
                    $attribute,
40
                    "Please fix the errors above."
41
                );
42
            }
43
        }
44
    }
45
}
46