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

DirectoryEmpty   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A directoryEmpty() 0 4 1
A validate() 0 8 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