Completed
Push — master ( 01798b...15f6ef )
by Anton
08:29
created

Directory::validate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
1
<?php
2
/**
3
 * @copyright Bluz PHP Team
4
 * @link https://github.com/bluzphp/bluzman
5
 */
6
7
namespace Bluzman\Validator\Rule;
8
9
use Bluz\Validator\Rule\AbstractRule;
10
11
/**
12
 * @package Bluzman\Validation\Rules
13
 */
14
class Directory extends AbstractRule
15
{
16
    /**
17
     * @var string error template
18
     */
19
    protected $template = '{{name}} must be a directory';
20
21
    /**
22
     * @param $input
23
     * @return bool
24
     */
25
    public function directoryEmpty($input)
26
    {
27
        return $this->validate($input);
28
    }
29
30
    /**
31
     * @param mixed $input
32
     * @return bool
33
     */
34
    public function validate($input) : bool
35
    {
36
        if (is_string($input)) {
37
            return is_dir($input);
38
        } elseif ($input instanceof \SplFileInfo) {
39
            return $input->isDir();
40
        } else {
41
            return false;
42
        }
43
    }
44
}
45