DirectoryValidatorTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateDir() 0 10 3
1
<?php
2
/**
3
 * ShouldPHP
4
 *
5
 * @author  Gabriel Jacinto <[email protected]>
6
 * @status  dev
7
 * @link    https://github.com/GabrielJMJ/ShouldPHP
8
 * @license MIT
9
 */
10
 
11
namespace Gabrieljmj\Should\Tool;
12
13
use Gabrieljmj\Should\Exception\DirectoryDoesNotExistException;
14
use Gabrieljmj\Should\Exception\DirectoryNotReadableException;
15
16
trait DirectoryValidatorTrait
17
{
18
    /**
19
     * Validates a directory for read
20
     *
21
     * @param string $dir
22
     * @return string
23
     */
24
    protected function validateDir($dir)
25
    {
26
        if (!is_dir($dir)) {
27
            DirectoryDoesNotExistException::trigger($dir);
28
        } elseif (!is_readable($dir)) {
29
            DirectoryNotReadableException::trigger($dir);
30
        }
31
32
        return $dir;
33
    }
34
}