@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | $this->setHeaders(); |
129 | 129 | |
130 | 130 | // Check security token |
131 | - if(self::config()->enable_security_token && !SecurityToken::inst()->checkRequest($this->request)) { |
|
131 | + if (self::config()->enable_security_token && !SecurityToken::inst()->checkRequest($this->request)) { |
|
132 | 132 | return $this->error( |
133 | 133 | _t( |
134 | 134 | 'SpellController.SecurityMissing', |
@@ -140,31 +140,31 @@ discard block |
||
140 | 140 | |
141 | 141 | // Check permission |
142 | 142 | $permission = self::config()->required_permission; |
143 | - if($permission && !Permission::check($permission)) { |
|
143 | + if ($permission && !Permission::check($permission)) { |
|
144 | 144 | return $this->error(_t('SpellController.SecurityDenied', 'Permission Denied'), 403); |
145 | 145 | } |
146 | 146 | |
147 | 147 | // Check data |
148 | 148 | $data = $this->getRequestData(); |
149 | - if(empty($data)) { |
|
149 | + if (empty($data)) { |
|
150 | 150 | return $this->error(_t('SpellController.MissingData', "Could not get raw post data"), 400); |
151 | 151 | } |
152 | 152 | |
153 | 153 | // Check params and request type |
154 | - if(!Director::is_ajax() || empty($data['method']) || empty($data['params']) || count($data['params']) < 2) { |
|
154 | + if (!Director::is_ajax() || empty($data['method']) || empty($data['params']) || count($data['params']) < 2) { |
|
155 | 155 | return $this->error(_t('SpellController.InvalidRequest', 'Invalid request'), 400); |
156 | 156 | } |
157 | 157 | |
158 | 158 | // Check locale |
159 | 159 | $params = $data['params']; |
160 | 160 | $locale = $params[0]; |
161 | - if(!in_array($locale, self::get_locales())) { |
|
161 | + if (!in_array($locale, self::get_locales())) { |
|
162 | 162 | return $this->error(_t('SpellController.InvalidLocale', 'Not supported locale'), 400); |
163 | 163 | } |
164 | 164 | |
165 | 165 | // Check provider |
166 | 166 | $provider = $this->getProvider(); |
167 | - if(empty($provider)) { |
|
167 | + if (empty($provider)) { |
|
168 | 168 | return $this->error(_t('SpellController.MissingProviders', "No spellcheck module installed"), 500); |
169 | 169 | } |
170 | 170 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | try { |
173 | 173 | $method = $data['method']; |
174 | 174 | $words = $params[1]; |
175 | - switch($method) { |
|
175 | + switch ($method) { |
|
176 | 176 | case 'checkWords': |
177 | 177 | return $this->success($provider->checkWords($locale, $words)); |
178 | 178 | case 'getSuggestions': |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | 400 |
188 | 188 | ); |
189 | 189 | } |
190 | - } catch(SpellException $ex) { |
|
190 | + } catch (SpellException $ex) { |
|
191 | 191 | return $this->error($ex->getMessage(), $ex->getCode()); |
192 | 192 | } |
193 | 193 | } |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | */ |
213 | 213 | protected function getRequestData() { |
214 | 214 | // Check if data needs to be parsed |
215 | - if($this->data === null) { |
|
215 | + if ($this->data === null) { |
|
216 | 216 | // Parse data from input |
217 | 217 | $result = $this->request->requestVar('json_data') |
218 | 218 | ?: file_get_contents("php://input"); |
@@ -13,7 +13,7 @@ |
||
13 | 13 | public function preRequest(\SS_HTTPRequest $request, \Session $session, \DataModel $model) { |
14 | 14 | // Check languages to set |
15 | 15 | $languages = array(); |
16 | - foreach(SpellController::get_locales() as $locale) { |
|
16 | + foreach (SpellController::get_locales() as $locale) { |
|
17 | 17 | $languages[] = i18n::get_locale_name($locale).'='.$locale; |
18 | 18 | } |
19 | 19 |
@@ -25,14 +25,14 @@ discard block |
||
25 | 25 | */ |
26 | 26 | protected function invoke($locale, $input, &$stdout, &$stderr) { |
27 | 27 | // Prepare arguments |
28 | - $command = 'hunspell -d ' . escapeshellarg($locale); |
|
28 | + $command = 'hunspell -d '.escapeshellarg($locale); |
|
29 | 29 | $descriptorSpecs = array( |
30 | 30 | 0 => array("pipe", "r"), |
31 | 31 | 1 => array("pipe", "w"), |
32 | 32 | 2 => array("pipe", "w") |
33 | 33 | ); |
34 | 34 | $env = array( |
35 | - 'LANG' => $locale . '.utf-8' |
|
35 | + 'LANG' => $locale.'.utf-8' |
|
36 | 36 | ); |
37 | 37 | // Invoke command |
38 | 38 | $proc = proc_open($command, $descriptorSpecs, $pipes, null, $env); |
@@ -64,17 +64,17 @@ discard block |
||
64 | 64 | // Invoke HunSpell |
65 | 65 | $input = implode(' ', $words); |
66 | 66 | $return = $this->invoke($locale, $input, $stdout, $stderr); |
67 | - if($stderr) { |
|
67 | + if ($stderr) { |
|
68 | 68 | throw new SpellException($stderr, 500); |
69 | - } elseif($return) { |
|
69 | + } elseif ($return) { |
|
70 | 70 | throw new SpellException("An unidentified error has occurred", 500); |
71 | 71 | } |
72 | 72 | |
73 | 73 | // Parse results |
74 | 74 | $pattern = Config::inst()->get(__CLASS__, 'pattern'); |
75 | 75 | $results = array(); |
76 | - foreach(preg_split('/$\R?^/m', $stdout) as $line) { |
|
77 | - if(preg_match($pattern, $line, $matches)) { |
|
76 | + foreach (preg_split('/$\R?^/m', $stdout) as $line) { |
|
77 | + if (preg_match($pattern, $line, $matches)) { |
|
78 | 78 | $results[$matches['original']] = explode(', ', $matches['misses']); |
79 | 79 | } |
80 | 80 | } |
@@ -88,6 +88,6 @@ discard block |
||
88 | 88 | |
89 | 89 | public function getSuggestions($locale, $word) { |
90 | 90 | $results = $this->getResults($locale, array($word)); |
91 | - if(isset($results[$word])) return $results[$word]; |
|
91 | + if (isset($results[$word])) return $results[$word]; |
|
92 | 92 | } |
93 | 93 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | } |
53 | 53 | |
54 | 54 | public function tearDown() { |
55 | - if($this->securityWasEnabled) SecurityToken::enable(); |
|
55 | + if ($this->securityWasEnabled) SecurityToken::enable(); |
|
56 | 56 | else SecurityToken::disable(); |
57 | 57 | Injector::unnest(); |
58 | 58 | Config::unnest(); |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | ) |
145 | 145 | ); |
146 | 146 | $response = $this->post('spellcheck', array('ajax' => 1, 'json_data' => json_encode($dataCheckWords))); |
147 | - $this->assertEquals(200, $response->getStatusCode()); |
|
147 | + $this->assertEquals(200, $response->getStatusCode()); |
|
148 | 148 | $jsonBody = json_decode($response->getBody()); |
149 | 149 | $this->assertEquals('c0', $jsonBody->id); |
150 | 150 | $this->assertEquals(array("collor", "color", "onee"), $jsonBody->result); |
@@ -160,14 +160,14 @@ discard block |
||
160 | 160 | ) |
161 | 161 | ); |
162 | 162 | $response = $this->post('spellcheck', array('ajax' => 1, 'json_data' => json_encode($dataGetSuggestions))); |
163 | - $this->assertEquals(200, $response->getStatusCode()); |
|
163 | + $this->assertEquals(200, $response->getStatusCode()); |
|
164 | 164 | $jsonBody = json_decode($response->getBody()); |
165 | 165 | $this->assertEquals('c1', $jsonBody->id); |
166 | 166 | $this->assertEquals(array('collar', 'colour'), $jsonBody->result); |
167 | 167 | |
168 | 168 | // Test non-ajax rejection |
169 | 169 | $response = $this->post('spellcheck', array('json_data' => json_encode($dataCheckWords))); |
170 | - $this->assertEquals(400, $response->getStatusCode()); |
|
170 | + $this->assertEquals(400, $response->getStatusCode()); |
|
171 | 171 | $jsonBody = json_decode($response->getBody()); |
172 | 172 | $this->assertEquals($invalidRequest, $jsonBody->error->errstr); |
173 | 173 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | $dataInvalidMethod = $dataCheckWords; |
176 | 176 | $dataInvalidMethod['method'] = 'validate'; |
177 | 177 | $response = $this->post('spellcheck', array('ajax' => 1, 'json_data' => json_encode($dataInvalidMethod))); |
178 | - $this->assertEquals(400, $response->getStatusCode()); |
|
178 | + $this->assertEquals(400, $response->getStatusCode()); |
|
179 | 179 | $jsonBody = json_decode($response->getBody()); |
180 | 180 | $this->assertEquals( |
181 | 181 | _t('SpellController.UnsupportedMethod', "Unsupported method '{method}'", array('method' => 'validate')), |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | $dataNoMethod = $dataCheckWords; |
187 | 187 | unset($dataNoMethod['method']); |
188 | 188 | $response = $this->post('spellcheck', array('ajax' => 1, 'json_data' => json_encode($dataNoMethod))); |
189 | - $this->assertEquals(400, $response->getStatusCode()); |
|
189 | + $this->assertEquals(400, $response->getStatusCode()); |
|
190 | 190 | $jsonBody = json_decode($response->getBody()); |
191 | 191 | $this->assertEquals($invalidRequest, $jsonBody->error->errstr); |
192 | 192 | |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | array('collor', 'colour', 'color', 'onee', 'correct') |
198 | 198 | ); |
199 | 199 | $response = $this->post('spellcheck', array('ajax' => 1, 'json_data' => json_encode($dataWrongLocale))); |
200 | - $this->assertEquals(400, $response->getStatusCode()); |
|
200 | + $this->assertEquals(400, $response->getStatusCode()); |
|
201 | 201 | $jsonBody = json_decode($response->getBody()); |
202 | 202 | $this->assertEquals(_t('SpellController.InvalidLocale', 'Not supported locale'), $jsonBody->error->errstr); |
203 | 203 | } |