RequiredRule::isValid()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 7
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 3
rs 9.4285
1
<?php
2
namespace JayaCode\Framework\Core\Validator\Rule;
3
4
use JayaCode\Framework\Core\Lang\Lang;
5
6
/**
7
 * Class RequiredRule
8
 * @package JayaCode\Framework\Core\Validator\Rule
9
 */
10
class RequiredRule extends Rule
11
{
12
13
    /**
14
     * @return bool
15
     */
16 6
    public function isValid()
17
    {
18 6
        if ($this->data === null || empty($this->data)) {
19 6
            $this->setErrorMessage($this->attributes["validatorName"], Lang::get("validator.required", [
20 6
                'name' => $this->attributes["name"]
21 6
            ], "The {name} field is required."));
22
23 6
            return false;
24
        }
25
26 3
        return true;
27
    }
28
}
29