Passed
Branch master (06ad6f)
by Alexander
22:27
created
src/Translator.php 1 patch
Braces   +10 added lines, -16 removed lines patch added patch discarded remove patch
@@ -124,14 +124,12 @@  discard block
 block discarded – undo
124 124
         // Check if the class from the config exists and implements HandlerInterface
125 125
         if (class_exists($handler_class) && is_a($handler_class, 'Hokan22\LaravelTranslator\Handler\HandlerInterface', TRUE)) {
126 126
             $oHandler = $handler_class;
127
-        }
128
-        elseif (!class_exists($handler_class)) {
127
+        } elseif (!class_exists($handler_class)) {
129 128
             // If one of the previous check fails check if the class does not exists and set message accordingly
130 129
             // As it could either be the class does not exist or does not implement HandlerInterface
131 130
             // check only the shorter statement to improve readability
132 131
             $message = "Handler '".$handler_class."' not found.";
133
-        }
134
-        else {
132
+        } else {
135 133
             // If the class exists but the class does not implement HandlerInterface set the message accordingly
136 134
             $message = "Handler '".$handler_class."' does not implement HandlerInterface.";
137 135
         }
@@ -147,8 +145,7 @@  discard block
 block discarded – undo
147 145
         // Try to create new Instance of Handler and return it
148 146
         try {
149 147
              $oHandler = new $oHandler($locale);
150
-        }
151
-        catch (TranslationCacheNotFound $exception) {
148
+        } catch (TranslationCacheNotFound $exception) {
152 149
             // Log error and fallback procedure
153 150
             Log::error($exception);
154 151
             Log::warning('Falling back to DatabaseHandler');
@@ -207,8 +204,7 @@  discard block
 block discarded – undo
207 204
 
208 205
             // Print notice about creation to laravel log
209 206
             Log::notice('The translation string "'.$identifier.'" will be written to the Database');
210
-        }
211
-        else {
207
+        } else {
212 208
             Log::warning('The translation string "'.$identifier.'" is already in the Database!');
213 209
         }
214 210
     }
@@ -279,29 +275,28 @@  discard block
 block discarded – undo
279 275
         }
280 276
 
281 277
         // Fallback if empty locale was given (should be handled in middleware)
282
-        if ($locale == ''){
278
+        if ($locale == '') {
283 279
             if (session()->get('locale') != '') {
284 280
                 $locale = session()->get('locale');
285
-            }
286
-            else {
281
+            } else {
287 282
                 return $default_locale;
288 283
             }
289 284
         }
290 285
 
291 286
         // If the given locale is not defined as valid, try to get a fallback locale
292
-        if (!in_array($locale, $avail_locales)){
287
+        if (!in_array($locale, $avail_locales)) {
293 288
 
294 289
             $found_locales = [];
295 290
 
296 291
             // Find any available locale which contains the locale as substring
297 292
             foreach ($avail_locales as $avail_locale) {
298
-                if (strpos($avail_locale, $locale) !== false){
293
+                if (strpos($avail_locale, $locale) !== false) {
299 294
                     $found_locales[] = $avail_locale;
300 295
                 }
301 296
             }
302 297
 
303 298
             // Check if default locale is inside the found locales. If it was, use it!
304
-            if (in_array($default_locale, $found_locales)){
299
+            if (in_array($default_locale, $found_locales)) {
305 300
                 Log::warning('Locale "'.$locale.'" was not found! Falling back to default locale "'.$default_locale.'"');
306 301
                 $locale = $default_locale;
307 302
             }
@@ -309,8 +304,7 @@  discard block
 block discarded – undo
309 304
             elseif (count($found_locales, 0) >= 1) {
310 305
                 Log::warning('Locale "'.$locale.'" was not found! Falling back to similar locale "'.$found_locales[0].'"');
311 306
                 $locale = $found_locales[0];
312
-            }
313
-            else {
307
+            } else {
314 308
                 throw new NotFoundResourceException("Locale '".$locale."' was not found in available locales");
315 309
             }
316 310
         }
Please login to merge, or discard this patch.