Completed
Push — master ( e090e4...18d79e )
by Damian
02:26
created
code/checks/SMTPConnectCheck.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
47 47
     /**
48 48
      * @inheritdoc
49 49
      *
50
-     * @return array
50
+     * @return string[]
51 51
      */
52 52
     public function check()
53 53
     {
Please login to merge, or discard this patch.
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -7,67 +7,67 @@
 block discarded – undo
7 7
  */
8 8
 class SMTPConnectCheck implements EnvironmentCheck
9 9
 {
10
-    /**
11
-     * @var string
12
-     */
13
-    protected $host;
10
+	/**
11
+	 * @var string
12
+	 */
13
+	protected $host;
14 14
 
15
-    /**
16
-     * @var int
17
-     */
18
-    protected $port;
15
+	/**
16
+	 * @var int
17
+	 */
18
+	protected $port;
19 19
 
20
-    /**
21
-     * Timeout (in seconds).
22
-     *
23
-     * @var int
24
-     */
25
-    protected $timeout;
20
+	/**
21
+	 * Timeout (in seconds).
22
+	 *
23
+	 * @var int
24
+	 */
25
+	protected $timeout;
26 26
 
27
-    /**
28
-     * @param null|string $host
29
-     * @param null|int $port
30
-     * @param int $timeout
31
-     */
32
-    public function __construct($host = null, $port = null, $timeout = 15)
33
-    {
34
-        $this->host = ($host) ? $host : ini_get('SMTP');
35
-        if (!$this->host) {
36
-            $this->host = 'localhost';
37
-        }
27
+	/**
28
+	 * @param null|string $host
29
+	 * @param null|int $port
30
+	 * @param int $timeout
31
+	 */
32
+	public function __construct($host = null, $port = null, $timeout = 15)
33
+	{
34
+		$this->host = ($host) ? $host : ini_get('SMTP');
35
+		if (!$this->host) {
36
+			$this->host = 'localhost';
37
+		}
38 38
         
39
-        $this->port = ($port) ? $port : ini_get('smtp_port');
40
-        if (!$this->port) {
41
-            $this->port = 25;
42
-        }
39
+		$this->port = ($port) ? $port : ini_get('smtp_port');
40
+		if (!$this->port) {
41
+			$this->port = 25;
42
+		}
43 43
 
44
-        $this->timeout = $timeout;
45
-    }
44
+		$this->timeout = $timeout;
45
+	}
46 46
 
47
-    /**
48
-     * @inheritdoc
49
-     *
50
-     * @return array
51
-     */
52
-    public function check()
53
-    {
54
-        $f = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
55
-        if (!$f) {
56
-            return array(
57
-                EnvironmentCheck::ERROR,
58
-                sprintf("Couldn't connect to SMTP on %s:%s (Error: %s %s)", $this->host, $this->port, $errno, $errstr)
59
-            );
60
-        }
47
+	/**
48
+	 * @inheritdoc
49
+	 *
50
+	 * @return array
51
+	 */
52
+	public function check()
53
+	{
54
+		$f = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
55
+		if (!$f) {
56
+			return array(
57
+				EnvironmentCheck::ERROR,
58
+				sprintf("Couldn't connect to SMTP on %s:%s (Error: %s %s)", $this->host, $this->port, $errno, $errstr)
59
+			);
60
+		}
61 61
 
62
-        fwrite($f, "HELO its_me\r\n");
63
-        $response = fread($f, 26);
64
-        if (substr($response, 0, 3) != '220') {
65
-            return array(
66
-                EnvironmentCheck::ERROR,
67
-                sprintf("Invalid mail server response: %s", $response)
68
-            );
69
-        }
62
+		fwrite($f, "HELO its_me\r\n");
63
+		$response = fread($f, 26);
64
+		if (substr($response, 0, 3) != '220') {
65
+			return array(
66
+				EnvironmentCheck::ERROR,
67
+				sprintf("Invalid mail server response: %s", $response)
68
+			);
69
+		}
70 70
 
71
-        return array(EnvironmentCheck::OK, '');
72
-    }
71
+		return array(EnvironmentCheck::OK, '');
72
+	}
73 73
 }
Please login to merge, or discard this patch.
code/EnvironmentCheckSuite.php 3 patches
Doc Comments   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
     /**
90 90
      * Run this test suite and return the result code of the worst result.
91 91
      *
92
-     * @return int
92
+     * @return EnvironmentCheckSuiteResult
93 93
      */
94 94
     public function run()
95 95
     {
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
     /**
176 176
      * Register a check against the named check suite.
177 177
      *
178
-     * @param string|array $names
178
+     * @param string $names
179 179
      * @param EnvironmentCheck $check
180 180
      * @param string|array
181 181
      */
@@ -287,6 +287,7 @@  discard block
 block discarded – undo
287 287
     /**
288 288
      * Return a text version of a status code.
289 289
      *
290
+     * @param integer $status
290 291
      * @return string
291 292
      */
292 293
     protected function statusText($status)
Please login to merge, or discard this patch.
Indentation   +243 added lines, -243 removed lines patch added patch discarded remove patch
@@ -21,181 +21,181 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class EnvironmentCheckSuite extends Object
23 23
 {
24
-    /**
25
-     * Name of this suite.
26
-     *
27
-     * @var string
28
-     */
29
-    protected $name;
24
+	/**
25
+	 * Name of this suite.
26
+	 *
27
+	 * @var string
28
+	 */
29
+	protected $name;
30 30
 
31
-    /**
32
-     * @var array
33
-     */
34
-    protected $checks = array();
31
+	/**
32
+	 * @var array
33
+	 */
34
+	protected $checks = array();
35 35
 
36
-    /**
37
-     * Associative array of named checks registered via the config system. Each check should specify:
38
-     * - definition (e.g. 'MyHealthCheck("my param")')
39
-     * - title (e.g. 'Is my feature working?')
40
-     * - state (setting this to 'disabled' will cause suites to skip this check entirely.
41
-     *
42
-     * @var array
43
-     */
44
-    private static $registered_checks = array();
36
+	/**
37
+	 * Associative array of named checks registered via the config system. Each check should specify:
38
+	 * - definition (e.g. 'MyHealthCheck("my param")')
39
+	 * - title (e.g. 'Is my feature working?')
40
+	 * - state (setting this to 'disabled' will cause suites to skip this check entirely.
41
+	 *
42
+	 * @var array
43
+	 */
44
+	private static $registered_checks = array();
45 45
 
46
-    /**
47
-     * Associative array of named suites registered via the config system. Each suite should enumerate
48
-     * named checks that have been configured in 'registered_checks'.
49
-     *
50
-     * @var array
51
-     */
52
-    private static $registered_suites = array();
46
+	/**
47
+	 * Associative array of named suites registered via the config system. Each suite should enumerate
48
+	 * named checks that have been configured in 'registered_checks'.
49
+	 *
50
+	 * @var array
51
+	 */
52
+	private static $registered_suites = array();
53 53
 
54
-    /**
55
-     * Load checks for this suite from the configuration system. This is an alternative to the
56
-     * EnvironmentCheckSuite::register - both can be used, checks will be appended to the suite.
57
-     *
58
-     * @param string $suiteName The name of this suite.
59
-     */
60
-    public function __construct($suiteName)
61
-    {
62
-        parent::__construct();
54
+	/**
55
+	 * Load checks for this suite from the configuration system. This is an alternative to the
56
+	 * EnvironmentCheckSuite::register - both can be used, checks will be appended to the suite.
57
+	 *
58
+	 * @param string $suiteName The name of this suite.
59
+	 */
60
+	public function __construct($suiteName)
61
+	{
62
+		parent::__construct();
63 63
 
64
-        if (empty($this->config()->registered_suites[$suiteName])) {
65
-            // Not registered via config system, but it still may be configured later via self::register.
66
-            return;
67
-        }
64
+		if (empty($this->config()->registered_suites[$suiteName])) {
65
+			// Not registered via config system, but it still may be configured later via self::register.
66
+			return;
67
+		}
68 68
 
69
-        foreach ($this->config()->registered_suites[$suiteName] as $checkName) {
70
-            if (empty($this->config()->registered_checks[$checkName])) {
71
-                throw new InvalidArgumentException(
72
-                    "Bad EnvironmentCheck: '$checkName' - the named check has not been registered."
73
-                );
74
-            }
69
+		foreach ($this->config()->registered_suites[$suiteName] as $checkName) {
70
+			if (empty($this->config()->registered_checks[$checkName])) {
71
+				throw new InvalidArgumentException(
72
+					"Bad EnvironmentCheck: '$checkName' - the named check has not been registered."
73
+				);
74
+			}
75 75
 
76
-            $check = $this->config()->registered_checks[$checkName];
76
+			$check = $this->config()->registered_checks[$checkName];
77 77
 
78
-            // Existing named checks can be disabled by setting their 'state' to 'disabled'.
79
-            // This is handy for disabling checks mandated by modules.
80
-            if (!empty($check['state']) && $check['state']==='disabled') {
81
-                continue;
82
-            }
78
+			// Existing named checks can be disabled by setting their 'state' to 'disabled'.
79
+			// This is handy for disabling checks mandated by modules.
80
+			if (!empty($check['state']) && $check['state']==='disabled') {
81
+				continue;
82
+			}
83 83
             
84
-            // Add the check to this suite.
85
-            $this->push($check['definition'], $check['title']);
86
-        }
87
-    }
84
+			// Add the check to this suite.
85
+			$this->push($check['definition'], $check['title']);
86
+		}
87
+	}
88 88
 
89
-    /**
90
-     * Run this test suite and return the result code of the worst result.
91
-     *
92
-     * @return int
93
-     */
94
-    public function run()
95
-    {
96
-        $result = new EnvironmentCheckSuiteResult();
89
+	/**
90
+	 * Run this test suite and return the result code of the worst result.
91
+	 *
92
+	 * @return int
93
+	 */
94
+	public function run()
95
+	{
96
+		$result = new EnvironmentCheckSuiteResult();
97 97
 
98
-        foreach ($this->checkInstances() as $check) {
99
-            list($checkClass, $checkTitle) = $check;
100
-            try {
101
-                list($status, $message) = $checkClass->check();
102
-            // If the check fails, register that as an error
103
-            } catch (Exception $e) {
104
-                $status = EnvironmentCheck::ERROR;
105
-                $message = $e->getMessage();
106
-            }
107
-            $result->addResult($status, $message, $checkTitle);
108
-        }
98
+		foreach ($this->checkInstances() as $check) {
99
+			list($checkClass, $checkTitle) = $check;
100
+			try {
101
+				list($status, $message) = $checkClass->check();
102
+			// If the check fails, register that as an error
103
+			} catch (Exception $e) {
104
+				$status = EnvironmentCheck::ERROR;
105
+				$message = $e->getMessage();
106
+			}
107
+			$result->addResult($status, $message, $checkTitle);
108
+		}
109 109
 
110
-        return $result;
111
-    }
110
+		return $result;
111
+	}
112 112
 
113
-    /**
114
-     * Get instances of all the environment checks.
115
-     *
116
-     * @return array
117
-     */
118
-    protected function checkInstances()
119
-    {
120
-        $output = array();
121
-        foreach ($this->checks as $check) {
122
-            list($checkClass, $checkTitle) = $check;
123
-            if (is_string($checkClass)) {
124
-                $checkInst = Object::create_from_string($checkClass);
125
-                if ($checkInst instanceof EnvironmentCheck) {
126
-                    $output[] = array($checkInst, $checkTitle);
127
-                } else {
128
-                    throw new InvalidArgumentException("Bad EnvironmentCheck: '$checkClass' - the named class doesn't implement EnvironmentCheck");
129
-                }
130
-            } elseif ($checkClass instanceof EnvironmentCheck) {
131
-                $output[] = array($checkClass, $checkTitle);
132
-            } else {
133
-                throw new InvalidArgumentException("Bad EnvironmentCheck: " . var_export($check, true));
134
-            }
135
-        }
136
-        return $output;
137
-    }
113
+	/**
114
+	 * Get instances of all the environment checks.
115
+	 *
116
+	 * @return array
117
+	 */
118
+	protected function checkInstances()
119
+	{
120
+		$output = array();
121
+		foreach ($this->checks as $check) {
122
+			list($checkClass, $checkTitle) = $check;
123
+			if (is_string($checkClass)) {
124
+				$checkInst = Object::create_from_string($checkClass);
125
+				if ($checkInst instanceof EnvironmentCheck) {
126
+					$output[] = array($checkInst, $checkTitle);
127
+				} else {
128
+					throw new InvalidArgumentException("Bad EnvironmentCheck: '$checkClass' - the named class doesn't implement EnvironmentCheck");
129
+				}
130
+			} elseif ($checkClass instanceof EnvironmentCheck) {
131
+				$output[] = array($checkClass, $checkTitle);
132
+			} else {
133
+				throw new InvalidArgumentException("Bad EnvironmentCheck: " . var_export($check, true));
134
+			}
135
+		}
136
+		return $output;
137
+	}
138 138
 
139
-    /**
140
-     * Add a check to this suite.
141
-     *
142
-     * @param mixed $check
143
-     * @param string $title
144
-     */
145
-    public function push($check, $title = null)
146
-    {
147
-        if (!$title) {
148
-            $title = is_string($check) ? $check : get_class($check);
149
-        }
150
-        $this->checks[] = array($check, $title);
151
-    }
139
+	/**
140
+	 * Add a check to this suite.
141
+	 *
142
+	 * @param mixed $check
143
+	 * @param string $title
144
+	 */
145
+	public function push($check, $title = null)
146
+	{
147
+		if (!$title) {
148
+			$title = is_string($check) ? $check : get_class($check);
149
+		}
150
+		$this->checks[] = array($check, $title);
151
+	}
152 152
 
153
-    /////////////////////////////////////////////////////////////////////////////////////////////
153
+	/////////////////////////////////////////////////////////////////////////////////////////////
154 154
 
155
-    /**
156
-     * @var array
157
-     */
158
-    protected static $instances = array();
155
+	/**
156
+	 * @var array
157
+	 */
158
+	protected static $instances = array();
159 159
 
160
-    /**
161
-     * Return a named instance of EnvironmentCheckSuite.
162
-     *
163
-     * @param string $name
164
-     *
165
-     * @return EnvironmentCheckSuite
166
-     */
167
-    public static function inst($name)
168
-    {
169
-        if (!isset(self::$instances[$name])) {
170
-            self::$instances[$name] = new EnvironmentCheckSuite($name);
171
-        }
172
-        return self::$instances[$name];
173
-    }
160
+	/**
161
+	 * Return a named instance of EnvironmentCheckSuite.
162
+	 *
163
+	 * @param string $name
164
+	 *
165
+	 * @return EnvironmentCheckSuite
166
+	 */
167
+	public static function inst($name)
168
+	{
169
+		if (!isset(self::$instances[$name])) {
170
+			self::$instances[$name] = new EnvironmentCheckSuite($name);
171
+		}
172
+		return self::$instances[$name];
173
+	}
174 174
 
175
-    /**
176
-     * Register a check against the named check suite.
177
-     *
178
-     * @param string|array $names
179
-     * @param EnvironmentCheck $check
180
-     * @param string|array
181
-     */
182
-    public static function register($names, $check, $title = null)
183
-    {
184
-        if (!is_array($names)) {
185
-            $names = array($names);
186
-        }
187
-        foreach ($names as $name) {
188
-            self::inst($name)->push($check, $title);
189
-        }
190
-    }
175
+	/**
176
+	 * Register a check against the named check suite.
177
+	 *
178
+	 * @param string|array $names
179
+	 * @param EnvironmentCheck $check
180
+	 * @param string|array
181
+	 */
182
+	public static function register($names, $check, $title = null)
183
+	{
184
+		if (!is_array($names)) {
185
+			$names = array($names);
186
+		}
187
+		foreach ($names as $name) {
188
+			self::inst($name)->push($check, $title);
189
+		}
190
+	}
191 191
 
192
-    /**
193
-     * Unregisters all checks.
194
-     */
195
-    public static function reset()
196
-    {
197
-        self::$instances = array();
198
-    }
192
+	/**
193
+	 * Unregisters all checks.
194
+	 */
195
+	public static function reset()
196
+	{
197
+		self::$instances = array();
198
+	}
199 199
 }
200 200
 
201 201
 /**
@@ -203,100 +203,100 @@  discard block
 block discarded – undo
203 203
  */
204 204
 class EnvironmentCheckSuiteResult extends ViewableData
205 205
 {
206
-    /**
207
-     * @var ArrayList
208
-     */
209
-    protected $details;
206
+	/**
207
+	 * @var ArrayList
208
+	 */
209
+	protected $details;
210 210
 
211
-    /**
212
-     * @var int
213
-     */
214
-    protected $worst = 0;
211
+	/**
212
+	 * @var int
213
+	 */
214
+	protected $worst = 0;
215 215
 
216
-    public function __construct()
217
-    {
218
-        parent::__construct();
219
-        $this->details = new ArrayList();
220
-    }
216
+	public function __construct()
217
+	{
218
+		parent::__construct();
219
+		$this->details = new ArrayList();
220
+	}
221 221
 
222
-    /**
223
-     * @param int $status
224
-     * @param string $message
225
-     * @param string $checkIdentifier
226
-     */
227
-    public function addResult($status, $message, $checkIdentifier)
228
-    {
229
-        $this->details->push(new ArrayData(array(
230
-            'Check' => $checkIdentifier,
231
-            'Status' => $this->statusText($status),
232
-            'StatusCode' => $status,
233
-            'Message' => $message,
234
-        )));
222
+	/**
223
+	 * @param int $status
224
+	 * @param string $message
225
+	 * @param string $checkIdentifier
226
+	 */
227
+	public function addResult($status, $message, $checkIdentifier)
228
+	{
229
+		$this->details->push(new ArrayData(array(
230
+			'Check' => $checkIdentifier,
231
+			'Status' => $this->statusText($status),
232
+			'StatusCode' => $status,
233
+			'Message' => $message,
234
+		)));
235 235
 
236
-        $this->worst = max($this->worst, $status);
237
-    }
236
+		$this->worst = max($this->worst, $status);
237
+	}
238 238
 
239
-    /**
240
-     * Returns true if there are no errors.
241
-     *
242
-     * @return bool
243
-     */
244
-    public function ShouldPass()
245
-    {
246
-        return $this->worst <= EnvironmentCheck::WARNING;
247
-    }
239
+	/**
240
+	 * Returns true if there are no errors.
241
+	 *
242
+	 * @return bool
243
+	 */
244
+	public function ShouldPass()
245
+	{
246
+		return $this->worst <= EnvironmentCheck::WARNING;
247
+	}
248 248
 
249
-    /**
250
-     * Returns overall (i.e. worst) status as a string.
251
-     *
252
-     * @return string
253
-     */
254
-    public function Status()
255
-    {
256
-        return $this->statusText($this->worst);
257
-    }
249
+	/**
250
+	 * Returns overall (i.e. worst) status as a string.
251
+	 *
252
+	 * @return string
253
+	 */
254
+	public function Status()
255
+	{
256
+		return $this->statusText($this->worst);
257
+	}
258 258
 
259
-    /**
260
-     * Returns detailed status information about each check.
261
-     *
262
-     * @return ArrayList
263
-     */
264
-    public function Details()
265
-    {
266
-        return $this->details;
267
-    }
259
+	/**
260
+	 * Returns detailed status information about each check.
261
+	 *
262
+	 * @return ArrayList
263
+	 */
264
+	public function Details()
265
+	{
266
+		return $this->details;
267
+	}
268 268
 
269
-    /**
270
-     * Convert the final result status and details to JSON.
271
-     *
272
-     * @return string
273
-     */
274
-    public function toJSON()
275
-    {
276
-        $result = array(
277
-            'Status' => $this->Status(),
278
-            'ShouldPass' => $this->ShouldPass(),
279
-            'Checks' => array()
280
-        );
281
-        foreach ($this->details as $detail) {
282
-            $result['Checks'][] = $detail->toMap();
283
-        }
284
-        return json_encode($result);
285
-    }
269
+	/**
270
+	 * Convert the final result status and details to JSON.
271
+	 *
272
+	 * @return string
273
+	 */
274
+	public function toJSON()
275
+	{
276
+		$result = array(
277
+			'Status' => $this->Status(),
278
+			'ShouldPass' => $this->ShouldPass(),
279
+			'Checks' => array()
280
+		);
281
+		foreach ($this->details as $detail) {
282
+			$result['Checks'][] = $detail->toMap();
283
+		}
284
+		return json_encode($result);
285
+	}
286 286
 
287
-    /**
288
-     * Return a text version of a status code.
289
-     *
290
-     * @return string
291
-     */
292
-    protected function statusText($status)
293
-    {
294
-        switch ($status) {
295
-            case EnvironmentCheck::ERROR: return "ERROR";
296
-            case EnvironmentCheck::WARNING: return "WARNING";
297
-            case EnvironmentCheck::OK: return "OK";
298
-            case 0: return "NO CHECKS";
299
-            default: throw new InvalidArgumentException("Bad environment check status '$status'");
300
-        }
301
-    }
287
+	/**
288
+	 * Return a text version of a status code.
289
+	 *
290
+	 * @return string
291
+	 */
292
+	protected function statusText($status)
293
+	{
294
+		switch ($status) {
295
+			case EnvironmentCheck::ERROR: return "ERROR";
296
+			case EnvironmentCheck::WARNING: return "WARNING";
297
+			case EnvironmentCheck::OK: return "OK";
298
+			case 0: return "NO CHECKS";
299
+			default: throw new InvalidArgumentException("Bad environment check status '$status'");
300
+		}
301
+	}
302 302
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@
 block discarded – undo
77 77
 
78 78
             // Existing named checks can be disabled by setting their 'state' to 'disabled'.
79 79
             // This is handy for disabling checks mandated by modules.
80
-            if (!empty($check['state']) && $check['state']==='disabled') {
80
+            if (!empty($check['state']) && $check['state'] === 'disabled') {
81 81
                 continue;
82 82
             }
83 83
             
Please login to merge, or discard this patch.
code/DevCheckController.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -2,38 +2,38 @@
 block discarded – undo
2 2
 
3 3
 class DevCheckController extends Controller
4 4
 {
5
-    /**
6
-     * @var array
7
-     */
8
-    public static $allowed_actions = array(
9
-        'index'
10
-    );
5
+	/**
6
+	 * @var array
7
+	 */
8
+	public static $allowed_actions = array(
9
+		'index'
10
+	);
11 11
 
12
-    /**
13
-     * Permission code to check for access to this controller.
14
-     *
15
-     * @var string
16
-     */
17
-    private static $permission = 'ADMIN';
12
+	/**
13
+	 * Permission code to check for access to this controller.
14
+	 *
15
+	 * @var string
16
+	 */
17
+	private static $permission = 'ADMIN';
18 18
 
19
-    /**
20
-     * @param SS_HTTPRequest $request
21
-     *
22
-     * @return EnvironmentChecker
23
-     *
24
-     * @throws SS_HTTPResponse_Exception
25
-     */
26
-    public function index($request)
27
-    {
28
-        $suite = 'check';
19
+	/**
20
+	 * @param SS_HTTPRequest $request
21
+	 *
22
+	 * @return EnvironmentChecker
23
+	 *
24
+	 * @throws SS_HTTPResponse_Exception
25
+	 */
26
+	public function index($request)
27
+	{
28
+		$suite = 'check';
29 29
 
30
-        if ($name = $request->param('Suite')) {
31
-            $suite = $name;
32
-        }
30
+		if ($name = $request->param('Suite')) {
31
+			$suite = $name;
32
+		}
33 33
 
34
-        $checker = new EnvironmentChecker($suite, 'Environment status');
35
-        $checker->init($this->config()->permission);
34
+		$checker = new EnvironmentChecker($suite, 'Environment status');
35
+		$checker->init($this->config()->permission);
36 36
 
37
-        return $checker;
38
-    }
37
+		return $checker;
38
+	}
39 39
 }
Please login to merge, or discard this patch.
code/DevHealthController.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -2,26 +2,26 @@
 block discarded – undo
2 2
 
3 3
 class DevHealthController extends Controller
4 4
 {
5
-    /**
6
-     * @var array
7
-     */
8
-    public static $allowed_actions = array(
9
-        'index'
10
-    );
5
+	/**
6
+	 * @var array
7
+	 */
8
+	public static $allowed_actions = array(
9
+		'index'
10
+	);
11 11
 
12
-    /**
13
-     * @return EnvironmentChecker
14
-     *
15
-     * @throws SS_HTTPResponse_Exception
16
-     */
17
-    public function index()
18
-    {
19
-        // health check does not require permission to run
12
+	/**
13
+	 * @return EnvironmentChecker
14
+	 *
15
+	 * @throws SS_HTTPResponse_Exception
16
+	 */
17
+	public function index()
18
+	{
19
+		// health check does not require permission to run
20 20
 
21
-        $checker = new EnvironmentChecker('health', 'Site health');
22
-        $checker->init('');
23
-        $checker->setErrorCode(404);
21
+		$checker = new EnvironmentChecker('health', 'Site health');
22
+		$checker->init('');
23
+		$checker->setErrorCode(404);
24 24
 
25
-        return $checker;
26
-    }
25
+		return $checker;
26
+	}
27 27
 }
Please login to merge, or discard this patch.
code/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.
code/EnvironmentChecker.php 2 patches
Indentation   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -5,288 +5,288 @@
 block discarded – undo
5 5
  */
6 6
 class EnvironmentChecker extends RequestHandler
7 7
 {
8
-    /**
9
-     * @var array
10
-     */
11
-    private static $url_handlers = array(
12
-        '' => 'index',
13
-    );
14
-
15
-    /**
16
-     * @var string
17
-     */
18
-    protected $checkSuiteName;
19
-
20
-    /**
21
-     * @var string
22
-     */
23
-    protected $title;
24
-
25
-    /**
26
-     * @var int
27
-     */
28
-    protected $errorCode = 500;
29
-
30
-    /**
31
-     * @var null|string
32
-     */
33
-    private static $to_email_address = null;
34
-
35
-    /**
36
-     * @var null|string
37
-     */
38
-    private static $from_email_address = null;
39
-
40
-    /**
41
-     * @var bool
42
-     */
43
-    private static $email_results = false;
44
-
45
-    /**
46
-     * @var bool Log results via {@link SS_Log}
47
-     */
48
-    private static $log_results_warning = false;
49
-
50
-    /**
51
-     * @var int Maps to {@link Zend_Log} levels. Defaults to Zend_Log::WARN
52
-     */
53
-    private static $log_results_warning_level = 4;
54
-
55
-    /**
56
-     * @var bool Log results via {@link SS_Log}
57
-     */
58
-    private static $log_results_error = false;
59
-
60
-    /**
61
-     * @var int Maps to {@link Zend_Log} levels. Defaults to Zend_Log::ALERT
62
-     */
63
-    private static $log_results_error_level = 1;
64
-
65
-    /**
66
-     * @param string $checkSuiteName
67
-     * @param string $title
68
-     */
69
-    public function __construct($checkSuiteName, $title)
70
-    {
71
-        parent::__construct();
8
+	/**
9
+	 * @var array
10
+	 */
11
+	private static $url_handlers = array(
12
+		'' => 'index',
13
+	);
14
+
15
+	/**
16
+	 * @var string
17
+	 */
18
+	protected $checkSuiteName;
19
+
20
+	/**
21
+	 * @var string
22
+	 */
23
+	protected $title;
24
+
25
+	/**
26
+	 * @var int
27
+	 */
28
+	protected $errorCode = 500;
29
+
30
+	/**
31
+	 * @var null|string
32
+	 */
33
+	private static $to_email_address = null;
34
+
35
+	/**
36
+	 * @var null|string
37
+	 */
38
+	private static $from_email_address = null;
39
+
40
+	/**
41
+	 * @var bool
42
+	 */
43
+	private static $email_results = false;
44
+
45
+	/**
46
+	 * @var bool Log results via {@link SS_Log}
47
+	 */
48
+	private static $log_results_warning = false;
49
+
50
+	/**
51
+	 * @var int Maps to {@link Zend_Log} levels. Defaults to Zend_Log::WARN
52
+	 */
53
+	private static $log_results_warning_level = 4;
54
+
55
+	/**
56
+	 * @var bool Log results via {@link SS_Log}
57
+	 */
58
+	private static $log_results_error = false;
59
+
60
+	/**
61
+	 * @var int Maps to {@link Zend_Log} levels. Defaults to Zend_Log::ALERT
62
+	 */
63
+	private static $log_results_error_level = 1;
64
+
65
+	/**
66
+	 * @param string $checkSuiteName
67
+	 * @param string $title
68
+	 */
69
+	public function __construct($checkSuiteName, $title)
70
+	{
71
+		parent::__construct();
72 72
         
73
-        $this->checkSuiteName = $checkSuiteName;
74
-        $this->title = $title;
75
-    }
76
-
77
-    /**
78
-     * @param string $permission
79
-     *
80
-     * @throws SS_HTTPResponse_Exception
81
-     */
82
-    public function init($permission = 'ADMIN')
83
-    {
84
-        // if the environment supports it, provide a basic auth challenge and see if it matches configured credentials
85
-        if (defined('ENVCHECK_BASICAUTH_USERNAME') && defined('ENVCHECK_BASICAUTH_PASSWORD')) {
86
-            if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
87
-                // authenticate the input user/pass with the configured credentials
88
-                if (
89
-                    !(
90
-                        $_SERVER['PHP_AUTH_USER'] == ENVCHECK_BASICAUTH_USERNAME
91
-                        && $_SERVER['PHP_AUTH_PW'] == ENVCHECK_BASICAUTH_PASSWORD
92
-                    )
93
-                ) {
94
-                    $response = new SS_HTTPResponse(null, 401);
95
-                    $response->addHeader('WWW-Authenticate', "Basic realm=\"Environment check\"");
96
-                    // Exception is caught by RequestHandler->handleRequest() and will halt further execution
97
-                    $e = new SS_HTTPResponse_Exception(null, 401);
98
-                    $e->setResponse($response);
99
-                    throw $e;
100
-                }
101
-            } else {
102
-                $response = new SS_HTTPResponse(null, 401);
103
-                $response->addHeader('WWW-Authenticate', "Basic realm=\"Environment check\"");
104
-                // Exception is caught by RequestHandler->handleRequest() and will halt further execution
105
-                $e = new SS_HTTPResponse_Exception(null, 401);
106
-                $e->setResponse($response);
107
-                throw $e;
108
-            }
109
-        } else {
110
-            if (!$this->canAccess(null, $permission)) {
111
-                return $this->httpError(403);
112
-            }
113
-        }
114
-    }
115
-
116
-    /**
117
-     * @param null|int|Member $member
118
-     * @param string $permission
119
-     *
120
-     * @return bool
121
-     *
122
-     * @throws SS_HTTPResponse_Exception
123
-     */
124
-    public function canAccess($member = null, $permission = "ADMIN")
125
-    {
126
-        if (!$member) {
127
-            $member = Member::currentUser();
128
-        }
129
-
130
-        if (!$member) {
131
-            $member = BasicAuth::requireLogin('Environment Checker', $permission, false);
132
-        }
133
-
134
-        // We allow access to this controller regardless of live-status or ADMIN permission only
135
-        // if on CLI.  Access to this controller is always allowed in "dev-mode", or of the user is ADMIN.
136
-        if (
137
-            Director::isDev()
138
-            || Director::is_cli()
139
-            || empty($permission)
140
-            || Permission::checkMember($member, $permission)
141
-        ) {
142
-            return true;
143
-        }
144
-
145
-        // Extended access checks.
146
-        // "Veto" style, return NULL to abstain vote.
147
-        $canExtended = null;
148
-        $results = $this->extend('canAccess', $member);
149
-        if ($results && is_array($results)) {
150
-            if (!min($results)) {
151
-                return false;
152
-            } else {
153
-                return true;
154
-            }
155
-        }
156
-
157
-        return false;
158
-    }
159
-
160
-    /**
161
-     * @return SS_HTTPResponse
162
-     */
163
-    public function index()
164
-    {
165
-        $response = new SS_HTTPResponse;
166
-        $result = EnvironmentCheckSuite::inst($this->checkSuiteName)->run();
167
-
168
-        if (!$result->ShouldPass()) {
169
-            $response->setStatusCode($this->errorCode);
170
-        }
171
-
172
-        $resultText = $result->customise(array(
173
-            "URL" => Director::absoluteBaseURL(),
174
-            "Title" => $this->title,
175
-            "Name" => $this->checkSuiteName,
176
-            "ErrorCode" => $this->errorCode,
177
-        ))->renderWith("EnvironmentChecker");
178
-
179
-        if ($this->config()->email_results && !$result->ShouldPass()) {
180
-            $email = new Email($this->config()->from_email_address, $this->config()->to_email_address, $this->title, $resultText);
181
-            $email->send();
182
-        }
183
-
184
-        // Optionally log errors and warnings individually
185
-        foreach ($result->Details() as $detail) {
186
-            if ($this->config()->log_results_warning && $detail->StatusCode == EnvironmentCheck::WARNING) {
187
-                $this->log(
188
-                    sprintf('EnvironmentChecker warning at "%s" check. Message: %s', $detail->Check, $detail->Message),
189
-                    $this->config()->log_results_warning_level
190
-                );
191
-            } elseif ($this->config()->log_results_error && $detail->StatusCode == EnvironmentCheck::ERROR) {
192
-                $this->log(
193
-                    sprintf('EnvironmentChecker error at "%s" check. Message: %s', $detail->Check, $detail->Message),
194
-                    $this->config()->log_results_error_level
195
-                );
196
-            }
197
-        }
198
-
199
-        // output the result as JSON if requested
200
-        if (
201
-            $this->getRequest()->getExtension() == 'json'
202
-            || strpos($this->getRequest()->getHeader('Accept'), 'application/json') !== false
203
-        ) {
204
-            $response->setBody($result->toJSON());
205
-            $response->addHeader('Content-Type', 'application/json');
206
-            return $response;
207
-        }
208
-
209
-        $response->setBody($resultText);
73
+		$this->checkSuiteName = $checkSuiteName;
74
+		$this->title = $title;
75
+	}
76
+
77
+	/**
78
+	 * @param string $permission
79
+	 *
80
+	 * @throws SS_HTTPResponse_Exception
81
+	 */
82
+	public function init($permission = 'ADMIN')
83
+	{
84
+		// if the environment supports it, provide a basic auth challenge and see if it matches configured credentials
85
+		if (defined('ENVCHECK_BASICAUTH_USERNAME') && defined('ENVCHECK_BASICAUTH_PASSWORD')) {
86
+			if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
87
+				// authenticate the input user/pass with the configured credentials
88
+				if (
89
+					!(
90
+						$_SERVER['PHP_AUTH_USER'] == ENVCHECK_BASICAUTH_USERNAME
91
+						&& $_SERVER['PHP_AUTH_PW'] == ENVCHECK_BASICAUTH_PASSWORD
92
+					)
93
+				) {
94
+					$response = new SS_HTTPResponse(null, 401);
95
+					$response->addHeader('WWW-Authenticate', "Basic realm=\"Environment check\"");
96
+					// Exception is caught by RequestHandler->handleRequest() and will halt further execution
97
+					$e = new SS_HTTPResponse_Exception(null, 401);
98
+					$e->setResponse($response);
99
+					throw $e;
100
+				}
101
+			} else {
102
+				$response = new SS_HTTPResponse(null, 401);
103
+				$response->addHeader('WWW-Authenticate', "Basic realm=\"Environment check\"");
104
+				// Exception is caught by RequestHandler->handleRequest() and will halt further execution
105
+				$e = new SS_HTTPResponse_Exception(null, 401);
106
+				$e->setResponse($response);
107
+				throw $e;
108
+			}
109
+		} else {
110
+			if (!$this->canAccess(null, $permission)) {
111
+				return $this->httpError(403);
112
+			}
113
+		}
114
+	}
115
+
116
+	/**
117
+	 * @param null|int|Member $member
118
+	 * @param string $permission
119
+	 *
120
+	 * @return bool
121
+	 *
122
+	 * @throws SS_HTTPResponse_Exception
123
+	 */
124
+	public function canAccess($member = null, $permission = "ADMIN")
125
+	{
126
+		if (!$member) {
127
+			$member = Member::currentUser();
128
+		}
129
+
130
+		if (!$member) {
131
+			$member = BasicAuth::requireLogin('Environment Checker', $permission, false);
132
+		}
133
+
134
+		// We allow access to this controller regardless of live-status or ADMIN permission only
135
+		// if on CLI.  Access to this controller is always allowed in "dev-mode", or of the user is ADMIN.
136
+		if (
137
+			Director::isDev()
138
+			|| Director::is_cli()
139
+			|| empty($permission)
140
+			|| Permission::checkMember($member, $permission)
141
+		) {
142
+			return true;
143
+		}
144
+
145
+		// Extended access checks.
146
+		// "Veto" style, return NULL to abstain vote.
147
+		$canExtended = null;
148
+		$results = $this->extend('canAccess', $member);
149
+		if ($results && is_array($results)) {
150
+			if (!min($results)) {
151
+				return false;
152
+			} else {
153
+				return true;
154
+			}
155
+		}
156
+
157
+		return false;
158
+	}
159
+
160
+	/**
161
+	 * @return SS_HTTPResponse
162
+	 */
163
+	public function index()
164
+	{
165
+		$response = new SS_HTTPResponse;
166
+		$result = EnvironmentCheckSuite::inst($this->checkSuiteName)->run();
167
+
168
+		if (!$result->ShouldPass()) {
169
+			$response->setStatusCode($this->errorCode);
170
+		}
171
+
172
+		$resultText = $result->customise(array(
173
+			"URL" => Director::absoluteBaseURL(),
174
+			"Title" => $this->title,
175
+			"Name" => $this->checkSuiteName,
176
+			"ErrorCode" => $this->errorCode,
177
+		))->renderWith("EnvironmentChecker");
178
+
179
+		if ($this->config()->email_results && !$result->ShouldPass()) {
180
+			$email = new Email($this->config()->from_email_address, $this->config()->to_email_address, $this->title, $resultText);
181
+			$email->send();
182
+		}
183
+
184
+		// Optionally log errors and warnings individually
185
+		foreach ($result->Details() as $detail) {
186
+			if ($this->config()->log_results_warning && $detail->StatusCode == EnvironmentCheck::WARNING) {
187
+				$this->log(
188
+					sprintf('EnvironmentChecker warning at "%s" check. Message: %s', $detail->Check, $detail->Message),
189
+					$this->config()->log_results_warning_level
190
+				);
191
+			} elseif ($this->config()->log_results_error && $detail->StatusCode == EnvironmentCheck::ERROR) {
192
+				$this->log(
193
+					sprintf('EnvironmentChecker error at "%s" check. Message: %s', $detail->Check, $detail->Message),
194
+					$this->config()->log_results_error_level
195
+				);
196
+			}
197
+		}
198
+
199
+		// output the result as JSON if requested
200
+		if (
201
+			$this->getRequest()->getExtension() == 'json'
202
+			|| strpos($this->getRequest()->getHeader('Accept'), 'application/json') !== false
203
+		) {
204
+			$response->setBody($result->toJSON());
205
+			$response->addHeader('Content-Type', 'application/json');
206
+			return $response;
207
+		}
208
+
209
+		$response->setBody($resultText);
210 210
         
211
-        return $response;
212
-    }
213
-
214
-    /**
215
-     * @param string $message
216
-     * @param int $level
217
-     */
218
-    public function log($message, $level)
219
-    {
220
-        SS_Log::log($message, $level);
221
-    }
222
-
223
-    /**
224
-     * Set the HTTP status code that should be returned when there's an error.
225
-     *
226
-     * @param int $errorCode
227
-     */
228
-    public function setErrorCode($errorCode)
229
-    {
230
-        $this->errorCode = $errorCode;
231
-    }
232
-
233
-    /**
234
-     * @deprecated
235
-     * @param string $from
236
-     */
237
-    public static function set_from_email_address($from)
238
-    {
239
-        Deprecation::notice('2.0', 'Use config API instead');
240
-        Config::inst()->update('EnvironmentChecker', 'from_email_address', $from);
241
-    }
242
-
243
-    /**
244
-     * @deprecated
245
-     * @return null|string
246
-     */
247
-    public static function get_from_email_address()
248
-    {
249
-        Deprecation::notice('2.0', 'Use config API instead');
250
-        return Config::inst()->get('EnvironmentChecker', 'from_email_address');
251
-    }
252
-
253
-    /**
254
-     * @deprecated
255
-     * @param string $to
256
-     */
257
-    public static function set_to_email_address($to)
258
-    {
259
-        Deprecation::notice('2.0', 'Use config API instead');
260
-        Config::inst()->update('EnvironmentChecker', 'to_email_address',  $to);
261
-    }
262
-
263
-    /**
264
-     * @deprecated
265
-     * @return null|string
266
-     */
267
-    public static function get_to_email_address()
268
-    {
269
-        Deprecation::notice('2.0', 'Use config API instead');
270
-        return Config::inst()->get('EnvironmentChecker', 'to_email_address');
271
-    }
272
-
273
-    /**
274
-     * @deprecated
275
-     * @param bool $results
276
-     */
277
-    public static function set_email_results($results)
278
-    {
279
-        Deprecation::notice('2.0', 'Use config API instead');
280
-        Config::inst()->update('EnvironmentChecker', 'email_results', $results);
281
-    }
282
-
283
-    /**
284
-     * @deprecated
285
-     * @return bool
286
-     */
287
-    public static function get_email_results()
288
-    {
289
-        Deprecation::notice('2.0', 'Use config API instead');
290
-        return Config::inst()->get('EnvironmentChecker', 'email_results');
291
-    }
211
+		return $response;
212
+	}
213
+
214
+	/**
215
+	 * @param string $message
216
+	 * @param int $level
217
+	 */
218
+	public function log($message, $level)
219
+	{
220
+		SS_Log::log($message, $level);
221
+	}
222
+
223
+	/**
224
+	 * Set the HTTP status code that should be returned when there's an error.
225
+	 *
226
+	 * @param int $errorCode
227
+	 */
228
+	public function setErrorCode($errorCode)
229
+	{
230
+		$this->errorCode = $errorCode;
231
+	}
232
+
233
+	/**
234
+	 * @deprecated
235
+	 * @param string $from
236
+	 */
237
+	public static function set_from_email_address($from)
238
+	{
239
+		Deprecation::notice('2.0', 'Use config API instead');
240
+		Config::inst()->update('EnvironmentChecker', 'from_email_address', $from);
241
+	}
242
+
243
+	/**
244
+	 * @deprecated
245
+	 * @return null|string
246
+	 */
247
+	public static function get_from_email_address()
248
+	{
249
+		Deprecation::notice('2.0', 'Use config API instead');
250
+		return Config::inst()->get('EnvironmentChecker', 'from_email_address');
251
+	}
252
+
253
+	/**
254
+	 * @deprecated
255
+	 * @param string $to
256
+	 */
257
+	public static function set_to_email_address($to)
258
+	{
259
+		Deprecation::notice('2.0', 'Use config API instead');
260
+		Config::inst()->update('EnvironmentChecker', 'to_email_address',  $to);
261
+	}
262
+
263
+	/**
264
+	 * @deprecated
265
+	 * @return null|string
266
+	 */
267
+	public static function get_to_email_address()
268
+	{
269
+		Deprecation::notice('2.0', 'Use config API instead');
270
+		return Config::inst()->get('EnvironmentChecker', 'to_email_address');
271
+	}
272
+
273
+	/**
274
+	 * @deprecated
275
+	 * @param bool $results
276
+	 */
277
+	public static function set_email_results($results)
278
+	{
279
+		Deprecation::notice('2.0', 'Use config API instead');
280
+		Config::inst()->update('EnvironmentChecker', 'email_results', $results);
281
+	}
282
+
283
+	/**
284
+	 * @deprecated
285
+	 * @return bool
286
+	 */
287
+	public static function get_email_results()
288
+	{
289
+		Deprecation::notice('2.0', 'Use config API instead');
290
+		return Config::inst()->get('EnvironmentChecker', 'email_results');
291
+	}
292 292
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -257,7 +257,7 @@
 block discarded – undo
257 257
     public static function set_to_email_address($to)
258 258
     {
259 259
         Deprecation::notice('2.0', 'Use config API instead');
260
-        Config::inst()->update('EnvironmentChecker', 'to_email_address',  $to);
260
+        Config::inst()->update('EnvironmentChecker', 'to_email_address', $to);
261 261
     }
262 262
 
263 263
     /**
Please login to merge, or discard this patch.
code/checks/DatabaseCheck.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -6,35 +6,35 @@
 block discarded – undo
6 6
  */
7 7
 class DatabaseCheck implements EnvironmentCheck
8 8
 {
9
-    protected $checkTable;
9
+	protected $checkTable;
10 10
 
11
-    /**
12
-     * By default, Member will be checked.
13
-     *
14
-     * @param string $checkTable
15
-     */
16
-    public function __construct($checkTable = "Member")
17
-    {
18
-        $this->checkTable = $checkTable;
19
-    }
11
+	/**
12
+	 * By default, Member will be checked.
13
+	 *
14
+	 * @param string $checkTable
15
+	 */
16
+	public function __construct($checkTable = "Member")
17
+	{
18
+		$this->checkTable = $checkTable;
19
+	}
20 20
 
21
-    /**
22
-     * @inheritdoc
23
-     *
24
-     * @return array
25
-     */
26
-    public function check()
27
-    {
28
-        if (!DB::getConn()->hasTable($this->checkTable)) {
29
-            return array(EnvironmentCheck::ERROR, "$this->checkTable not present in the database");
30
-        }
21
+	/**
22
+	 * @inheritdoc
23
+	 *
24
+	 * @return array
25
+	 */
26
+	public function check()
27
+	{
28
+		if (!DB::getConn()->hasTable($this->checkTable)) {
29
+			return array(EnvironmentCheck::ERROR, "$this->checkTable not present in the database");
30
+		}
31 31
 
32
-        $count = DB::query("SELECT COUNT(*) FROM \"$this->checkTable\"")->value();
32
+		$count = DB::query("SELECT COUNT(*) FROM \"$this->checkTable\"")->value();
33 33
         
34
-        if ($count > 0) {
35
-            return array(EnvironmentCheck::OK, "");
36
-        } else {
37
-            return array(EnvironmentCheck::WARNING, "$this->checkTable queried ok but has no records");
38
-        }
39
-    }
34
+		if ($count > 0) {
35
+			return array(EnvironmentCheck::OK, "");
36
+		} else {
37
+			return array(EnvironmentCheck::WARNING, "$this->checkTable queried ok but has no records");
38
+		}
39
+	}
40 40
 }
Please login to merge, or discard this patch.
code/checks/ExternalURLCheck.php 1 patch
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -10,118 +10,118 @@
 block discarded – undo
10 10
  */
11 11
 class ExternalURLCheck implements EnvironmentCheck
12 12
 {
13
-    /**
14
-     * @var array
15
-     */
16
-    protected $urls = array();
13
+	/**
14
+	 * @var array
15
+	 */
16
+	protected $urls = array();
17 17
 
18
-    /**
19
-     * @var Int Timeout in seconds.
20
-     */
21
-    protected $timeout;
18
+	/**
19
+	 * @var Int Timeout in seconds.
20
+	 */
21
+	protected $timeout;
22 22
 
23
-    /**
24
-     * @param string $urls Space-separated list of absolute URLs.
25
-     * @param int $timeout
26
-     */
27
-    public function __construct($urls, $timeout = 15)
28
-    {
29
-        if ($urls) {
30
-            $this->urls = explode(' ', $urls);
31
-        }
32
-        $this->timeout = $timeout;
33
-    }
23
+	/**
24
+	 * @param string $urls Space-separated list of absolute URLs.
25
+	 * @param int $timeout
26
+	 */
27
+	public function __construct($urls, $timeout = 15)
28
+	{
29
+		if ($urls) {
30
+			$this->urls = explode(' ', $urls);
31
+		}
32
+		$this->timeout = $timeout;
33
+	}
34 34
 
35
-    /**
36
-     * @inheritdoc
37
-     *
38
-     * @return array
39
-     */
40
-    public function check()
41
-    {
42
-        $urls = $this->getURLs();
35
+	/**
36
+	 * @inheritdoc
37
+	 *
38
+	 * @return array
39
+	 */
40
+	public function check()
41
+	{
42
+		$urls = $this->getURLs();
43 43
 
44
-        $chs = array();
45
-        foreach ($urls as $url) {
46
-            $ch = curl_init();
47
-            $chs[] = $ch;
48
-            curl_setopt_array($ch, $this->getCurlOpts($url));
49
-        }
50
-        // Parallel execution for faster performance
51
-        $mh = curl_multi_init();
52
-        foreach ($chs as $ch) {
53
-            curl_multi_add_handle($mh, $ch);
54
-        }
44
+		$chs = array();
45
+		foreach ($urls as $url) {
46
+			$ch = curl_init();
47
+			$chs[] = $ch;
48
+			curl_setopt_array($ch, $this->getCurlOpts($url));
49
+		}
50
+		// Parallel execution for faster performance
51
+		$mh = curl_multi_init();
52
+		foreach ($chs as $ch) {
53
+			curl_multi_add_handle($mh, $ch);
54
+		}
55 55
         
56
-        $active = null;
57
-        // Execute the handles
58
-        do {
59
-            $mrc = curl_multi_exec($mh, $active);
60
-            curl_multi_select($mh);
61
-        } while ($active > 0);
56
+		$active = null;
57
+		// Execute the handles
58
+		do {
59
+			$mrc = curl_multi_exec($mh, $active);
60
+			curl_multi_select($mh);
61
+		} while ($active > 0);
62 62
 
63
-        while ($active && $mrc == CURLM_OK) {
64
-            if (curl_multi_select($mh) != -1) {
65
-                do {
66
-                    $mrc = curl_multi_exec($mh, $active);
67
-                } while ($mrc == CURLM_CALL_MULTI_PERFORM);
68
-            }
69
-        }
63
+		while ($active && $mrc == CURLM_OK) {
64
+			if (curl_multi_select($mh) != -1) {
65
+				do {
66
+					$mrc = curl_multi_exec($mh, $active);
67
+				} while ($mrc == CURLM_CALL_MULTI_PERFORM);
68
+			}
69
+		}
70 70
 
71
-        $hasError = false;
72
-        $msgs = array();
73
-        foreach ($chs as $ch) {
74
-            $url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
75
-            $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
76
-            if (curl_errno($ch) || $code >= 400) {
77
-                $hasError = true;
78
-                $msgs[] = sprintf(
79
-                    'Error retrieving "%s": %s (Code: %s)',
80
-                    $url,
81
-                    curl_error($ch),
82
-                    $code
83
-                );
84
-            } else {
85
-                $msgs[] = sprintf(
86
-                    'Success retrieving "%s" (Code: %s)',
87
-                    $url,
88
-                    $code
89
-                );
90
-            }
91
-        }
71
+		$hasError = false;
72
+		$msgs = array();
73
+		foreach ($chs as $ch) {
74
+			$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
75
+			$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
76
+			if (curl_errno($ch) || $code >= 400) {
77
+				$hasError = true;
78
+				$msgs[] = sprintf(
79
+					'Error retrieving "%s": %s (Code: %s)',
80
+					$url,
81
+					curl_error($ch),
82
+					$code
83
+				);
84
+			} else {
85
+				$msgs[] = sprintf(
86
+					'Success retrieving "%s" (Code: %s)',
87
+					$url,
88
+					$code
89
+				);
90
+			}
91
+		}
92 92
 
93
-        // Close the handles
94
-        foreach ($chs as $ch) {
95
-            curl_multi_remove_handle($mh, $ch);
96
-        }
97
-        curl_multi_close($mh);
93
+		// Close the handles
94
+		foreach ($chs as $ch) {
95
+			curl_multi_remove_handle($mh, $ch);
96
+		}
97
+		curl_multi_close($mh);
98 98
         
99
-        if ($hasError) {
100
-            return array(EnvironmentCheck::ERROR, implode(', ', $msgs));
101
-        } else {
102
-            return array(EnvironmentCheck::OK, implode(', ', $msgs));
103
-        }
104
-    }
99
+		if ($hasError) {
100
+			return array(EnvironmentCheck::ERROR, implode(', ', $msgs));
101
+		} else {
102
+			return array(EnvironmentCheck::OK, implode(', ', $msgs));
103
+		}
104
+	}
105 105
 
106
-    /**
107
-     * @return array
108
-     */
109
-    protected function getCurlOpts($url)
110
-    {
111
-        return array(
112
-            CURLOPT_URL => $url,
113
-            CURLOPT_HEADER => 0,
114
-            CURLOPT_RETURNTRANSFER => 1,
115
-            CURLOPT_FAILONERROR => 1,
116
-            CURLOPT_TIMEOUT => $this->timeout,
117
-        );
118
-    }
106
+	/**
107
+	 * @return array
108
+	 */
109
+	protected function getCurlOpts($url)
110
+	{
111
+		return array(
112
+			CURLOPT_URL => $url,
113
+			CURLOPT_HEADER => 0,
114
+			CURLOPT_RETURNTRANSFER => 1,
115
+			CURLOPT_FAILONERROR => 1,
116
+			CURLOPT_TIMEOUT => $this->timeout,
117
+		);
118
+	}
119 119
 
120
-    /**
121
-     * @return array
122
-     */
123
-    protected function getURLs()
124
-    {
125
-        return $this->urls;
126
-    }
120
+	/**
121
+	 * @return array
122
+	 */
123
+	protected function getURLs()
124
+	{
125
+		return $this->urls;
126
+	}
127 127
 }
Please login to merge, or discard this patch.
code/checks/FileAccessibilityAndValidationCheck.php 3 patches
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -21,163 +21,163 @@
 block discarded – undo
21 21
  */
22 22
 class FileAccessibilityAndValidationCheck implements EnvironmentCheck
23 23
 {
24
-    /**
25
-     * @var int
26
-     */
27
-    const CHECK_SINGLE = 1;
28
-
29
-    /**
30
-     * @var int
31
-     */
32
-    const CHECK_ALL = 2;
33
-
34
-    /**
35
-     * Absolute path to a file or folder, compatible with glob().
36
-     *
37
-     * @var string
38
-     */
39
-    protected $path;
40
-
41
-    /**
42
-     * Constant, check for a single file to match age criteria, or all of them.
43
-     *
44
-     * @var int
45
-     */
46
-    protected $fileTypeValidateFunc;
47
-
48
-    /**
49
-     * Constant, check for a single file to match age criteria, or all of them.
50
-     *
51
-     * @var int
52
-     */
53
-    protected $checkType;
54
-
55
-    /**
56
-     * @param string $path
57
-     * @param string $fileTypeValidateFunc
58
-     * @param null|int $checkType
59
-     */
60
-    public function __construct($path, $fileTypeValidateFunc = 'noVidation', $checkType = null)
61
-    {
62
-        $this->path = $path;
63
-        $this->fileTypeValidateFunc = ($fileTypeValidateFunc)? $fileTypeValidateFunc:'noVidation';
64
-        $this->checkType = ($checkType) ? $checkType : self::CHECK_SINGLE;
65
-    }
66
-
67
-    /**
68
-     * @inheritdoc
69
-     *
70
-     * @return array
71
-     */
72
-    public function check()
73
-    {
74
-        $origStage = Versioned::get_reading_mode();
75
-        Versioned::set_reading_mode('Live');
76
-
77
-        $files = $this->getFiles();
78
-        if ($files) {
79
-            $fileTypeValidateFunc = $this->fileTypeValidateFunc;
80
-            if (method_exists($this, $fileTypeValidateFunc)) {
81
-                $invalidFiles = array();
82
-                $validFiles = array();
83
-
84
-                foreach ($files as $file) {
85
-                    if ($this->$fileTypeValidateFunc($file)) {
86
-                        $validFiles[] = $file;
87
-                    } else {
88
-                        $invalidFiles[] = $file;
89
-                    }
90
-                }
91
-
92
-                // If at least one file was valid, count as passed
93
-                if ($this->checkType == self::CHECK_SINGLE && count($invalidFiles) < count($files)) {
94
-                    $validFileList = "\n";
95
-                    foreach ($validFiles as $vf) {
96
-                        $validFileList .= $vf."\n";
97
-                    }
98
-                    if ($fileTypeValidateFunc == 'noVidation') {
99
-                        $checkReturn = array(
100
-                            EnvironmentCheck::OK,
101
-                            sprintf('At least these file(s) accessible: %s', $validFileList)
102
-                        );
103
-                    } else {
104
-                        $checkReturn = array(
105
-                            EnvironmentCheck::OK,
106
-                            sprintf('At least these file(s) passed file type validate function "%s": %s', $fileTypeValidateFunc, $validFileList)
107
-                        );
108
-                    }
109
-                } else {
110
-                    if (count($invalidFiles) == 0) {
111
-                        $checkReturn = array(EnvironmentCheck::OK, 'All files valideted');
112
-                    } else {
113
-                        $invalidFileList = "\n";
114
-                        foreach ($invalidFiles as $vf) {
115
-                            $invalidFileList .= $vf."\n";
116
-                        }
117
-
118
-                        if ($fileTypeValidateFunc == 'noVidation') {
119
-                            $checkReturn = array(
120
-                                EnvironmentCheck::ERROR,
121
-                                sprintf('File(s) not accessible: %s', $invalidFileList)
122
-                            );
123
-                        } else {
124
-                            $checkReturn = array(
125
-                                EnvironmentCheck::ERROR,
126
-                                sprintf('File(s) not passing the file type validate function "%s": %s', $fileTypeValidateFunc, $invalidFileList)
127
-                            );
128
-                        }
129
-                    }
130
-                }
131
-            } else {
132
-                $checkReturn =  array(
133
-                    EnvironmentCheck::ERROR,
134
-                    sprintf("Invalid file type validation method name passed: %s ", $fileTypeValidateFunc)
135
-                );
136
-            }
137
-        } else {
138
-            $checkReturn = array(
139
-                EnvironmentCheck::ERROR,
140
-                sprintf("No files accessible at path %s", $this->path)
141
-            );
142
-        }
143
-
144
-        Versioned::set_reading_mode($origStage);
145
-
146
-        return $checkReturn;
147
-    }
148
-
149
-    /**
150
-     * @param string $file
151
-     *
152
-     * @return bool
153
-     */
154
-    private function jsonValidate($file)
155
-    {
156
-        $json = json_decode(file_get_contents($file));
157
-        if (!$json) {
158
-            return false;
159
-        } else {
160
-            return true;
161
-        }
162
-    }
163
-
164
-    /**
165
-     * @param string $file
166
-     *
167
-     * @return bool
168
-     */
169
-    protected function noVidation($file)
170
-    {
171
-        return true;
172
-    }
173
-
174
-    /**
175
-     * Gets a list of absolute file paths.
176
-     *
177
-     * @return array
178
-     */
179
-    protected function getFiles()
180
-    {
181
-        return glob($this->path);
182
-    }
24
+	/**
25
+	 * @var int
26
+	 */
27
+	const CHECK_SINGLE = 1;
28
+
29
+	/**
30
+	 * @var int
31
+	 */
32
+	const CHECK_ALL = 2;
33
+
34
+	/**
35
+	 * Absolute path to a file or folder, compatible with glob().
36
+	 *
37
+	 * @var string
38
+	 */
39
+	protected $path;
40
+
41
+	/**
42
+	 * Constant, check for a single file to match age criteria, or all of them.
43
+	 *
44
+	 * @var int
45
+	 */
46
+	protected $fileTypeValidateFunc;
47
+
48
+	/**
49
+	 * Constant, check for a single file to match age criteria, or all of them.
50
+	 *
51
+	 * @var int
52
+	 */
53
+	protected $checkType;
54
+
55
+	/**
56
+	 * @param string $path
57
+	 * @param string $fileTypeValidateFunc
58
+	 * @param null|int $checkType
59
+	 */
60
+	public function __construct($path, $fileTypeValidateFunc = 'noVidation', $checkType = null)
61
+	{
62
+		$this->path = $path;
63
+		$this->fileTypeValidateFunc = ($fileTypeValidateFunc)? $fileTypeValidateFunc:'noVidation';
64
+		$this->checkType = ($checkType) ? $checkType : self::CHECK_SINGLE;
65
+	}
66
+
67
+	/**
68
+	 * @inheritdoc
69
+	 *
70
+	 * @return array
71
+	 */
72
+	public function check()
73
+	{
74
+		$origStage = Versioned::get_reading_mode();
75
+		Versioned::set_reading_mode('Live');
76
+
77
+		$files = $this->getFiles();
78
+		if ($files) {
79
+			$fileTypeValidateFunc = $this->fileTypeValidateFunc;
80
+			if (method_exists($this, $fileTypeValidateFunc)) {
81
+				$invalidFiles = array();
82
+				$validFiles = array();
83
+
84
+				foreach ($files as $file) {
85
+					if ($this->$fileTypeValidateFunc($file)) {
86
+						$validFiles[] = $file;
87
+					} else {
88
+						$invalidFiles[] = $file;
89
+					}
90
+				}
91
+
92
+				// If at least one file was valid, count as passed
93
+				if ($this->checkType == self::CHECK_SINGLE && count($invalidFiles) < count($files)) {
94
+					$validFileList = "\n";
95
+					foreach ($validFiles as $vf) {
96
+						$validFileList .= $vf."\n";
97
+					}
98
+					if ($fileTypeValidateFunc == 'noVidation') {
99
+						$checkReturn = array(
100
+							EnvironmentCheck::OK,
101
+							sprintf('At least these file(s) accessible: %s', $validFileList)
102
+						);
103
+					} else {
104
+						$checkReturn = array(
105
+							EnvironmentCheck::OK,
106
+							sprintf('At least these file(s) passed file type validate function "%s": %s', $fileTypeValidateFunc, $validFileList)
107
+						);
108
+					}
109
+				} else {
110
+					if (count($invalidFiles) == 0) {
111
+						$checkReturn = array(EnvironmentCheck::OK, 'All files valideted');
112
+					} else {
113
+						$invalidFileList = "\n";
114
+						foreach ($invalidFiles as $vf) {
115
+							$invalidFileList .= $vf."\n";
116
+						}
117
+
118
+						if ($fileTypeValidateFunc == 'noVidation') {
119
+							$checkReturn = array(
120
+								EnvironmentCheck::ERROR,
121
+								sprintf('File(s) not accessible: %s', $invalidFileList)
122
+							);
123
+						} else {
124
+							$checkReturn = array(
125
+								EnvironmentCheck::ERROR,
126
+								sprintf('File(s) not passing the file type validate function "%s": %s', $fileTypeValidateFunc, $invalidFileList)
127
+							);
128
+						}
129
+					}
130
+				}
131
+			} else {
132
+				$checkReturn =  array(
133
+					EnvironmentCheck::ERROR,
134
+					sprintf("Invalid file type validation method name passed: %s ", $fileTypeValidateFunc)
135
+				);
136
+			}
137
+		} else {
138
+			$checkReturn = array(
139
+				EnvironmentCheck::ERROR,
140
+				sprintf("No files accessible at path %s", $this->path)
141
+			);
142
+		}
143
+
144
+		Versioned::set_reading_mode($origStage);
145
+
146
+		return $checkReturn;
147
+	}
148
+
149
+	/**
150
+	 * @param string $file
151
+	 *
152
+	 * @return bool
153
+	 */
154
+	private function jsonValidate($file)
155
+	{
156
+		$json = json_decode(file_get_contents($file));
157
+		if (!$json) {
158
+			return false;
159
+		} else {
160
+			return true;
161
+		}
162
+	}
163
+
164
+	/**
165
+	 * @param string $file
166
+	 *
167
+	 * @return bool
168
+	 */
169
+	protected function noVidation($file)
170
+	{
171
+		return true;
172
+	}
173
+
174
+	/**
175
+	 * Gets a list of absolute file paths.
176
+	 *
177
+	 * @return array
178
+	 */
179
+	protected function getFiles()
180
+	{
181
+		return glob($this->path);
182
+	}
183 183
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
     public function __construct($path, $fileTypeValidateFunc = 'noVidation', $checkType = null)
61 61
     {
62 62
         $this->path = $path;
63
-        $this->fileTypeValidateFunc = ($fileTypeValidateFunc)? $fileTypeValidateFunc:'noVidation';
63
+        $this->fileTypeValidateFunc = ($fileTypeValidateFunc) ? $fileTypeValidateFunc : 'noVidation';
64 64
         $this->checkType = ($checkType) ? $checkType : self::CHECK_SINGLE;
65 65
     }
66 66
 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
                 if ($this->checkType == self::CHECK_SINGLE && count($invalidFiles) < count($files)) {
94 94
                     $validFileList = "\n";
95 95
                     foreach ($validFiles as $vf) {
96
-                        $validFileList .= $vf."\n";
96
+                        $validFileList .= $vf . "\n";
97 97
                     }
98 98
                     if ($fileTypeValidateFunc == 'noVidation') {
99 99
                         $checkReturn = array(
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
                     } else {
113 113
                         $invalidFileList = "\n";
114 114
                         foreach ($invalidFiles as $vf) {
115
-                            $invalidFileList .= $vf."\n";
115
+                            $invalidFileList .= $vf . "\n";
116 116
                         }
117 117
 
118 118
                         if ($fileTypeValidateFunc == 'noVidation') {
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
                     }
130 130
                 }
131 131
             } else {
132
-                $checkReturn =  array(
132
+                $checkReturn = array(
133 133
                     EnvironmentCheck::ERROR,
134 134
                     sprintf("Invalid file type validation method name passed: %s ", $fileTypeValidateFunc)
135 135
                 );
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
47 47
     /**
48 48
      * @inheritdoc
49 49
      *
50
-     * @return array
50
+     * @return string[]
51 51
      */
52 52
     public function check()
53 53
     {
Please login to merge, or discard this patch.