Passed
Push — master ( 484e36...59734e )
by Jakub
01:04
created
src/Bridges/NetteDI/TranslationExtension.php 3 patches
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
             "localeResolver" => Expect::anyOf(
89 89
                 Expect::string(),
90 90
                 Expect::arrayOf("string")
91
-            )->default(["param", "session", "header",]),
91
+            )->default(["param", "session", "header", ]),
92 92
             "default" => Expect::string("en"),
93 93
             "debugger" => Expect::bool(Helpers::expand("%debugMode%", $params)),
94 94
             "loader" => Expect::structure([
@@ -115,14 +115,14 @@  discard block
 block discarded – undo
115 115
         $config = $this->getConfig();
116 116
         $return = [];
117 117
         $resolvers = $config->localeResolver;
118
-        if (!is_array($resolvers)) {
118
+        if(!is_array($resolvers)) {
119 119
             $resolvers = [$resolvers];
120 120
         }
121
-        foreach ($resolvers as $resolverName) {
121
+        foreach($resolvers as $resolverName) {
122 122
             $resolver = Arrays::get($this->resolvers, strtolower($resolverName), "");
123
-            if ($resolver !== "") {
123
+            if($resolver !== "") {
124 124
                 $return[] = $resolver;
125
-            } elseif (class_exists($resolverName) && is_subclass_of($resolverName, LocaleResolver::class)) {
125
+            } elseif(class_exists($resolverName) && is_subclass_of($resolverName, LocaleResolver::class)) {
126 126
                 $return[] = $resolverName;
127 127
             } else {
128 128
                 throw new InvalidLocaleResolverException("Invalid locale resolver $resolverName.");
@@ -140,9 +140,9 @@  discard block
 block discarded – undo
140 140
         /** @var string $loaderName */
141 141
         $loaderName = $config->loader["name"];
142 142
         $loader = Arrays::get($this->loaders, strtolower($loaderName), "");
143
-        if ($loader !== "") {
143
+        if($loader !== "") {
144 144
             return $loader;
145
-        } elseif (class_exists($loaderName) && is_subclass_of($loaderName, Loader::class)) {
145
+        } elseif(class_exists($loaderName) && is_subclass_of($loaderName, Loader::class)) {
146 146
             return $loaderName;
147 147
         }
148 148
         throw new InvalidLoaderException("Invalid translation loader $loaderName.");
@@ -157,11 +157,11 @@  discard block
 block discarded – undo
157 157
         $config = $this->getConfig();
158 158
         $folders = $config->loader["folders"];
159 159
         /** @var TranslationProvider $extension */
160
-        foreach ($this->compiler->getExtensions(TranslationProvider::class) as $extension) {
160
+        foreach($this->compiler->getExtensions(TranslationProvider::class) as $extension) {
161 161
             $folders = array_merge($folders, array_values($extension->getTranslationResources()));
162 162
         }
163
-        foreach ($folders as $folder) {
164
-            if (!is_dir($folder)) {
163
+        foreach($folders as $folder) {
164
+            if(!is_dir($folder)) {
165 165
                 throw new InvalidFolderException("Folder $folder does not exist.");
166 166
             }
167 167
         }
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
         $config = $this->getConfig();
177 177
         /** @var string $messageSelector */
178 178
         $messageSelector = $config->messageSelector;
179
-        if (class_exists($messageSelector) && is_subclass_of($messageSelector, IMessageSelector::class)) {
179
+        if(class_exists($messageSelector) && is_subclass_of($messageSelector, IMessageSelector::class)) {
180 180
             return $messageSelector;
181 181
         }
182 182
         throw new InvalidMessageSelectorException("Invalid message selector $messageSelector.");
@@ -201,20 +201,20 @@  discard block
 block discarded – undo
201 201
         $messageSelector = $this->resolveMessageSelector();
202 202
         $builder->addDefinition($this->prefix(self::SERVICE_MESSAGE_SELECTOR))
203 203
             ->setType($messageSelector);
204
-        if (count($resolvers) === 1) {
204
+        if(count($resolvers) === 1) {
205 205
             $builder->addDefinition($this->prefix(self::SERVICE_LOCALE_RESOLVER))
206 206
                 ->setType($resolvers[0]);
207 207
         } else {
208 208
             $chainResolver = $builder->addDefinition($this->prefix(self::SERVICE_LOCALE_RESOLVER))
209 209
                 ->setType(ChainLocaleResolver::class);
210
-            foreach ($resolvers as $index => $resolver) {
210
+            foreach($resolvers as $index => $resolver) {
211 211
                 $resolverService = $builder->addDefinition($this->prefix("resolver.$index"))
212 212
                     ->setType($resolver)
213 213
                     ->setAutowired(false);
214 214
                 $chainResolver->addSetup('$service[] = ?', [$resolverService]);
215 215
             }
216 216
         }
217
-        if ($config->debugger && interface_exists(\Tracy\IBarPanel::class)) {
217
+        if($config->debugger && interface_exists(\Tracy\IBarPanel::class)) {
218 218
             $builder->addDefinition($this->prefix(self::SERVICE_PANEL))
219 219
                 ->setType(TranslationPanel::class);
220 220
             /** @var ServiceDefinition $tracy */
@@ -232,24 +232,24 @@  discard block
 block discarded – undo
232 232
         $config = $this->getConfig();
233 233
         /** @var ServiceDefinition $loader */
234 234
         $loader = $builder->getDefinition($this->prefix(self::SERVICE_LOADER));
235
-        if (in_array(FileLoader::class, (array) class_implements((string) $loader->class), true)) {
235
+        if(in_array(FileLoader::class, (array) class_implements((string) $loader->class), true)) {
236 236
             $folders = $this->getFolders();
237 237
             $loader->addSetup("setFolders", [$folders]);
238
-            foreach ($folders as $folder) {
238
+            foreach($folders as $folder) {
239 239
                 $builder->addDependency($folder);
240 240
             }
241 241
         }
242 242
         /** @var ServiceDefinition $resolver */
243 243
         $resolver = $builder->getDefinition($this->prefix(self::SERVICE_LOCALE_RESOLVER));
244
-        if (in_array(AppRequestAwareLocaleResolver::class, (array) class_implements((string) $resolver->class), true)) {
244
+        if(in_array(AppRequestAwareLocaleResolver::class, (array) class_implements((string) $resolver->class), true)) {
245 245
             $applicationService = $builder->getByType(Application::class) ?? "application";
246
-            if ($builder->hasDefinition($applicationService)) {
246
+            if($builder->hasDefinition($applicationService)) {
247 247
                 /** @var ServiceDefinition $application */
248 248
                 $application = $builder->getDefinition($applicationService);
249 249
                 $application->addSetup('$service->onRequest[] = ?', [[$resolver, "onRequest"]]);
250 250
             }
251 251
         }
252
-        if ($config->compiler["enabled"]) {
252
+        if($config->compiler["enabled"]) {
253 253
             $serviceName = $this->prefix(self::SERVICE_LOADER);
254 254
             /** @var ServiceDefinition $loader */
255 255
             $loader = $builder->getDefinition($serviceName);
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
                 ->setFactory(CatalogueCompiler::class, [$loader, $folder, $config->compiler["languages"]]);
266 266
         }
267 267
         $latteFactoryService = $builder->getByType(LatteFactory::class) ?? "latte.latteFactory";
268
-        if ($builder->hasDefinition($latteFactoryService)) {
268
+        if($builder->hasDefinition($latteFactoryService)) {
269 269
             /** @var FactoryDefinition $latteFactory */
270 270
             $latteFactory = $builder->getDefinition($latteFactoryService);
271 271
             $latteFactory->getResultDefinition()->addSetup(
@@ -284,10 +284,10 @@  discard block
 block discarded – undo
284 284
         $config = $this->getConfig();
285 285
         $initialize = $this->initialization;
286 286
         $initialize->addBody('$translator = $this->getService(?);', [$this->prefix(self::SERVICE_TRANSLATOR)]);
287
-        foreach ($config->onUntranslated as &$task) {
288
-            if (!is_array($task)) {
287
+        foreach($config->onUntranslated as &$task) {
288
+            if(!is_array($task)) {
289 289
                 $task = explode("::", $task);
290
-            } elseif (str_starts_with($task[0], "@")) {
290
+            } elseif(str_starts_with($task[0], "@")) {
291 291
                 $initialize->addBody(
292 292
                     '$translator->onUntranslated[] = [$this->getService(?), ?];',
293 293
                     [substr($task[0], 1), $task[1]]
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 foreach($resolvers as $resolver) {
301 301
     $this->getService($resolver)->setLoader($this->getService(?));
302 302
 }', [LoaderAwareLocaleResolver::class, $this->prefix(self::SERVICE_LOADER)]);
303
-        if ($config->compiler["enabled"]) {
303
+        if($config->compiler["enabled"]) {
304 304
             $initialize->addBody('$this->getService(?)->compile();', [$this->prefix(self::SERVICE_CATALOGUE_COMPILER)]);
305 305
         }
306 306
     }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -46,8 +46,7 @@
 block discarded – undo
46 46
  * @author Jakub Konečný
47 47
  * @method \stdClass getConfig()
48 48
  */
49
-final class TranslationExtension extends CompilerExtension
50
-{
49
+final class TranslationExtension extends CompilerExtension {
51 50
     /** @internal */
52 51
     public const SERVICE_TRANSLATOR = "translator";
53 52
     /** @internal */
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -162,7 +162,7 @@
 block discarded – undo
162 162
         }
163 163
         foreach ($folders as $folder) {
164 164
             if (!is_dir($folder)) {
165
-                throw new InvalidFolderException("Folder $folder does not exist.");
165
+                throw new InvalidFolderException("folder $folder does not exist.");
166 166
             }
167 167
         }
168 168
         return $folders;
Please login to merge, or discard this patch.
src/Bridges/Tracy/TranslationPanel.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
 
39 39
     protected function renderLink(string $resource): string
40 40
     {
41
-        if (is_file($resource)) {
41
+        if(is_file($resource)) {
42 42
             return \Tracy\Helpers::editorLink($resource);
43 43
         }
44 44
         return $resource;
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -12,10 +12,8 @@
 block discarded – undo
12 12
  *
13 13
  * @author Jakub Konečný
14 14
  */
15
-final class TranslationPanel implements IBarPanel
16
-{
17
-    public function __construct(private readonly Translator $translator, private readonly Loader $loader)
18
-    {
15
+final class TranslationPanel implements IBarPanel {
16
+    public function __construct(private readonly Translator $translator, private readonly Loader $loader) {
19 17
     }
20 18
 
21 19
     public function getTab(): string
Please login to merge, or discard this patch.
src/Bridges/NetteApplication/IAppRequestAwareLocaleResolver.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,11 +3,11 @@
 block discarded – undo
3 3
 
4 4
 namespace Nexendrie\Translation\Bridges\NetteApplication;
5 5
 
6
-if (false) { // @phpstan-ignore if.alwaysFalse
6
+if(false) { // @phpstan-ignore if.alwaysFalse
7 7
     /** @deprecated Use AppRequestAwareLocaleResolver */
8 8
     interface IAppRequestAwareLocaleResolver extends AppRequestAwareLocaleResolver
9 9
     {
10 10
     }
11
-} elseif (!interface_exists(IAppRequestAwareLocaleResolver::class)) {
11
+} elseif(!interface_exists(IAppRequestAwareLocaleResolver::class)) {
12 12
     class_alias(AppRequestAwareLocaleResolver::class, IAppRequestAwareLocaleResolver::class);
13 13
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -3,10 +3,10 @@
 block discarded – undo
3 3
 
4 4
 namespace Nexendrie\Translation\Bridges\NetteApplication;
5 5
 
6
-if (false) { // @phpstan-ignore if.alwaysFalse
6
+if (false) {
7
+// @phpstan-ignore if.alwaysFalse
7 8
     /** @deprecated Use AppRequestAwareLocaleResolver */
8
-    interface IAppRequestAwareLocaleResolver extends AppRequestAwareLocaleResolver
9
-    {
9
+    interface IAppRequestAwareLocaleResolver extends AppRequestAwareLocaleResolver {
10 10
     }
11 11
 } elseif (!interface_exists(IAppRequestAwareLocaleResolver::class)) {
12 12
     class_alias(AppRequestAwareLocaleResolver::class, IAppRequestAwareLocaleResolver::class);
Please login to merge, or discard this patch.
src/Bridges/NetteApplication/ParamLocaleResolver.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@
 block discarded – undo
36 36
     public function onRequest(Application $application, Request $request): void
37 37
     {
38 38
         $locale = $request->getParameter($this->param);
39
-        if ($request->method === Request::FORWARD && $locale === null) {
39
+        if($request->method === Request::FORWARD && $locale === null) {
40 40
             return;
41 41
         }
42 42
         $this->request = $request;
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,8 +11,7 @@
 block discarded – undo
11 11
  *
12 12
  * @author Jakub Konečný
13 13
  */
14
-final class ParamLocaleResolver implements AppRequestAwareLocaleResolver
15
-{
14
+final class ParamLocaleResolver implements AppRequestAwareLocaleResolver {
16 15
     private ?Request $request = null;
17 16
     /** @var string */
18 17
     public string $param = "locale";
Please login to merge, or discard this patch.
src/Bridges/NetteApplication/AppRequestAwareLocaleResolver.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,7 +12,6 @@
 block discarded – undo
12 12
  *
13 13
  * @author Jakub Konečný
14 14
  */
15
-interface AppRequestAwareLocaleResolver extends LocaleResolver
16
-{
15
+interface AppRequestAwareLocaleResolver extends LocaleResolver {
17 16
     public function onRequest(Application $application, Request $request): void;
18 17
 }
Please login to merge, or discard this patch.
src/InvalidMessageSelectorException.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -8,6 +8,5 @@
 block discarded – undo
8 8
  *
9 9
  * @author Jakub Konečný
10 10
  */
11
-class InvalidMessageSelectorException extends InvalidStateException
12
-{
11
+class InvalidMessageSelectorException extends InvalidStateException {
13 12
 }
Please login to merge, or discard this patch.
src/FolderNotSetException.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,6 +3,5 @@
 block discarded – undo
3 3
 
4 4
 namespace Nexendrie\Translation;
5 5
 
6
-class FolderNotSetException extends InvalidStateException
7
-{
6
+class FolderNotSetException extends InvalidStateException {
8 7
 }
Please login to merge, or discard this patch.
src/ISettableLocaleResolver.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,11 +3,11 @@
 block discarded – undo
3 3
 
4 4
 namespace Nexendrie\Translation;
5 5
 
6
-if (false) { // @phpstan-ignore if.alwaysFalse
6
+if(false) { // @phpstan-ignore if.alwaysFalse
7 7
     /** @deprecated Use SettableLocaleResolver */
8 8
     interface ISettableLocaleResolver extends SettableLocaleResolver
9 9
     {
10 10
     }
11
-} elseif (!interface_exists(ISettableLocaleResolver::class)) {
11
+} elseif(!interface_exists(ISettableLocaleResolver::class)) {
12 12
     class_alias(SettableLocaleResolver::class, ISettableLocaleResolver::class);
13 13
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -3,10 +3,10 @@
 block discarded – undo
3 3
 
4 4
 namespace Nexendrie\Translation;
5 5
 
6
-if (false) { // @phpstan-ignore if.alwaysFalse
6
+if (false) {
7
+// @phpstan-ignore if.alwaysFalse
7 8
     /** @deprecated Use SettableLocaleResolver */
8
-    interface ISettableLocaleResolver extends SettableLocaleResolver
9
-    {
9
+    interface ISettableLocaleResolver extends SettableLocaleResolver {
10 10
     }
11 11
 } elseif (!interface_exists(ISettableLocaleResolver::class)) {
12 12
     class_alias(SettableLocaleResolver::class, ISettableLocaleResolver::class);
Please login to merge, or discard this patch.
src/Resolvers/SessionLocaleResolver.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 
26 26
     public function __construct(Session $session = null)
27 27
     {
28
-        if ($session === null) {
28
+        if($session === null) {
29 29
             $request = (new RequestFactory())->fromGlobals();
30 30
             $response = new Response();
31 31
             $session = new Session($request, $response);
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
     public function getLang(): ?string
41 41
     {
42 42
         $lang = (string) $this->section->{$this->varName};
43
-        if ($lang === '') {
43
+        if($lang === '') {
44 44
             return null;
45 45
         }
46 46
         return $lang;
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,16 +15,14 @@
 block discarded – undo
15 15
  * @author Jakub Konečný
16 16
  * @property string|null $lang
17 17
  */
18
-final class SessionLocaleResolver implements SettableLocaleResolver
19
-{
18
+final class SessionLocaleResolver implements SettableLocaleResolver {
20 19
     use \Nette\SmartObject;
21 20
 
22 21
     private readonly Session $session;
23 22
     private readonly SessionSection $section;
24 23
     public string $varName = "lang";
25 24
 
26
-    public function __construct(Session $session = null)
27
-    {
25
+    public function __construct(Session $session = null) {
28 26
         if ($session === null) {
29 27
             $request = (new RequestFactory())->fromGlobals();
30 28
             $response = new Response();
Please login to merge, or discard this patch.