Passed
Push — master ( 53bb62...283d0c )
by Rougin
08:28
created

BaseValidator   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Test Coverage

Coverage 73.32%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
c 1
b 0
f 0
dl 0
loc 96
ccs 22
cts 30
cp 0.7332
rs 10
wmc 12

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getLibrary() 0 3 1
A __construct() 0 4 1
A getMessage() 0 3 1
B fails() 0 39 9
1
<?php
2
3
namespace Rougin\Combustor\Validator;
4
5
/**
6
 * Base Validator
7
 *
8
 * Checks if Wildfire or Doctrine is available
9
 *
10
 * @package Combustor
11
 * @author  Rougin Gutib <[email protected]>
12
 */
13
class BaseValidator implements ValidatorInterface
14
{
15
    /**
16
     * @var array
17
     */
18
    protected $file = [];
19
20
    /**
21
     * @var boolean
22
     */
23
    protected $isCamel = false;
24
25
    /**
26
     * @var string
27
     */
28
    protected $library = '';
29
30
    /**
31
     * @var string
32
     */
33
    protected $message = '';
34
35
    /**
36
     * @param boolean $isCamel
37
     * @param array   $file
38
     */
39 12
    public function __construct($isCamel, $file)
40
    {
41 12
        $this->file = $file;
42 12
        $this->isCamel = $isCamel;
43 12
    }
44
45
    /**
46
     * Checks if the validator fails.
47
     *
48
     * @return boolean
49
     */
50 12
    public function fails()
51
    {
52 12
        $hasDoctrine = file_exists(APPPATH . 'libraries/Doctrine.php');
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...
53 12
        $hasWildfire = file_exists(APPPATH . 'libraries/Wildfire.php');
54
55 12
        if (! $hasWildfire && ! $hasDoctrine) {
56 6
            $this->message = 'Please install Wildfire or Doctrine!';
57
58 6
            return true;
59
        }
60
61 6
        if ($hasWildfire && $hasDoctrine) {
62 3
            $this->message = 'Both Wildfire and Doctrine exists! Choose only one.';
63
64 3
            return true;
65
        }
66
67 3
        if ($hasWildfire && $this->isCamel) {
68
            $this->message = 'Wildfire does not support camel casing!';
69
70
            return true;
71
        }
72
73 3
        if (file_exists($this->file['path'])) {
74
            $name = $this->file['name'];
75
            $type = $this->file['type'];
76
77
            $this->message = 'The "' . $name . '" ' . $type . ' already exists!';
78
79
            return true;
80
        }
81
82 3
        if ($hasDoctrine) {
83
            $this->library = 'doctrine';
84
        } else {
85 3
            $this->library = 'wildfire';
86
        }
87
88 3
        return false;
89
    }
90
91
    /**
92
     * Gets the rendered message.
93
     *
94
     * @return string
95
     */
96 9
    public function getMessage()
97
    {
98 9
        return $this->message;
99
    }
100
101
    /**
102
     * Gets the selected library.
103
     *
104
     * @return string
105
     */
106 3
    public function getLibrary()
107
    {
108 3
        return $this->library;
109
    }
110
}
111