ViewValidator::fails()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 3
b 0
f 0
nc 2
nop 0
dl 0
loc 11
ccs 6
cts 6
cp 1
crap 2
rs 10
1
<?php
2
3
namespace Rougin\Combustor\Validator;
4
5
use Rougin\Describe\Describe;
6
use Rougin\Combustor\Validator\ValidatorInterface;
7
8
/**
9
 * View Validator
10
 *
11
 * Checks if it is valid to generate view files.
12
 *
13
 * @package Combustor
14
 * @author  Rougin Gutib <[email protected]>
15
 */
16
class ViewValidator implements ValidatorInterface
17
{
18
    /**
19
     * @var string
20
     */
21
    protected $name = '';
22
23
    /**
24
     * @var string
25
     */
26
    protected $message = '';
27
28 9
    public function __construct($name)
29
    {
30 9
        $this->name = $name;
31 9
    }
32
33
    /**
34
     * Checks if the validator fails.
35
     *
36
     * @return boolean
37
     */
38 9
    public function fails()
39
    {
40 9
        $filePath = APPPATH . 'views/' . $this->name;
0 ignored issues
show
Bug introduced by
The constant Rougin\Combustor\Validator\APPPATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
41
42 9
        if (! @mkdir($filePath, 0775, true)) {
43 3
            $this->message = 'The "' . $this->name . '" views folder already exists!';
44
45 3
            return true;
46
        }
47
48 9
        return false;
49
    }
50
51
    /**
52
     * Gets the rendered message.
53
     *
54
     * @return string
55
     */
56 3
    public function getMessage()
57
    {
58 3
        return $this->message;
59
    }
60
}
61