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

DirectoryEmpty::validate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
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
use Symfony\Component\Finder\Finder;
11
12
/**
13
 * @package Bluzman\Validation\Rules
14
 */
15
class DirectoryEmpty extends AbstractRule
16
{
17
    /**
18
     * @var string error template
19
     */
20
    protected $template = '{{name}} must be an empty directory';
21
22
    /**
23
     * @param $input
24
     * @return bool
25
     */
26
    public function directoryEmpty($input)
0 ignored issues
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
27
    {
28
        return $this->validate($input);
29
    }
30
31
    /**
32
     * @param mixed $input
33
     * @return bool
34
     */
35
    public function validate($input) : bool
36
    {
37
        $finder = new Finder();
38
39
        $itemsCount = $finder->in($input)->count();
40
41
        return $itemsCount < 1;
42
    }
43
}
44