Completed
Branch master (9dcfc4)
by Daniel
24:32
created
src/Checks/FileAccessibilityAndValidationCheck.php 1 patch
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.
src/Checks/URLCheck.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -14,50 +14,50 @@
 block discarded – undo
14 14
  */
15 15
 class URLCheck implements EnvironmentCheck
16 16
 {
17
-    /**
18
-     * @var string
19
-     */
20
-    protected $url;
17
+	/**
18
+	 * @var string
19
+	 */
20
+	protected $url;
21 21
 
22
-    /**
23
-     * @var string
24
-     */
25
-    protected $testString;
22
+	/**
23
+	 * @var string
24
+	 */
25
+	protected $testString;
26 26
 
27
-    /**
28
-     * @param string $url The URL to check, relative to the site (homepage is '').
29
-     * @param string $testString An optional piece of text to search for on the homepage.
30
-     */
31
-    public function __construct($url = '', $testString = '')
32
-    {
33
-        $this->url = $url;
34
-        $this->testString = $testString;
35
-    }
27
+	/**
28
+	 * @param string $url The URL to check, relative to the site (homepage is '').
29
+	 * @param string $testString An optional piece of text to search for on the homepage.
30
+	 */
31
+	public function __construct($url = '', $testString = '')
32
+	{
33
+		$this->url = $url;
34
+		$this->testString = $testString;
35
+	}
36 36
 
37
-    /**
38
-     * {@inheritDoc}
39
-     *
40
-     * @return array
41
-     * @throws HTTPResponse_Exception
42
-     */
43
-    public function check()
44
-    {
45
-        $response = Director::test($this->url);
37
+	/**
38
+	 * {@inheritDoc}
39
+	 *
40
+	 * @return array
41
+	 * @throws HTTPResponse_Exception
42
+	 */
43
+	public function check()
44
+	{
45
+		$response = Director::test($this->url);
46 46
 
47
-        if ($response->getStatusCode() != 200) {
48
-            return [
49
-                EnvironmentCheck::ERROR,
50
-                sprintf('Error retrieving "%s" (Code: %d)', $this->url, $response->getStatusCode())
51
-            ];
52
-        } elseif ($this->testString && (strpos($response->getBody(), $this->testString) === false)) {
53
-            return [
54
-                EnvironmentCheck::WARNING,
55
-                sprintf('Success retrieving "%s", but string "%s" not found', $this->url, $this->testString)
56
-            ];
57
-        }
58
-        return [
59
-            EnvironmentCheck::OK,
60
-            sprintf('Success retrieving "%s"', $this->url)
61
-        ];
62
-    }
47
+		if ($response->getStatusCode() != 200) {
48
+			return [
49
+				EnvironmentCheck::ERROR,
50
+				sprintf('Error retrieving "%s" (Code: %d)', $this->url, $response->getStatusCode())
51
+			];
52
+		} elseif ($this->testString && (strpos($response->getBody(), $this->testString) === false)) {
53
+			return [
54
+				EnvironmentCheck::WARNING,
55
+				sprintf('Success retrieving "%s", but string "%s" not found', $this->url, $this->testString)
56
+			];
57
+		}
58
+		return [
59
+			EnvironmentCheck::OK,
60
+			sprintf('Success retrieving "%s"', $this->url)
61
+		];
62
+	}
63 63
 }
Please login to merge, or discard this patch.
src/Checks/ExternalURLCheck.php 1 patch
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -16,118 +16,118 @@
 block discarded – undo
16 16
  */
17 17
 class ExternalURLCheck implements EnvironmentCheck
18 18
 {
19
-    /**
20
-     * @var array
21
-     */
22
-    protected $urls = [];
19
+	/**
20
+	 * @var array
21
+	 */
22
+	protected $urls = [];
23 23
 
24
-    /**
25
-     * @var Int Timeout in seconds.
26
-     */
27
-    protected $timeout;
24
+	/**
25
+	 * @var Int Timeout in seconds.
26
+	 */
27
+	protected $timeout;
28 28
 
29
-    /**
30
-     * @param string $urls Space-separated list of absolute URLs.
31
-     * @param int $timeout
32
-     */
33
-    public function __construct($urls, $timeout = 15)
34
-    {
35
-        if ($urls) {
36
-            $this->urls = explode(' ', $urls);
37
-        }
38
-        $this->timeout = $timeout;
39
-    }
29
+	/**
30
+	 * @param string $urls Space-separated list of absolute URLs.
31
+	 * @param int $timeout
32
+	 */
33
+	public function __construct($urls, $timeout = 15)
34
+	{
35
+		if ($urls) {
36
+			$this->urls = explode(' ', $urls);
37
+		}
38
+		$this->timeout = $timeout;
39
+	}
40 40
 
41
-    /**
42
-     * {@inheritDoc}
43
-     *
44
-     * @return array
45
-     */
46
-    public function check()
47
-    {
48
-        $urls = $this->getURLs();
41
+	/**
42
+	 * {@inheritDoc}
43
+	 *
44
+	 * @return array
45
+	 */
46
+	public function check()
47
+	{
48
+		$urls = $this->getURLs();
49 49
 
50
-        $chs = [];
51
-        foreach ($urls as $url) {
52
-            $ch = curl_init();
53
-            $chs[] = $ch;
54
-            curl_setopt_array($ch, $this->getCurlOpts($url));
55
-        }
56
-        // Parallel execution for faster performance
57
-        $mh = curl_multi_init();
58
-        foreach ($chs as $ch) {
59
-            curl_multi_add_handle($mh, $ch);
60
-        }
50
+		$chs = [];
51
+		foreach ($urls as $url) {
52
+			$ch = curl_init();
53
+			$chs[] = $ch;
54
+			curl_setopt_array($ch, $this->getCurlOpts($url));
55
+		}
56
+		// Parallel execution for faster performance
57
+		$mh = curl_multi_init();
58
+		foreach ($chs as $ch) {
59
+			curl_multi_add_handle($mh, $ch);
60
+		}
61 61
 
62
-        $active = null;
63
-        // Execute the handles
64
-        do {
65
-            $mrc = curl_multi_exec($mh, $active);
66
-            curl_multi_select($mh);
67
-        } while ($active > 0);
62
+		$active = null;
63
+		// Execute the handles
64
+		do {
65
+			$mrc = curl_multi_exec($mh, $active);
66
+			curl_multi_select($mh);
67
+		} while ($active > 0);
68 68
 
69
-        while ($active && $mrc == CURLM_OK) {
70
-            if (curl_multi_select($mh) != -1) {
71
-                do {
72
-                    $mrc = curl_multi_exec($mh, $active);
73
-                } while ($mrc == CURLM_CALL_MULTI_PERFORM);
74
-            }
75
-        }
69
+		while ($active && $mrc == CURLM_OK) {
70
+			if (curl_multi_select($mh) != -1) {
71
+				do {
72
+					$mrc = curl_multi_exec($mh, $active);
73
+				} while ($mrc == CURLM_CALL_MULTI_PERFORM);
74
+			}
75
+		}
76 76
 
77
-        $hasError = false;
78
-        $msgs = [];
79
-        foreach ($chs as $ch) {
80
-            $url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
81
-            $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
82
-            if (curl_errno($ch) || $code >= 400) {
83
-                $hasError = true;
84
-                $msgs[] = sprintf(
85
-                    'Error retrieving "%s": %s (Code: %s)',
86
-                    $url,
87
-                    curl_error($ch),
88
-                    $code
89
-                );
90
-            } else {
91
-                $msgs[] = sprintf(
92
-                    'Success retrieving "%s" (Code: %s)',
93
-                    $url,
94
-                    $code
95
-                );
96
-            }
97
-        }
77
+		$hasError = false;
78
+		$msgs = [];
79
+		foreach ($chs as $ch) {
80
+			$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
81
+			$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
82
+			if (curl_errno($ch) || $code >= 400) {
83
+				$hasError = true;
84
+				$msgs[] = sprintf(
85
+					'Error retrieving "%s": %s (Code: %s)',
86
+					$url,
87
+					curl_error($ch),
88
+					$code
89
+				);
90
+			} else {
91
+				$msgs[] = sprintf(
92
+					'Success retrieving "%s" (Code: %s)',
93
+					$url,
94
+					$code
95
+				);
96
+			}
97
+		}
98 98
 
99
-        // Close the handles
100
-        foreach ($chs as $ch) {
101
-            curl_multi_remove_handle($mh, $ch);
102
-        }
103
-        curl_multi_close($mh);
99
+		// Close the handles
100
+		foreach ($chs as $ch) {
101
+			curl_multi_remove_handle($mh, $ch);
102
+		}
103
+		curl_multi_close($mh);
104 104
 
105
-        if ($hasError) {
106
-            return [EnvironmentCheck::ERROR, implode(', ', $msgs)];
107
-        }
105
+		if ($hasError) {
106
+			return [EnvironmentCheck::ERROR, implode(', ', $msgs)];
107
+		}
108 108
 
109
-        return [EnvironmentCheck::OK, implode(', ', $msgs)];
110
-    }
109
+		return [EnvironmentCheck::OK, implode(', ', $msgs)];
110
+	}
111 111
 
112
-    /**
113
-     * @return array
114
-     */
115
-    protected function getCurlOpts($url)
116
-    {
117
-        return [
118
-            CURLOPT_URL => $url,
119
-            CURLOPT_HEADER => 0,
120
-            CURLOPT_RETURNTRANSFER => 1,
121
-            CURLOPT_FAILONERROR => 1,
122
-            CURLOPT_TIMEOUT => $this->timeout,
123
-        ];
124
-    }
112
+	/**
113
+	 * @return array
114
+	 */
115
+	protected function getCurlOpts($url)
116
+	{
117
+		return [
118
+			CURLOPT_URL => $url,
119
+			CURLOPT_HEADER => 0,
120
+			CURLOPT_RETURNTRANSFER => 1,
121
+			CURLOPT_FAILONERROR => 1,
122
+			CURLOPT_TIMEOUT => $this->timeout,
123
+		];
124
+	}
125 125
 
126
-    /**
127
-     * @return array
128
-     */
129
-    protected function getURLs()
130
-    {
131
-        return $this->urls;
132
-    }
126
+	/**
127
+	 * @return array
128
+	 */
129
+	protected function getURLs()
130
+	{
131
+		return $this->urls;
132
+	}
133 133
 }
Please login to merge, or discard this patch.
src/Checks/FileAgeCheck.php 1 patch
Indentation   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -28,124 +28,124 @@
 block discarded – undo
28 28
  */
29 29
 class FileAgeCheck implements EnvironmentCheck
30 30
 {
31
-    /**
32
-     * @var int
33
-     */
34
-    const CHECK_SINGLE = 1;
31
+	/**
32
+	 * @var int
33
+	 */
34
+	const CHECK_SINGLE = 1;
35 35
 
36
-    /**
37
-     * @var int
38
-     */
39
-    const CHECK_ALL = 2;
36
+	/**
37
+	 * @var int
38
+	 */
39
+	const CHECK_ALL = 2;
40 40
 
41
-    /**
42
-     * Absolute path to a file or folder, compatible with glob().
43
-     *
44
-     * @var string
45
-     */
46
-    protected $path;
41
+	/**
42
+	 * Absolute path to a file or folder, compatible with glob().
43
+	 *
44
+	 * @var string
45
+	 */
46
+	protected $path;
47 47
 
48
-    /**
49
-     * Relative date specification, compatible with strtotime().
50
-     *
51
-     * @var string
52
-     */
53
-    protected $relativeAge;
48
+	/**
49
+	 * Relative date specification, compatible with strtotime().
50
+	 *
51
+	 * @var string
52
+	 */
53
+	protected $relativeAge;
54 54
 
55
-    /**
56
-     * The function to use for checking file age: so filemtime(), filectime(), or fileatime().
57
-     *
58
-     * @var string
59
-     */
60
-    protected $checkFn;
55
+	/**
56
+	 * The function to use for checking file age: so filemtime(), filectime(), or fileatime().
57
+	 *
58
+	 * @var string
59
+	 */
60
+	protected $checkFn;
61 61
 
62
-    /**
63
-     * Constant, check for a single file to match age criteria, or all of them.
64
-     *
65
-     * @var int
66
-     */
67
-    protected $checkType;
62
+	/**
63
+	 * Constant, check for a single file to match age criteria, or all of them.
64
+	 *
65
+	 * @var int
66
+	 */
67
+	protected $checkType;
68 68
 
69
-    /**
70
-     * Type of comparison (either > or <).
71
-     *
72
-     * @var string
73
-     */
74
-    protected $compareOperand;
69
+	/**
70
+	 * Type of comparison (either > or <).
71
+	 *
72
+	 * @var string
73
+	 */
74
+	protected $compareOperand;
75 75
 
76
-    /**
77
-     * @param string $path
78
-     * @param string $relativeAge
79
-     * @param string $compareOperand
80
-     * @param null|int $checkType
81
-     * @param string $checkFn
82
-     */
83
-    public function __construct($path, $relativeAge, $compareOperand = '>', $checkType = null, $checkFn = 'filemtime')
84
-    {
85
-        $this->path = $path;
86
-        $this->relativeAge = $relativeAge;
87
-        $this->checkFn = $checkFn;
88
-        $this->checkType = ($checkType) ? $checkType : self::CHECK_SINGLE;
89
-        $this->compareOperand = $compareOperand;
90
-    }
76
+	/**
77
+	 * @param string $path
78
+	 * @param string $relativeAge
79
+	 * @param string $compareOperand
80
+	 * @param null|int $checkType
81
+	 * @param string $checkFn
82
+	 */
83
+	public function __construct($path, $relativeAge, $compareOperand = '>', $checkType = null, $checkFn = 'filemtime')
84
+	{
85
+		$this->path = $path;
86
+		$this->relativeAge = $relativeAge;
87
+		$this->checkFn = $checkFn;
88
+		$this->checkType = ($checkType) ? $checkType : self::CHECK_SINGLE;
89
+		$this->compareOperand = $compareOperand;
90
+	}
91 91
 
92
-    /**
93
-     * {@inheritDoc}
94
-     *
95
-     * @return array
96
-     */
97
-    public function check()
98
-    {
99
-        $cutoffTime =  strtotime($this->relativeAge, DBDatetime::now()->Format('U'));
100
-        $files = $this->getFiles();
101
-        $invalidFiles = [];
102
-        $validFiles = [];
103
-        $checkFn = $this->checkFn;
104
-        $allValid = true;
105
-        if ($files) {
106
-            foreach ($files as $file) {
107
-                $fileTime = $checkFn($file);
108
-                $valid = ($this->compareOperand == '>') ? ($fileTime >= $cutoffTime) : ($fileTime <= $cutoffTime);
109
-                if ($valid) {
110
-                    $validFiles[] = $file;
111
-                } else {
112
-                    $invalidFiles[] = $file;
113
-                    if ($this->checkType == self::CHECK_ALL) {
114
-                        return [
115
-                            EnvironmentCheck::ERROR,
116
-                            sprintf(
117
-                                'File "%s" doesn\'t match age check (compare %s: %s, actual: %s)',
118
-                                $file,
119
-                                $this->compareOperand,
120
-                                date('c', $cutoffTime),
121
-                                date('c', $fileTime)
122
-                            )
123
-                        ];
124
-                    }
125
-                }
126
-            }
127
-        }
92
+	/**
93
+	 * {@inheritDoc}
94
+	 *
95
+	 * @return array
96
+	 */
97
+	public function check()
98
+	{
99
+		$cutoffTime =  strtotime($this->relativeAge, DBDatetime::now()->Format('U'));
100
+		$files = $this->getFiles();
101
+		$invalidFiles = [];
102
+		$validFiles = [];
103
+		$checkFn = $this->checkFn;
104
+		$allValid = true;
105
+		if ($files) {
106
+			foreach ($files as $file) {
107
+				$fileTime = $checkFn($file);
108
+				$valid = ($this->compareOperand == '>') ? ($fileTime >= $cutoffTime) : ($fileTime <= $cutoffTime);
109
+				if ($valid) {
110
+					$validFiles[] = $file;
111
+				} else {
112
+					$invalidFiles[] = $file;
113
+					if ($this->checkType == self::CHECK_ALL) {
114
+						return [
115
+							EnvironmentCheck::ERROR,
116
+							sprintf(
117
+								'File "%s" doesn\'t match age check (compare %s: %s, actual: %s)',
118
+								$file,
119
+								$this->compareOperand,
120
+								date('c', $cutoffTime),
121
+								date('c', $fileTime)
122
+							)
123
+						];
124
+					}
125
+				}
126
+			}
127
+		}
128 128
 
129
-        // If at least one file was valid, count as passed
130
-        if ($this->checkType == self::CHECK_SINGLE && count($invalidFiles) < count($files)) {
131
-            return [EnvironmentCheck::OK, ''];
132
-        }
133
-        if (count($invalidFiles) == 0) {
134
-            return [EnvironmentCheck::OK, ''];
135
-        }
136
-        return [
137
-            EnvironmentCheck::ERROR,
138
-            sprintf('No files matched criteria (%s %s)', $this->compareOperand, date('c', $cutoffTime))
139
-        ];
140
-    }
129
+		// If at least one file was valid, count as passed
130
+		if ($this->checkType == self::CHECK_SINGLE && count($invalidFiles) < count($files)) {
131
+			return [EnvironmentCheck::OK, ''];
132
+		}
133
+		if (count($invalidFiles) == 0) {
134
+			return [EnvironmentCheck::OK, ''];
135
+		}
136
+		return [
137
+			EnvironmentCheck::ERROR,
138
+			sprintf('No files matched criteria (%s %s)', $this->compareOperand, date('c', $cutoffTime))
139
+		];
140
+	}
141 141
 
142
-    /**
143
-     * Gets a list of absolute file paths.
144
-     *
145
-     * @return array
146
-     */
147
-    protected function getFiles()
148
-    {
149
-        return glob($this->path);
150
-    }
142
+	/**
143
+	 * Gets a list of absolute file paths.
144
+	 *
145
+	 * @return array
146
+	 */
147
+	protected function getFiles()
148
+	{
149
+		return glob($this->path);
150
+	}
151 151
 }
Please login to merge, or discard this patch.
src/Checks/HasClassCheck.php 1 patch
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 HasClassCheck implements EnvironmentCheck
13 13
 {
14
-    /**
15
-     * @var string
16
-     */
17
-    protected $className;
14
+	/**
15
+	 * @var string
16
+	 */
17
+	protected $className;
18 18
 
19
-    /**
20
-     * @param string $className The name of the class to look for.
21
-     */
22
-    public function __construct($className)
23
-    {
24
-        $this->className = $className;
25
-    }
19
+	/**
20
+	 * @param string $className The name of the class to look for.
21
+	 */
22
+	public function __construct($className)
23
+	{
24
+		$this->className = $className;
25
+	}
26 26
 
27
-    /**
28
-     * {@inheritDoc}
29
-     *
30
-     * @return array
31
-     */
32
-    public function check()
33
-    {
34
-        if (class_exists($this->className)) {
35
-            return [EnvironmentCheck::OK, 'Class ' . $this->className.' exists'];
36
-        }
37
-        return [EnvironmentCheck::ERROR, 'Class ' . $this->className.' doesn\'t exist'];
38
-    }
27
+	/**
28
+	 * {@inheritDoc}
29
+	 *
30
+	 * @return array
31
+	 */
32
+	public function check()
33
+	{
34
+		if (class_exists($this->className)) {
35
+			return [EnvironmentCheck::OK, 'Class ' . $this->className.' exists'];
36
+		}
37
+		return [EnvironmentCheck::ERROR, 'Class ' . $this->className.' doesn\'t exist'];
38
+	}
39 39
 }
Please login to merge, or discard this patch.
src/Checks/FileWriteableCheck.php 1 patch
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -11,77 +11,77 @@
 block discarded – undo
11 11
  */
12 12
 class FileWriteableCheck implements EnvironmentCheck
13 13
 {
14
-    /**
15
-     * @var string
16
-     */
17
-    protected $path;
14
+	/**
15
+	 * @var string
16
+	 */
17
+	protected $path;
18 18
 
19
-    /**
20
-     * @param string $path The full path. If a relative path, it will relative to the BASE_PATH.
21
-     */
22
-    public function __construct($path)
23
-    {
24
-        $this->path = $path;
25
-    }
19
+	/**
20
+	 * @param string $path The full path. If a relative path, it will relative to the BASE_PATH.
21
+	 */
22
+	public function __construct($path)
23
+	{
24
+		$this->path = $path;
25
+	}
26 26
 
27
-    /**
28
-     * {@inheritDoc}
29
-     *
30
-     * @return array
31
-     */
32
-    public function check()
33
-    {
34
-        if ($this->path[0] == '/') {
35
-            $filename = $this->path;
36
-        } else {
37
-            $filename = BASE_PATH . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $this->path);
38
-        }
27
+	/**
28
+	 * {@inheritDoc}
29
+	 *
30
+	 * @return array
31
+	 */
32
+	public function check()
33
+	{
34
+		if ($this->path[0] == '/') {
35
+			$filename = $this->path;
36
+		} else {
37
+			$filename = BASE_PATH . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $this->path);
38
+		}
39 39
 
40
-        if (file_exists($filename)) {
41
-            $isWriteable = is_writeable($filename);
42
-        } else {
43
-            $isWriteable = is_writeable(dirname($filename));
44
-        }
40
+		if (file_exists($filename)) {
41
+			$isWriteable = is_writeable($filename);
42
+		} else {
43
+			$isWriteable = is_writeable(dirname($filename));
44
+		}
45 45
 
46
-        if (!$isWriteable) {
47
-            if (function_exists('posix_getgroups')) {
48
-                $userID = posix_geteuid();
49
-                $user = posix_getpwuid($userID);
46
+		if (!$isWriteable) {
47
+			if (function_exists('posix_getgroups')) {
48
+				$userID = posix_geteuid();
49
+				$user = posix_getpwuid($userID);
50 50
 
51
-                $currentOwnerID = fileowner(file_exists($filename) ? $filename : dirname($filename));
52
-                $currentOwner = posix_getpwuid($currentOwnerID);
51
+				$currentOwnerID = fileowner(file_exists($filename) ? $filename : dirname($filename));
52
+				$currentOwner = posix_getpwuid($currentOwnerID);
53 53
 
54
-                $message = "User '$user[name]' needs to be able to write to this file:\n$filename\n\nThe file is "
55
-                    . "currently owned by '$currentOwner[name]'.  ";
54
+				$message = "User '$user[name]' needs to be able to write to this file:\n$filename\n\nThe file is "
55
+					. "currently owned by '$currentOwner[name]'.  ";
56 56
 
57
-                if ($user['name'] == $currentOwner['name']) {
58
-                    $message .= 'We recommend that you make the file writeable.';
59
-                } else {
60
-                    $groups = posix_getgroups();
61
-                    $groupList = [];
62
-                    foreach ($groups as $group) {
63
-                        $groupInfo = posix_getgrgid($group);
64
-                        if (in_array($currentOwner['name'], $groupInfo['members'])) {
65
-                            $groupList[] = $groupInfo['name'];
66
-                        }
67
-                    }
68
-                    if ($groupList) {
69
-                        $message .= "	We recommend that you make the file group-writeable and change the group to "
70
-                            . "one of these groups:\n - " . implode("\n - ", $groupList)
71
-                            . "\n\nFor example:\nchmod g+w $filename\nchgrp " . $groupList[0] . " $filename";
72
-                    } else {
73
-                        $message .= "  There is no user-group that contains both the web-server user and the owner "
74
-                            . "of this file.  Change the ownership of the file, create a new group, or temporarily "
75
-                            . "make the file writeable by everyone during the install process.";
76
-                    }
77
-                }
78
-            } else {
79
-                $message = "The webserver user needs to be able to write to this file:\n$filename";
80
-            }
57
+				if ($user['name'] == $currentOwner['name']) {
58
+					$message .= 'We recommend that you make the file writeable.';
59
+				} else {
60
+					$groups = posix_getgroups();
61
+					$groupList = [];
62
+					foreach ($groups as $group) {
63
+						$groupInfo = posix_getgrgid($group);
64
+						if (in_array($currentOwner['name'], $groupInfo['members'])) {
65
+							$groupList[] = $groupInfo['name'];
66
+						}
67
+					}
68
+					if ($groupList) {
69
+						$message .= "	We recommend that you make the file group-writeable and change the group to "
70
+							. "one of these groups:\n - " . implode("\n - ", $groupList)
71
+							. "\n\nFor example:\nchmod g+w $filename\nchgrp " . $groupList[0] . " $filename";
72
+					} else {
73
+						$message .= "  There is no user-group that contains both the web-server user and the owner "
74
+							. "of this file.  Change the ownership of the file, create a new group, or temporarily "
75
+							. "make the file writeable by everyone during the install process.";
76
+					}
77
+				}
78
+			} else {
79
+				$message = "The webserver user needs to be able to write to this file:\n$filename";
80
+			}
81 81
 
82
-            return [EnvironmentCheck::ERROR, $message];
83
-        }
82
+			return [EnvironmentCheck::ERROR, $message];
83
+		}
84 84
 
85
-        return [EnvironmentCheck::OK, ''];
86
-    }
85
+		return [EnvironmentCheck::OK, ''];
86
+	}
87 87
 }
Please login to merge, or discard this patch.
tests/Controllers/DevHealthControllerTest.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -16,27 +16,27 @@
 block discarded – undo
16 16
  */
17 17
 class DevHealthControllerTest extends SapphireTest
18 18
 {
19
-    /**
20
-     * {@inheritDoc}
21
-     * @var array
22
-     */
23
-    protected $usesDatabase = true;
19
+	/**
20
+	 * {@inheritDoc}
21
+	 * @var array
22
+	 */
23
+	protected $usesDatabase = true;
24 24
 
25
-    public function testIndexCreatesChecker()
26
-    {
27
-        $controller = new DevHealthController();
25
+	public function testIndexCreatesChecker()
26
+	{
27
+		$controller = new DevHealthController();
28 28
 
29
-        $request = new HTTPRequest('GET', 'example.com');
29
+		$request = new HTTPRequest('GET', 'example.com');
30 30
 
31
-        // we need to fake authenticated access as BasicAuth::requireLogin doesn't like empty
32
-        // permission type strings, which is what health check uses.
31
+		// we need to fake authenticated access as BasicAuth::requireLogin doesn't like empty
32
+		// permission type strings, which is what health check uses.
33 33
 
34
-        putenv('ENVCHECK_BASICAUTH_USERNAME="foo"');
35
-        putenv('ENVCHECK_BASICAUTH_PASSWORD="bar"');
34
+		putenv('ENVCHECK_BASICAUTH_USERNAME="foo"');
35
+		putenv('ENVCHECK_BASICAUTH_PASSWORD="bar"');
36 36
 
37
-        $_SERVER['PHP_AUTH_USER'] = 'foo';
38
-        $_SERVER['PHP_AUTH_PW'] = 'bar';
37
+		$_SERVER['PHP_AUTH_USER'] = 'foo';
38
+		$_SERVER['PHP_AUTH_PW'] = 'bar';
39 39
 
40
-        $this->assertInstanceOf(EnvironmentChecker::class, $controller->index($request));
41
-    }
40
+		$this->assertInstanceOf(EnvironmentChecker::class, $controller->index($request));
41
+	}
42 42
 }
Please login to merge, or discard this patch.
tests/Controllers/DevCheckControllerTest.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -16,18 +16,18 @@
 block discarded – undo
16 16
  */
17 17
 class DevCheckControllerTest extends SapphireTest
18 18
 {
19
-    /**
20
-     * {@inheritDoc}
21
-     * @var array
22
-     */
23
-    protected $usesDatabase = true;
19
+	/**
20
+	 * {@inheritDoc}
21
+	 * @var array
22
+	 */
23
+	protected $usesDatabase = true;
24 24
 
25
-    public function testIndexCreatesChecker()
26
-    {
27
-        $controller = new DevCheckController();
25
+	public function testIndexCreatesChecker()
26
+	{
27
+		$controller = new DevCheckController();
28 28
 
29
-        $request = new HTTPRequest('GET', 'example.com');
29
+		$request = new HTTPRequest('GET', 'example.com');
30 30
 
31
-        $this->assertInstanceOf(EnvironmentChecker::class, $controller->index($request));
32
-    }
31
+		$this->assertInstanceOf(EnvironmentChecker::class, $controller->index($request));
32
+	}
33 33
 }
Please login to merge, or discard this patch.
tests/EnvironmentCheckerTest.php 1 patch
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -19,119 +19,119 @@
 block discarded – undo
19 19
  */
20 20
 class EnvironmentCheckerTest extends SapphireTest
21 21
 {
22
-    /**
23
-     * {@inheritDoc}
24
-     * @var bool
25
-     */
26
-    protected $usesDatabase = true;
27
-
28
-    /**
29
-     * {@inheritDoc}
30
-     */
31
-    public static function setUpBeforeClass()
32
-    {
33
-        parent::setUpBeforeClass();
34
-
35
-        Phockito::include_hamcrest();
36
-
37
-        $logger = Injector::inst()->get(LoggerInterface::class);
38
-        if ($logger instanceof \Monolog\Logger) {
39
-            // It logs to stderr by default - disable
40
-            $logger->pushHandler(new \Monolog\Handler\NullHandler);
41
-        }
42
-    }
43
-
44
-    /**
45
-     * {@inheritDoc}
46
-     */
47
-    public function setUp()
48
-    {
49
-        parent::setUp();
50
-        Config::nest();
51
-    }
52
-
53
-    /**
54
-     * {@inheritDoc}
55
-     */
56
-    public function tearDown()
57
-    {
58
-        Config::unnest();
59
-        parent::tearDown();
60
-    }
61
-
62
-    public function testOnlyLogsWithErrors()
63
-    {
64
-        Config::modify()->set(EnvironmentChecker::class, 'log_results_warning', true);
65
-        Config::modify()->set(EnvironmentChecker::class, 'log_results_error', true);
66
-        EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckNoErrors());
67
-        $checker = Phockito::spy(
68
-            EnvironmentChecker::class,
69
-            'test suite',
70
-            'test'
71
-        );
72
-
73
-        $response = $checker->index();
74
-        Phockito::verify($checker, 0)->log(\anything(), \anything());
75
-        EnvironmentCheckSuite::reset();
76
-    }
77
-
78
-    public function testLogsWithWarnings()
79
-    {
80
-        Config::modify()->set(EnvironmentChecker::class, 'log_results_warning', true);
81
-        Config::modify()->set(EnvironmentChecker::class, 'log_results_error', false);
82
-        EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckWarnings());
83
-        EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckErrors());
84
-        $checker = Phockito::spy(
85
-            EnvironmentChecker::class,
86
-            'test suite',
87
-            'test'
88
-        );
89
-
90
-        $response = $checker->index();
91
-        Phockito::verify($checker, 1)->log(containsString('warning'), \anything());
92
-        Phockito::verify($checker, 0)->log(containsString('error'), \anything());
93
-        EnvironmentCheckSuite::reset();
94
-    }
95
-
96
-    public function testLogsWithErrors()
97
-    {
98
-        Config::modify()->set(EnvironmentChecker::class, 'log_results_error', false);
99
-        Config::modify()->set(EnvironmentChecker::class, 'log_results_error', true);
100
-        EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckWarnings());
101
-        EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckErrors());
102
-        $checker = Phockito::spy(
103
-            EnvironmentChecker::class,
104
-            'test suite',
105
-            'test'
106
-        );
107
-
108
-        $response = $checker->index();
109
-        Phockito::verify($checker, 0)->log(containsString('warning'), \anything());
110
-        Phockito::verify($checker, 1)->log(containsString('error'), \anything());
111
-        EnvironmentCheckSuite::reset();
112
-    }
22
+	/**
23
+	 * {@inheritDoc}
24
+	 * @var bool
25
+	 */
26
+	protected $usesDatabase = true;
27
+
28
+	/**
29
+	 * {@inheritDoc}
30
+	 */
31
+	public static function setUpBeforeClass()
32
+	{
33
+		parent::setUpBeforeClass();
34
+
35
+		Phockito::include_hamcrest();
36
+
37
+		$logger = Injector::inst()->get(LoggerInterface::class);
38
+		if ($logger instanceof \Monolog\Logger) {
39
+			// It logs to stderr by default - disable
40
+			$logger->pushHandler(new \Monolog\Handler\NullHandler);
41
+		}
42
+	}
43
+
44
+	/**
45
+	 * {@inheritDoc}
46
+	 */
47
+	public function setUp()
48
+	{
49
+		parent::setUp();
50
+		Config::nest();
51
+	}
52
+
53
+	/**
54
+	 * {@inheritDoc}
55
+	 */
56
+	public function tearDown()
57
+	{
58
+		Config::unnest();
59
+		parent::tearDown();
60
+	}
61
+
62
+	public function testOnlyLogsWithErrors()
63
+	{
64
+		Config::modify()->set(EnvironmentChecker::class, 'log_results_warning', true);
65
+		Config::modify()->set(EnvironmentChecker::class, 'log_results_error', true);
66
+		EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckNoErrors());
67
+		$checker = Phockito::spy(
68
+			EnvironmentChecker::class,
69
+			'test suite',
70
+			'test'
71
+		);
72
+
73
+		$response = $checker->index();
74
+		Phockito::verify($checker, 0)->log(\anything(), \anything());
75
+		EnvironmentCheckSuite::reset();
76
+	}
77
+
78
+	public function testLogsWithWarnings()
79
+	{
80
+		Config::modify()->set(EnvironmentChecker::class, 'log_results_warning', true);
81
+		Config::modify()->set(EnvironmentChecker::class, 'log_results_error', false);
82
+		EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckWarnings());
83
+		EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckErrors());
84
+		$checker = Phockito::spy(
85
+			EnvironmentChecker::class,
86
+			'test suite',
87
+			'test'
88
+		);
89
+
90
+		$response = $checker->index();
91
+		Phockito::verify($checker, 1)->log(containsString('warning'), \anything());
92
+		Phockito::verify($checker, 0)->log(containsString('error'), \anything());
93
+		EnvironmentCheckSuite::reset();
94
+	}
95
+
96
+	public function testLogsWithErrors()
97
+	{
98
+		Config::modify()->set(EnvironmentChecker::class, 'log_results_error', false);
99
+		Config::modify()->set(EnvironmentChecker::class, 'log_results_error', true);
100
+		EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckWarnings());
101
+		EnvironmentCheckSuite::register('test suite', new EnvironmentCheckerTest_CheckErrors());
102
+		$checker = Phockito::spy(
103
+			EnvironmentChecker::class,
104
+			'test suite',
105
+			'test'
106
+		);
107
+
108
+		$response = $checker->index();
109
+		Phockito::verify($checker, 0)->log(containsString('warning'), \anything());
110
+		Phockito::verify($checker, 1)->log(containsString('error'), \anything());
111
+		EnvironmentCheckSuite::reset();
112
+	}
113 113
 }
114 114
 
115 115
 class EnvironmentCheckerTest_CheckNoErrors implements EnvironmentCheck, TestOnly
116 116
 {
117
-    public function check()
118
-    {
119
-        return [EnvironmentCheck::OK, ''];
120
-    }
117
+	public function check()
118
+	{
119
+		return [EnvironmentCheck::OK, ''];
120
+	}
121 121
 }
122 122
 
123 123
 class EnvironmentCheckerTest_CheckWarnings implements EnvironmentCheck, TestOnly
124 124
 {
125
-    public function check()
126
-    {
127
-        return [EnvironmentCheck::WARNING, 'test warning'];
128
-    }
125
+	public function check()
126
+	{
127
+		return [EnvironmentCheck::WARNING, 'test warning'];
128
+	}
129 129
 }
130 130
 
131 131
 class EnvironmentCheckerTest_CheckErrors implements EnvironmentCheck, TestOnly
132 132
 {
133
-    public function check()
134
-    {
135
-        return [EnvironmentCheck::ERROR, 'test error'];
136
-    }
133
+	public function check()
134
+	{
135
+		return [EnvironmentCheck::ERROR, 'test error'];
136
+	}
137 137
 }
Please login to merge, or discard this patch.