DirectoryValidatorTrait::validateDir()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 3
nc 3
nop 1
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
}