Completed
Push — master ( db029f...19202d )
by Restu
16:00
created

RequiredRule::isValid()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

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
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
    public function isValid()
17
    {
18
        if ($this->data === null || empty($this->data)) {
19
            $this->setErrorMessage($this->attributes["validatorName"], Lang::get("validator.required", [
20
                'name' => $this->attributes["name"]
21
            ], "The {name} field is required."));
22
23
            return false;
24
        }
25
26
        return true;
27
    }
28
}
29