Passed
Pull Request — master (#58)
by
unknown
01:49
created
src/EnvironmentCheckSuite.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -150,7 +150,7 @@
 block discarded – undo
150 150
             } elseif ($checkClass instanceof EnvironmentCheck) {
151 151
                 $output[] = [$checkClass, $checkTitle];
152 152
             } else {
153
-                throw new InvalidArgumentException("Bad EnvironmentCheck: " . var_export($check, true));
153
+                throw new InvalidArgumentException("Bad EnvironmentCheck: ".var_export($check, true));
154 154
             }
155 155
         }
156 156
         return $output;
Please login to merge, or discard this patch.
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -32,184 +32,184 @@
 block discarded – undo
32 32
  */
33 33
 class EnvironmentCheckSuite
34 34
 {
35
-    use Configurable;
36
-    use Injectable;
37
-    use Extensible;
38
-    /**
39
-     * Name of this suite.
40
-     *
41
-     * @var string
42
-     */
43
-    protected $name;
44
-
45
-    /**
46
-     * @var array
47
-     */
48
-    protected $checks = [];
49
-
50
-    /**
51
-     * Associative array of named checks registered via the config system. Each check should specify:
52
-     * - definition (e.g. 'MyHealthCheck("my param")')
53
-     * - title (e.g. 'Is my feature working?')
54
-     * - state (setting this to 'disabled' will cause suites to skip this check entirely.
55
-     *
56
-     * @var array
57
-     */
58
-    private static $registered_checks = [];
59
-
60
-    /**
61
-     * Associative array of named suites registered via the config system. Each suite should enumerate
62
-     * named checks that have been configured in 'registered_checks'.
63
-     *
64
-     * @var array
65
-     */
66
-    private static $registered_suites = [];
67
-
68
-    /**
69
-     * Load checks for this suite from the configuration system. This is an alternative to the
70
-     * EnvironmentCheckSuite::register - both can be used, checks will be appended to the suite.
71
-     *
72
-     * @param string $suiteName The name of this suite.
73
-     */
74
-    public function __construct($suiteName)
75
-    {
76
-        if (empty($this->config()->registered_suites[$suiteName])) {
77
-            // Not registered via config system, but it still may be configured later via self::register.
78
-            return;
79
-        }
80
-
81
-        foreach ($this->config()->registered_suites[$suiteName] as $checkName) {
82
-            if (empty($this->config()->registered_checks[$checkName])) {
83
-                throw new InvalidArgumentException(
84
-                    "Bad EnvironmentCheck: '$checkName' - the named check has not been registered."
85
-                );
86
-            }
87
-
88
-            $check = $this->config()->registered_checks[$checkName];
89
-
90
-            // Existing named checks can be disabled by setting their 'state' to 'disabled'.
91
-            // This is handy for disabling checks mandated by modules.
92
-            if (!empty($check['state']) && $check['state'] === 'disabled') {
93
-                continue;
94
-            }
95
-
96
-            // Add the check to this suite.
97
-            $this->push($check['definition'], $check['title']);
98
-        }
99
-    }
100
-
101
-    /**
102
-     * Run this test suite and return the result code of the worst result.
103
-     *
104
-     * @return int
105
-     */
106
-    public function run()
107
-    {
108
-        $result = new EnvironmentCheckSuiteResult();
109
-
110
-        foreach ($this->checkInstances() as $check) {
111
-            list($checkClass, $checkTitle) = $check;
112
-            try {
113
-                list($status, $message) = $checkClass->check();
114
-            // If the check fails, register that as an error
115
-            } catch (Exception $e) {
116
-                $status = EnvironmentCheck::ERROR;
117
-                $message = $e->getMessage();
118
-            }
119
-            $result->addResult($status, $message, $checkTitle);
120
-        }
121
-
122
-        return $result;
123
-    }
124
-
125
-    /**
126
-     * Get instances of all the environment checks.
127
-     *
128
-     * @return array
129
-     * @throws InvalidArgumentException
130
-     */
131
-    protected function checkInstances()
132
-    {
133
-        $output = [];
134
-        foreach ($this->checks as $check) {
135
-            list($checkClass, $checkTitle) = $check;
136
-            if (is_string($checkClass)) {
137
-                $checkInst = Injector::inst()->create($checkClass);
138
-                if ($checkInst instanceof EnvironmentCheck) {
139
-                    $output[] = [$checkInst, $checkTitle];
140
-                } else {
141
-                    throw new InvalidArgumentException(
142
-                        "Bad EnvironmentCheck: '$checkClass' - the named class doesn't implement EnvironmentCheck"
143
-                    );
144
-                }
145
-            } elseif ($checkClass instanceof EnvironmentCheck) {
146
-                $output[] = [$checkClass, $checkTitle];
147
-            } else {
148
-                throw new InvalidArgumentException("Bad EnvironmentCheck: " . var_export($check, true));
149
-            }
150
-        }
151
-        return $output;
152
-    }
153
-
154
-    /**
155
-     * Add a check to this suite.
156
-     *
157
-     * @param mixed $check
158
-     * @param string $title
159
-     */
160
-    public function push($check, $title = null)
161
-    {
162
-        if (!$title) {
163
-            $title = is_string($check) ? $check : get_class($check);
164
-        }
165
-        $this->checks[] = [$check, $title];
166
-    }
167
-
168
-    /////////////////////////////////////////////////////////////////////////////////////////////
169
-
170
-    /**
171
-     * @var array
172
-     */
173
-    protected static $instances = [];
174
-
175
-    /**
176
-     * Return a named instance of EnvironmentCheckSuite.
177
-     *
178
-     * @param string $name
179
-     *
180
-     * @return EnvironmentCheckSuite
181
-     */
182
-    public static function inst($name)
183
-    {
184
-        if (!isset(self::$instances[$name])) {
185
-            self::$instances[$name] = new EnvironmentCheckSuite($name);
186
-        }
187
-        return self::$instances[$name];
188
-    }
189
-
190
-    /**
191
-     * Register a check against the named check suite.
192
-     *
193
-     * @param string|array $names
194
-     * @param EnvironmentCheck $check
195
-     * @param string|array
196
-     */
197
-    public static function register($names, $check, $title = null)
198
-    {
199
-        if (!is_array($names)) {
200
-            $names = [$names];
201
-        }
202
-
203
-        foreach ($names as $name) {
204
-            self::inst($name)->push($check, $title);
205
-        }
206
-    }
207
-
208
-    /**
209
-     * Unregisters all checks.
210
-     */
211
-    public static function reset()
212
-    {
213
-        self::$instances = [];
214
-    }
35
+	use Configurable;
36
+	use Injectable;
37
+	use Extensible;
38
+	/**
39
+	 * Name of this suite.
40
+	 *
41
+	 * @var string
42
+	 */
43
+	protected $name;
44
+
45
+	/**
46
+	 * @var array
47
+	 */
48
+	protected $checks = [];
49
+
50
+	/**
51
+	 * Associative array of named checks registered via the config system. Each check should specify:
52
+	 * - definition (e.g. 'MyHealthCheck("my param")')
53
+	 * - title (e.g. 'Is my feature working?')
54
+	 * - state (setting this to 'disabled' will cause suites to skip this check entirely.
55
+	 *
56
+	 * @var array
57
+	 */
58
+	private static $registered_checks = [];
59
+
60
+	/**
61
+	 * Associative array of named suites registered via the config system. Each suite should enumerate
62
+	 * named checks that have been configured in 'registered_checks'.
63
+	 *
64
+	 * @var array
65
+	 */
66
+	private static $registered_suites = [];
67
+
68
+	/**
69
+	 * Load checks for this suite from the configuration system. This is an alternative to the
70
+	 * EnvironmentCheckSuite::register - both can be used, checks will be appended to the suite.
71
+	 *
72
+	 * @param string $suiteName The name of this suite.
73
+	 */
74
+	public function __construct($suiteName)
75
+	{
76
+		if (empty($this->config()->registered_suites[$suiteName])) {
77
+			// Not registered via config system, but it still may be configured later via self::register.
78
+			return;
79
+		}
80
+
81
+		foreach ($this->config()->registered_suites[$suiteName] as $checkName) {
82
+			if (empty($this->config()->registered_checks[$checkName])) {
83
+				throw new InvalidArgumentException(
84
+					"Bad EnvironmentCheck: '$checkName' - the named check has not been registered."
85
+				);
86
+			}
87
+
88
+			$check = $this->config()->registered_checks[$checkName];
89
+
90
+			// Existing named checks can be disabled by setting their 'state' to 'disabled'.
91
+			// This is handy for disabling checks mandated by modules.
92
+			if (!empty($check['state']) && $check['state'] === 'disabled') {
93
+				continue;
94
+			}
95
+
96
+			// Add the check to this suite.
97
+			$this->push($check['definition'], $check['title']);
98
+		}
99
+	}
100
+
101
+	/**
102
+	 * Run this test suite and return the result code of the worst result.
103
+	 *
104
+	 * @return int
105
+	 */
106
+	public function run()
107
+	{
108
+		$result = new EnvironmentCheckSuiteResult();
109
+
110
+		foreach ($this->checkInstances() as $check) {
111
+			list($checkClass, $checkTitle) = $check;
112
+			try {
113
+				list($status, $message) = $checkClass->check();
114
+			// If the check fails, register that as an error
115
+			} catch (Exception $e) {
116
+				$status = EnvironmentCheck::ERROR;
117
+				$message = $e->getMessage();
118
+			}
119
+			$result->addResult($status, $message, $checkTitle);
120
+		}
121
+
122
+		return $result;
123
+	}
124
+
125
+	/**
126
+	 * Get instances of all the environment checks.
127
+	 *
128
+	 * @return array
129
+	 * @throws InvalidArgumentException
130
+	 */
131
+	protected function checkInstances()
132
+	{
133
+		$output = [];
134
+		foreach ($this->checks as $check) {
135
+			list($checkClass, $checkTitle) = $check;
136
+			if (is_string($checkClass)) {
137
+				$checkInst = Injector::inst()->create($checkClass);
138
+				if ($checkInst instanceof EnvironmentCheck) {
139
+					$output[] = [$checkInst, $checkTitle];
140
+				} else {
141
+					throw new InvalidArgumentException(
142
+						"Bad EnvironmentCheck: '$checkClass' - the named class doesn't implement EnvironmentCheck"
143
+					);
144
+				}
145
+			} elseif ($checkClass instanceof EnvironmentCheck) {
146
+				$output[] = [$checkClass, $checkTitle];
147
+			} else {
148
+				throw new InvalidArgumentException("Bad EnvironmentCheck: " . var_export($check, true));
149
+			}
150
+		}
151
+		return $output;
152
+	}
153
+
154
+	/**
155
+	 * Add a check to this suite.
156
+	 *
157
+	 * @param mixed $check
158
+	 * @param string $title
159
+	 */
160
+	public function push($check, $title = null)
161
+	{
162
+		if (!$title) {
163
+			$title = is_string($check) ? $check : get_class($check);
164
+		}
165
+		$this->checks[] = [$check, $title];
166
+	}
167
+
168
+	/////////////////////////////////////////////////////////////////////////////////////////////
169
+
170
+	/**
171
+	 * @var array
172
+	 */
173
+	protected static $instances = [];
174
+
175
+	/**
176
+	 * Return a named instance of EnvironmentCheckSuite.
177
+	 *
178
+	 * @param string $name
179
+	 *
180
+	 * @return EnvironmentCheckSuite
181
+	 */
182
+	public static function inst($name)
183
+	{
184
+		if (!isset(self::$instances[$name])) {
185
+			self::$instances[$name] = new EnvironmentCheckSuite($name);
186
+		}
187
+		return self::$instances[$name];
188
+	}
189
+
190
+	/**
191
+	 * Register a check against the named check suite.
192
+	 *
193
+	 * @param string|array $names
194
+	 * @param EnvironmentCheck $check
195
+	 * @param string|array
196
+	 */
197
+	public static function register($names, $check, $title = null)
198
+	{
199
+		if (!is_array($names)) {
200
+			$names = [$names];
201
+		}
202
+
203
+		foreach ($names as $name) {
204
+			self::inst($name)->push($check, $title);
205
+		}
206
+	}
207
+
208
+	/**
209
+	 * Unregisters all checks.
210
+	 */
211
+	public static function reset()
212
+	{
213
+		self::$instances = [];
214
+	}
215 215
 }
Please login to merge, or discard this patch.
src/Controllers/DevHealthController.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -12,25 +12,25 @@
 block discarded – undo
12 12
  */
13 13
 class DevHealthController extends Controller
14 14
 {
15
-    /**
16
-     * @var array
17
-     */
18
-    private static $allowed_actions = [
19
-        'index'
20
-    ];
15
+	/**
16
+	 * @var array
17
+	 */
18
+	private static $allowed_actions = [
19
+		'index'
20
+	];
21 21
 
22
-    /**
23
-     * @return EnvironmentChecker
24
-     *
25
-     * @throws HTTPResponse_Exception
26
-     */
27
-    public function index()
28
-    {
29
-        // health check does not require permission to run
22
+	/**
23
+	 * @return EnvironmentChecker
24
+	 *
25
+	 * @throws HTTPResponse_Exception
26
+	 */
27
+	public function index()
28
+	{
29
+		// health check does not require permission to run
30 30
 
31
-        $checker = new EnvironmentChecker('health', 'Site health');
32
-        $checker->setErrorCode(500);
31
+		$checker = new EnvironmentChecker('health', 'Site health');
32
+		$checker->setErrorCode(500);
33 33
 
34
-        return $checker;
35
-    }
34
+		return $checker;
35
+	}
36 36
 }
Please login to merge, or discard this patch.
src/Controllers/DevCheckController.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -12,38 +12,38 @@
 block discarded – undo
12 12
  */
13 13
 class DevCheckController extends Controller
14 14
 {
15
-    /**
16
-     * @var array
17
-     */
18
-    private static $allowed_actions = [
19
-        'index'
20
-    ];
21
-
22
-    /**
23
-     * Permission code to check for access to this controller.
24
-     *
25
-     * @var string
26
-     */
27
-    private static $permission = 'ADMIN';
28
-
29
-    /**
30
-     * @param HTTPRequest $request
31
-     *
32
-     * @return EnvironmentChecker
33
-     *
34
-     * @throws HTTPResponse_Exception
35
-     */
36
-    public function index($request)
37
-    {
38
-        $suite = 'check';
39
-
40
-        if ($name = $request->param('Suite')) {
41
-            $suite = $name;
42
-        }
43
-
44
-        $checker = new EnvironmentChecker($suite, 'Environment status');
45
-        $checker->init($this->config()->permission);
46
-
47
-        return $checker;
48
-    }
15
+	/**
16
+	 * @var array
17
+	 */
18
+	private static $allowed_actions = [
19
+		'index'
20
+	];
21
+
22
+	/**
23
+	 * Permission code to check for access to this controller.
24
+	 *
25
+	 * @var string
26
+	 */
27
+	private static $permission = 'ADMIN';
28
+
29
+	/**
30
+	 * @param HTTPRequest $request
31
+	 *
32
+	 * @return EnvironmentChecker
33
+	 *
34
+	 * @throws HTTPResponse_Exception
35
+	 */
36
+	public function index($request)
37
+	{
38
+		$suite = 'check';
39
+
40
+		if ($name = $request->param('Suite')) {
41
+			$suite = $name;
42
+		}
43
+
44
+		$checker = new EnvironmentChecker($suite, 'Environment status');
45
+		$checker->init($this->config()->permission);
46
+
47
+		return $checker;
48
+	}
49 49
 }
Please login to merge, or discard this patch.
src/EnvironmentCheckSuiteResult.php 1 patch
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -14,112 +14,112 @@
 block discarded – undo
14 14
  */
15 15
 class EnvironmentCheckSuiteResult extends ViewableData
16 16
 {
17
-    /**
18
-     * @var ArrayList
19
-     */
20
-    protected $details;
17
+	/**
18
+	 * @var ArrayList
19
+	 */
20
+	protected $details;
21 21
 
22
-    /**
23
-     * @var int
24
-     */
25
-    protected $worst = 0;
22
+	/**
23
+	 * @var int
24
+	 */
25
+	protected $worst = 0;
26 26
 
27
-    public function __construct()
28
-    {
29
-        parent::__construct();
30
-        $this->details = new ArrayList();
31
-    }
27
+	public function __construct()
28
+	{
29
+		parent::__construct();
30
+		$this->details = new ArrayList();
31
+	}
32 32
 
33
-    /**
34
-     * @param int $status
35
-     * @param string $message
36
-     * @param string $checkIdentifier
37
-     */
38
-    public function addResult($status, $message, $checkIdentifier)
39
-    {
40
-        $this->details->push(new ArrayData([
41
-            'Check' => $checkIdentifier,
42
-            'Status' => $this->statusText($status),
43
-            'StatusCode' => $status,
44
-            'Message' => $message,
45
-        ]));
33
+	/**
34
+	 * @param int $status
35
+	 * @param string $message
36
+	 * @param string $checkIdentifier
37
+	 */
38
+	public function addResult($status, $message, $checkIdentifier)
39
+	{
40
+		$this->details->push(new ArrayData([
41
+			'Check' => $checkIdentifier,
42
+			'Status' => $this->statusText($status),
43
+			'StatusCode' => $status,
44
+			'Message' => $message,
45
+		]));
46 46
 
47
-        $this->worst = max($this->worst, $status);
48
-    }
47
+		$this->worst = max($this->worst, $status);
48
+	}
49 49
 
50
-    /**
51
-     * Returns true if there are no errors.
52
-     *
53
-     * @return bool
54
-     */
55
-    public function ShouldPass()
56
-    {
57
-        return $this->worst <= EnvironmentCheck::WARNING;
58
-    }
50
+	/**
51
+	 * Returns true if there are no errors.
52
+	 *
53
+	 * @return bool
54
+	 */
55
+	public function ShouldPass()
56
+	{
57
+		return $this->worst <= EnvironmentCheck::WARNING;
58
+	}
59 59
 
60
-    /**
61
-     * Returns overall (i.e. worst) status as a string.
62
-     *
63
-     * @return string
64
-     */
65
-    public function Status()
66
-    {
67
-        return $this->statusText($this->worst);
68
-    }
60
+	/**
61
+	 * Returns overall (i.e. worst) status as a string.
62
+	 *
63
+	 * @return string
64
+	 */
65
+	public function Status()
66
+	{
67
+		return $this->statusText($this->worst);
68
+	}
69 69
 
70
-    /**
71
-     * Returns detailed status information about each check.
72
-     *
73
-     * @return ArrayList
74
-     */
75
-    public function Details()
76
-    {
77
-        return $this->details;
78
-    }
70
+	/**
71
+	 * Returns detailed status information about each check.
72
+	 *
73
+	 * @return ArrayList
74
+	 */
75
+	public function Details()
76
+	{
77
+		return $this->details;
78
+	}
79 79
 
80
-    /**
81
-     * Convert the final result status and details to JSON.
82
-     *
83
-     * @return string
84
-     */
85
-    public function toJSON()
86
-    {
87
-        $result = [
88
-            'Status' => $this->Status(),
89
-            'ShouldPass' => $this->ShouldPass(),
90
-            'Checks' => []
91
-        ];
92
-        foreach ($this->details as $detail) {
93
-            $result['Checks'][] = $detail->toMap();
94
-        }
95
-        return json_encode($result);
96
-    }
80
+	/**
81
+	 * Convert the final result status and details to JSON.
82
+	 *
83
+	 * @return string
84
+	 */
85
+	public function toJSON()
86
+	{
87
+		$result = [
88
+			'Status' => $this->Status(),
89
+			'ShouldPass' => $this->ShouldPass(),
90
+			'Checks' => []
91
+		];
92
+		foreach ($this->details as $detail) {
93
+			$result['Checks'][] = $detail->toMap();
94
+		}
95
+		return json_encode($result);
96
+	}
97 97
 
98
-    /**
99
-     * Return a text version of a status code.
100
-     *
101
-     * @param  int $status
102
-     * @return string
103
-     * @throws InvalidArgumentException
104
-     */
105
-    protected function statusText($status)
106
-    {
107
-        switch ($status) {
108
-            case EnvironmentCheck::ERROR:
109
-                return 'ERROR';
110
-                break;
111
-            case EnvironmentCheck::WARNING:
112
-                return 'WARNING';
113
-                break;
114
-            case EnvironmentCheck::OK:
115
-                return 'OK';
116
-                break;
117
-            case 0:
118
-                return 'NO CHECKS';
119
-                break;
120
-            default:
121
-                throw new InvalidArgumentException("Bad environment check status '$status'");
122
-                break;
123
-        }
124
-    }
98
+	/**
99
+	 * Return a text version of a status code.
100
+	 *
101
+	 * @param  int $status
102
+	 * @return string
103
+	 * @throws InvalidArgumentException
104
+	 */
105
+	protected function statusText($status)
106
+	{
107
+		switch ($status) {
108
+			case EnvironmentCheck::ERROR:
109
+				return 'ERROR';
110
+				break;
111
+			case EnvironmentCheck::WARNING:
112
+				return 'WARNING';
113
+				break;
114
+			case EnvironmentCheck::OK:
115
+				return 'OK';
116
+				break;
117
+			case 0:
118
+				return 'NO CHECKS';
119
+				break;
120
+			default:
121
+				throw new InvalidArgumentException("Bad environment check status '$status'");
122
+				break;
123
+		}
124
+	}
125 125
 }
Please login to merge, or discard this patch.
src/EnvironmentCheck.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -16,25 +16,25 @@
 block discarded – undo
16 16
  */
17 17
 interface EnvironmentCheck
18 18
 {
19
-    /**
20
-     * @var int
21
-     */
22
-    const ERROR = 3;
19
+	/**
20
+	 * @var int
21
+	 */
22
+	const ERROR = 3;
23 23
 
24
-    /**
25
-     * @var int
26
-     */
27
-    const WARNING = 2;
24
+	/**
25
+	 * @var int
26
+	 */
27
+	const WARNING = 2;
28 28
 
29
-    /**
30
-     * @var int
31
-     */
32
-    const OK = 1;
29
+	/**
30
+	 * @var int
31
+	 */
32
+	const OK = 1;
33 33
 
34
-    /**
35
-     * @return array Result with 'status' and 'message' keys.
36
-     *
37
-     * Status is EnvironmentCheck::ERROR, EnvironmentCheck::WARNING, or EnvironmentCheck::OK.
38
-     */
39
-    public function check();
34
+	/**
35
+	 * @return array Result with 'status' and 'message' keys.
36
+	 *
37
+	 * Status is EnvironmentCheck::ERROR, EnvironmentCheck::WARNING, or EnvironmentCheck::OK.
38
+	 */
39
+	public function check();
40 40
 }
Please login to merge, or discard this patch.
src/Checks/SMTPConnectCheck.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -13,67 +13,67 @@
 block discarded – undo
13 13
  */
14 14
 class SMTPConnectCheck implements EnvironmentCheck
15 15
 {
16
-    /**
17
-     * @var string
18
-     */
19
-    protected $host;
16
+	/**
17
+	 * @var string
18
+	 */
19
+	protected $host;
20 20
 
21
-    /**
22
-     * @var int
23
-     */
24
-    protected $port;
21
+	/**
22
+	 * @var int
23
+	 */
24
+	protected $port;
25 25
 
26
-    /**
27
-     * Timeout (in seconds).
28
-     *
29
-     * @var int
30
-     */
31
-    protected $timeout;
26
+	/**
27
+	 * Timeout (in seconds).
28
+	 *
29
+	 * @var int
30
+	 */
31
+	protected $timeout;
32 32
 
33
-    /**
34
-     * @param null|string $host
35
-     * @param null|int $port
36
-     * @param int $timeout
37
-     */
38
-    public function __construct($host = null, $port = null, $timeout = 15)
39
-    {
40
-        $this->host = ($host) ? $host : ini_get('SMTP');
41
-        if (!$this->host) {
42
-            $this->host = 'localhost';
43
-        }
33
+	/**
34
+	 * @param null|string $host
35
+	 * @param null|int $port
36
+	 * @param int $timeout
37
+	 */
38
+	public function __construct($host = null, $port = null, $timeout = 15)
39
+	{
40
+		$this->host = ($host) ? $host : ini_get('SMTP');
41
+		if (!$this->host) {
42
+			$this->host = 'localhost';
43
+		}
44 44
 
45
-        $this->port = ($port) ? $port : ini_get('smtp_port');
46
-        if (!$this->port) {
47
-            $this->port = 25;
48
-        }
45
+		$this->port = ($port) ? $port : ini_get('smtp_port');
46
+		if (!$this->port) {
47
+			$this->port = 25;
48
+		}
49 49
 
50
-        $this->timeout = $timeout;
51
-    }
50
+		$this->timeout = $timeout;
51
+	}
52 52
 
53
-    /**
54
-     * {@inheritDoc}
55
-     *
56
-     * @return array
57
-     */
58
-    public function check()
59
-    {
60
-        $f = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
61
-        if (!$f) {
62
-            return [
63
-                EnvironmentCheck::ERROR,
64
-                sprintf("Couldn't connect to SMTP on %s:%s (Error: %s %s)", $this->host, $this->port, $errno, $errstr)
65
-            ];
66
-        }
53
+	/**
54
+	 * {@inheritDoc}
55
+	 *
56
+	 * @return array
57
+	 */
58
+	public function check()
59
+	{
60
+		$f = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
61
+		if (!$f) {
62
+			return [
63
+				EnvironmentCheck::ERROR,
64
+				sprintf("Couldn't connect to SMTP on %s:%s (Error: %s %s)", $this->host, $this->port, $errno, $errstr)
65
+			];
66
+		}
67 67
 
68
-        fwrite($f, "HELO its_me\r\n");
69
-        $response = fread($f, 26);
70
-        if (substr($response, 0, 3) != '220') {
71
-            return [
72
-                EnvironmentCheck::ERROR,
73
-                sprintf('Invalid mail server response: %s', $response)
74
-            ];
75
-        }
68
+		fwrite($f, "HELO its_me\r\n");
69
+		$response = fread($f, 26);
70
+		if (substr($response, 0, 3) != '220') {
71
+			return [
72
+				EnvironmentCheck::ERROR,
73
+				sprintf('Invalid mail server response: %s', $response)
74
+			];
75
+		}
76 76
 
77
-        return [EnvironmentCheck::OK, ''];
78
-    }
77
+		return [EnvironmentCheck::OK, ''];
78
+	}
79 79
 }
Please login to merge, or discard this patch.
src/Checks/DatabaseCheck.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -13,38 +13,38 @@
 block discarded – undo
13 13
  */
14 14
 class DatabaseCheck implements EnvironmentCheck
15 15
 {
16
-    /**
17
-     * @var string
18
-     */
19
-    protected $checkTable;
20
-
21
-    /**
22
-     * By default, Member will be checked.
23
-     *
24
-     * @param string $checkTable
25
-     */
26
-    public function __construct($checkTable = 'Member')
27
-    {
28
-        $this->checkTable = $checkTable;
29
-    }
30
-
31
-    /**
32
-     * {@inheritDoc}
33
-     *
34
-     * @return array
35
-     */
36
-    public function check()
37
-    {
38
-        if (!DB::get_schema()->hasTable($this->checkTable)) {
39
-            return [EnvironmentCheck::ERROR, "$this->checkTable not present in the database"];
40
-        }
41
-
42
-        $count = DB::query("SELECT COUNT(*) FROM \"$this->checkTable\"")->value();
43
-
44
-        if ($count > 0) {
45
-            return [EnvironmentCheck::OK, ''];
46
-        }
47
-
48
-        return [EnvironmentCheck::WARNING, "$this->checkTable queried ok but has no records"];
49
-    }
16
+	/**
17
+	 * @var string
18
+	 */
19
+	protected $checkTable;
20
+
21
+	/**
22
+	 * By default, Member will be checked.
23
+	 *
24
+	 * @param string $checkTable
25
+	 */
26
+	public function __construct($checkTable = 'Member')
27
+	{
28
+		$this->checkTable = $checkTable;
29
+	}
30
+
31
+	/**
32
+	 * {@inheritDoc}
33
+	 *
34
+	 * @return array
35
+	 */
36
+	public function check()
37
+	{
38
+		if (!DB::get_schema()->hasTable($this->checkTable)) {
39
+			return [EnvironmentCheck::ERROR, "$this->checkTable not present in the database"];
40
+		}
41
+
42
+		$count = DB::query("SELECT COUNT(*) FROM \"$this->checkTable\"")->value();
43
+
44
+		if ($count > 0) {
45
+			return [EnvironmentCheck::OK, ''];
46
+		}
47
+
48
+		return [EnvironmentCheck::WARNING, "$this->checkTable queried ok but has no records"];
49
+	}
50 50
 }
Please login to merge, or discard this patch.
src/Checks/HasFunctionCheck.php 2 patches
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -11,29 +11,29 @@
 block discarded – undo
11 11
  */
12 12
 class HasFunctionCheck implements EnvironmentCheck
13 13
 {
14
-    /**
15
-     * @var string
16
-     */
17
-    protected $functionName;
14
+	/**
15
+	 * @var string
16
+	 */
17
+	protected $functionName;
18 18
 
19
-    /**
20
-     * @param string $functionName The name of the function to look for.
21
-     */
22
-    public function __construct($functionName)
23
-    {
24
-        $this->functionName = $functionName;
25
-    }
19
+	/**
20
+	 * @param string $functionName The name of the function to look for.
21
+	 */
22
+	public function __construct($functionName)
23
+	{
24
+		$this->functionName = $functionName;
25
+	}
26 26
 
27
-    /**
28
-     * {@inheritDoc}
29
-     *
30
-     * @return array
31
-     */
32
-    public function check()
33
-    {
34
-        if (function_exists($this->functionName)) {
35
-            return [EnvironmentCheck::OK, $this->functionName . '() exists'];
36
-        }
37
-        return [EnvironmentCheck::ERROR, $this->functionName . '() doesn\'t exist'];
38
-    }
27
+	/**
28
+	 * {@inheritDoc}
29
+	 *
30
+	 * @return array
31
+	 */
32
+	public function check()
33
+	{
34
+		if (function_exists($this->functionName)) {
35
+			return [EnvironmentCheck::OK, $this->functionName . '() exists'];
36
+		}
37
+		return [EnvironmentCheck::ERROR, $this->functionName . '() doesn\'t exist'];
38
+	}
39 39
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@
 block discarded – undo
32 32
     public function check()
33 33
     {
34 34
         if (function_exists($this->functionName)) {
35
-            return [EnvironmentCheck::OK, $this->functionName . '() exists'];
35
+            return [EnvironmentCheck::OK, $this->functionName.'() exists'];
36 36
         }
37
-        return [EnvironmentCheck::ERROR, $this->functionName . '() doesn\'t exist'];
37
+        return [EnvironmentCheck::ERROR, $this->functionName.'() doesn\'t exist'];
38 38
     }
39 39
 }
Please login to merge, or discard this patch.
src/Checks/FileAccessibilityAndValidationCheck.php 2 patches
Indentation   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -28,170 +28,170 @@
 block discarded – undo
28 28
  */
29 29
 class FileAccessibilityAndValidationCheck implements EnvironmentCheck
30 30
 {
31
-    /**
32
-     * @var int
33
-     */
34
-    const CHECK_SINGLE = 1;
35
-
36
-    /**
37
-     * @var int
38
-     */
39
-    const CHECK_ALL = 2;
40
-
41
-    /**
42
-     * Absolute path to a file or folder, compatible with glob().
43
-     *
44
-     * @var string
45
-     */
46
-    protected $path;
47
-
48
-    /**
49
-     * Constant, check for a single file to match age criteria, or all of them.
50
-     *
51
-     * @var int
52
-     */
53
-    protected $fileTypeValidateFunc;
54
-
55
-    /**
56
-     * Constant, check for a single file to match age criteria, or all of them.
57
-     *
58
-     * @var int
59
-     */
60
-    protected $checkType;
61
-
62
-    /**
63
-     * @param string $path
64
-     * @param string $fileTypeValidateFunc
65
-     * @param null|int $checkType
66
-     */
67
-    public function __construct($path, $fileTypeValidateFunc = 'noVidation', $checkType = null)
68
-    {
69
-        $this->path = $path;
70
-        $this->fileTypeValidateFunc = ($fileTypeValidateFunc)? $fileTypeValidateFunc : 'noVidation';
71
-        $this->checkType = ($checkType) ? $checkType : self::CHECK_SINGLE;
72
-    }
73
-
74
-    /**
75
-     * {@inheritDoc}
76
-     *
77
-     * @return array
78
-     */
79
-    public function check()
80
-    {
81
-        $origStage = Versioned::get_reading_mode();
82
-        Versioned::set_reading_mode(Versioned::LIVE);
83
-
84
-        $files = $this->getFiles();
85
-        if ($files) {
86
-            $fileTypeValidateFunc = $this->fileTypeValidateFunc;
87
-            if (method_exists($this, $fileTypeValidateFunc)) {
88
-                $invalidFiles = [];
89
-                $validFiles = [];
90
-
91
-                foreach ($files as $file) {
92
-                    if ($this->$fileTypeValidateFunc($file)) {
93
-                        $validFiles[] = $file;
94
-                    } else {
95
-                        $invalidFiles[] = $file;
96
-                    }
97
-                }
98
-
99
-                // If at least one file was valid, count as passed
100
-                if ($this->checkType == self::CHECK_SINGLE && count($invalidFiles) < count($files)) {
101
-                    $validFileList = PHP_EOL;
102
-                    foreach ($validFiles as $vf) {
103
-                        $validFileList .= $vf . PHP_EOL;
104
-                    }
105
-                    if ($fileTypeValidateFunc == 'noVidation') {
106
-                        $checkReturn = [
107
-                            EnvironmentCheck::OK,
108
-                            sprintf('At least these file(s) accessible: %s', $validFileList)
109
-                        ];
110
-                    } else {
111
-                        $checkReturn = [
112
-                            EnvironmentCheck::OK,
113
-                            sprintf(
114
-                                'At least these file(s) passed file type validate function "%s": %s',
115
-                                $fileTypeValidateFunc,
116
-                                $validFileList
117
-                            )
118
-                        ];
119
-                    }
120
-                } else {
121
-                    if (count($invalidFiles) == 0) {
122
-                        $checkReturn = [EnvironmentCheck::OK, 'All files valideted'];
123
-                    } else {
124
-                        $invalidFileList = PHP_EOL;
125
-                        foreach ($invalidFiles as $vf) {
126
-                            $invalidFileList .= $vf . PHP_EOL;
127
-                        }
128
-
129
-                        if ($fileTypeValidateFunc == 'noVidation') {
130
-                            $checkReturn = [
131
-                                EnvironmentCheck::ERROR,
132
-                                sprintf('File(s) not accessible: %s', $invalidFileList)
133
-                            ];
134
-                        } else {
135
-                            $checkReturn = [
136
-                                EnvironmentCheck::ERROR,
137
-                                sprintf(
138
-                                    'File(s) not passing the file type validate function "%s": %s',
139
-                                    $fileTypeValidateFunc,
140
-                                    $invalidFileList
141
-                                )
142
-                            ];
143
-                        }
144
-                    }
145
-                }
146
-            } else {
147
-                $checkReturn =  array(
148
-                    EnvironmentCheck::ERROR,
149
-                    sprintf("Invalid file type validation method name passed: %s ", $fileTypeValidateFunc)
150
-                );
151
-            }
152
-        } else {
153
-            $checkReturn = array(
154
-                EnvironmentCheck::ERROR,
155
-                sprintf("No files accessible at path %s", $this->path)
156
-            );
157
-        }
158
-
159
-        Versioned::set_reading_mode($origStage);
160
-
161
-        return $checkReturn;
162
-    }
163
-
164
-    /**
165
-     * @param string $file
166
-     *
167
-     * @return bool
168
-     */
169
-    private function jsonValidate($file)
170
-    {
171
-        $json = json_decode(file_get_contents($file));
172
-        if (!$json) {
173
-            return false;
174
-        }
175
-        return true;
176
-    }
177
-
178
-    /**
179
-     * @param string $file
180
-     *
181
-     * @return bool
182
-     */
183
-    protected function noVidation($file)
184
-    {
185
-        return true;
186
-    }
187
-
188
-    /**
189
-     * Gets a list of absolute file paths.
190
-     *
191
-     * @return array
192
-     */
193
-    protected function getFiles()
194
-    {
195
-        return glob($this->path);
196
-    }
31
+	/**
32
+	 * @var int
33
+	 */
34
+	const CHECK_SINGLE = 1;
35
+
36
+	/**
37
+	 * @var int
38
+	 */
39
+	const CHECK_ALL = 2;
40
+
41
+	/**
42
+	 * Absolute path to a file or folder, compatible with glob().
43
+	 *
44
+	 * @var string
45
+	 */
46
+	protected $path;
47
+
48
+	/**
49
+	 * Constant, check for a single file to match age criteria, or all of them.
50
+	 *
51
+	 * @var int
52
+	 */
53
+	protected $fileTypeValidateFunc;
54
+
55
+	/**
56
+	 * Constant, check for a single file to match age criteria, or all of them.
57
+	 *
58
+	 * @var int
59
+	 */
60
+	protected $checkType;
61
+
62
+	/**
63
+	 * @param string $path
64
+	 * @param string $fileTypeValidateFunc
65
+	 * @param null|int $checkType
66
+	 */
67
+	public function __construct($path, $fileTypeValidateFunc = 'noVidation', $checkType = null)
68
+	{
69
+		$this->path = $path;
70
+		$this->fileTypeValidateFunc = ($fileTypeValidateFunc)? $fileTypeValidateFunc : 'noVidation';
71
+		$this->checkType = ($checkType) ? $checkType : self::CHECK_SINGLE;
72
+	}
73
+
74
+	/**
75
+	 * {@inheritDoc}
76
+	 *
77
+	 * @return array
78
+	 */
79
+	public function check()
80
+	{
81
+		$origStage = Versioned::get_reading_mode();
82
+		Versioned::set_reading_mode(Versioned::LIVE);
83
+
84
+		$files = $this->getFiles();
85
+		if ($files) {
86
+			$fileTypeValidateFunc = $this->fileTypeValidateFunc;
87
+			if (method_exists($this, $fileTypeValidateFunc)) {
88
+				$invalidFiles = [];
89
+				$validFiles = [];
90
+
91
+				foreach ($files as $file) {
92
+					if ($this->$fileTypeValidateFunc($file)) {
93
+						$validFiles[] = $file;
94
+					} else {
95
+						$invalidFiles[] = $file;
96
+					}
97
+				}
98
+
99
+				// If at least one file was valid, count as passed
100
+				if ($this->checkType == self::CHECK_SINGLE && count($invalidFiles) < count($files)) {
101
+					$validFileList = PHP_EOL;
102
+					foreach ($validFiles as $vf) {
103
+						$validFileList .= $vf . PHP_EOL;
104
+					}
105
+					if ($fileTypeValidateFunc == 'noVidation') {
106
+						$checkReturn = [
107
+							EnvironmentCheck::OK,
108
+							sprintf('At least these file(s) accessible: %s', $validFileList)
109
+						];
110
+					} else {
111
+						$checkReturn = [
112
+							EnvironmentCheck::OK,
113
+							sprintf(
114
+								'At least these file(s) passed file type validate function "%s": %s',
115
+								$fileTypeValidateFunc,
116
+								$validFileList
117
+							)
118
+						];
119
+					}
120
+				} else {
121
+					if (count($invalidFiles) == 0) {
122
+						$checkReturn = [EnvironmentCheck::OK, 'All files valideted'];
123
+					} else {
124
+						$invalidFileList = PHP_EOL;
125
+						foreach ($invalidFiles as $vf) {
126
+							$invalidFileList .= $vf . PHP_EOL;
127
+						}
128
+
129
+						if ($fileTypeValidateFunc == 'noVidation') {
130
+							$checkReturn = [
131
+								EnvironmentCheck::ERROR,
132
+								sprintf('File(s) not accessible: %s', $invalidFileList)
133
+							];
134
+						} else {
135
+							$checkReturn = [
136
+								EnvironmentCheck::ERROR,
137
+								sprintf(
138
+									'File(s) not passing the file type validate function "%s": %s',
139
+									$fileTypeValidateFunc,
140
+									$invalidFileList
141
+								)
142
+							];
143
+						}
144
+					}
145
+				}
146
+			} else {
147
+				$checkReturn =  array(
148
+					EnvironmentCheck::ERROR,
149
+					sprintf("Invalid file type validation method name passed: %s ", $fileTypeValidateFunc)
150
+				);
151
+			}
152
+		} else {
153
+			$checkReturn = array(
154
+				EnvironmentCheck::ERROR,
155
+				sprintf("No files accessible at path %s", $this->path)
156
+			);
157
+		}
158
+
159
+		Versioned::set_reading_mode($origStage);
160
+
161
+		return $checkReturn;
162
+	}
163
+
164
+	/**
165
+	 * @param string $file
166
+	 *
167
+	 * @return bool
168
+	 */
169
+	private function jsonValidate($file)
170
+	{
171
+		$json = json_decode(file_get_contents($file));
172
+		if (!$json) {
173
+			return false;
174
+		}
175
+		return true;
176
+	}
177
+
178
+	/**
179
+	 * @param string $file
180
+	 *
181
+	 * @return bool
182
+	 */
183
+	protected function noVidation($file)
184
+	{
185
+		return true;
186
+	}
187
+
188
+	/**
189
+	 * Gets a list of absolute file paths.
190
+	 *
191
+	 * @return array
192
+	 */
193
+	protected function getFiles()
194
+	{
195
+		return glob($this->path);
196
+	}
197 197
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
     public function __construct($path, $fileTypeValidateFunc = 'noVidation', $checkType = null)
68 68
     {
69 69
         $this->path = $path;
70
-        $this->fileTypeValidateFunc = ($fileTypeValidateFunc)? $fileTypeValidateFunc : 'noVidation';
70
+        $this->fileTypeValidateFunc = ($fileTypeValidateFunc) ? $fileTypeValidateFunc : 'noVidation';
71 71
         $this->checkType = ($checkType) ? $checkType : self::CHECK_SINGLE;
72 72
     }
73 73
 
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
                 if ($this->checkType == self::CHECK_SINGLE && count($invalidFiles) < count($files)) {
101 101
                     $validFileList = PHP_EOL;
102 102
                     foreach ($validFiles as $vf) {
103
-                        $validFileList .= $vf . PHP_EOL;
103
+                        $validFileList .= $vf.PHP_EOL;
104 104
                     }
105 105
                     if ($fileTypeValidateFunc == 'noVidation') {
106 106
                         $checkReturn = [
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
                     } else {
124 124
                         $invalidFileList = PHP_EOL;
125 125
                         foreach ($invalidFiles as $vf) {
126
-                            $invalidFileList .= $vf . PHP_EOL;
126
+                            $invalidFileList .= $vf.PHP_EOL;
127 127
                         }
128 128
 
129 129
                         if ($fileTypeValidateFunc == 'noVidation') {
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
                     }
145 145
                 }
146 146
             } else {
147
-                $checkReturn =  array(
147
+                $checkReturn = array(
148 148
                     EnvironmentCheck::ERROR,
149 149
                     sprintf("Invalid file type validation method name passed: %s ", $fileTypeValidateFunc)
150 150
                 );
Please login to merge, or discard this patch.