@@ -9,8 +9,7 @@ |
||
9 | 9 | * |
10 | 10 | * @author Jakub Konečný |
11 | 11 | */ |
12 | -final class PhpLoader extends FileLoader |
|
13 | -{ |
|
12 | +final class PhpLoader extends FileLoader { |
|
14 | 13 | protected string $extension = "php"; |
15 | 14 | |
16 | 15 | protected function parseFile(string $filename): array |
@@ -19,7 +19,7 @@ |
||
19 | 19 | protected function parseFile(string $filename): array |
20 | 20 | { |
21 | 21 | $result = parse_ini_file($filename, true); |
22 | - if ($result === false) { |
|
22 | + if($result === false) { |
|
23 | 23 | throw new \RuntimeException("File $filename does not exist or cannot be read."); |
24 | 24 | } |
25 | 25 | return $result; |
@@ -9,8 +9,7 @@ |
||
9 | 9 | * |
10 | 10 | * @author Jakub Konečný |
11 | 11 | */ |
12 | -final class IniLoader extends FileLoader |
|
13 | -{ |
|
12 | +final class IniLoader extends FileLoader { |
|
14 | 13 | protected string $extension = "ini"; |
15 | 14 | |
16 | 15 | /** |
@@ -20,7 +20,7 @@ |
||
20 | 20 | { |
21 | 21 | $result = parse_ini_file($filename, true); |
22 | 22 | if ($result === false) { |
23 | - throw new \RuntimeException("File $filename does not exist or cannot be read."); |
|
23 | + throw new \RuntimeException("file $filename does not exist or cannot be read."); |
|
24 | 24 | } |
25 | 25 | return $result; |
26 | 26 | } |
@@ -11,8 +11,7 @@ |
||
11 | 11 | * |
12 | 12 | * @author Jakub Konečný |
13 | 13 | */ |
14 | -final class YamlLoader extends FileLoader |
|
15 | -{ |
|
14 | +final class YamlLoader extends FileLoader { |
|
16 | 15 | protected string $extension = "yaml"; |
17 | 16 | |
18 | 17 | /** |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function setLang(string $lang): void |
70 | 70 | { |
71 | - if (is_a($this->resolver, SettableLocaleResolver::class)) { |
|
71 | + if(is_a($this->resolver, SettableLocaleResolver::class)) { |
|
72 | 72 | $oldLang = $this->lang; |
73 | 73 | $this->resolver->setLang($lang); |
74 | 74 | $this->onLanguageChange($this, $oldLang, $lang); |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public function setFolders(array $folders): void |
109 | 109 | { |
110 | - foreach ($folders as $folder) { |
|
111 | - if (!is_dir($folder)) { |
|
110 | + foreach($folders as $folder) { |
|
111 | + if(!is_dir($folder)) { |
|
112 | 112 | throw new InvalidFolderException("Folder $folder does not exist."); |
113 | 113 | } |
114 | 114 | $this->folders[] = $folder; |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | |
119 | 119 | protected function addResource(string $filename, string $domain): void |
120 | 120 | { |
121 | - if (!isset($this->resources[$domain]) || !in_array($filename, $this->resources[$domain], true)) { |
|
121 | + if(!isset($this->resources[$domain]) || !in_array($filename, $this->resources[$domain], true)) { |
|
122 | 122 | $this->resources[$domain][] = $filename; |
123 | 123 | } |
124 | 124 | } |
@@ -145,20 +145,20 @@ discard block |
||
145 | 145 | $defaultLang = $this->defaultLang; |
146 | 146 | $defaultFilename = $this->getLanguageFilenameMask(); |
147 | 147 | $defaultFilename = str_replace( |
148 | - [static::DOMAIN_MASK, static::LANGUAGE_MASK,], |
|
149 | - [$name, $defaultLang,], |
|
148 | + [static::DOMAIN_MASK, static::LANGUAGE_MASK, ], |
|
149 | + [$name, $defaultLang, ], |
|
150 | 150 | $defaultFilename |
151 | 151 | ); |
152 | 152 | $files = Finder::findFiles($defaultFilename) |
153 | 153 | ->from(...$this->folders); |
154 | 154 | /** @var \SplFileInfo $file */ |
155 | - foreach ($files as $file) { |
|
155 | + foreach($files as $file) { |
|
156 | 156 | $default = $this->parseFile($file->getPathname()); |
157 | 157 | $this->addResource($file->getPathname(), $name); |
158 | 158 | $lang = []; |
159 | 159 | $filename = str_replace($defaultLang, $this->lang, $defaultFilename); |
160 | 160 | $filename = str_replace($defaultFilename, $filename, $file->getPathname()); |
161 | - if ($this->lang !== $defaultLang && is_file($filename)) { |
|
161 | + if($this->lang !== $defaultLang && is_file($filename)) { |
|
162 | 162 | $lang = $this->parseFile($filename); |
163 | 163 | $this->addResource($filename, $name); |
164 | 164 | } |
@@ -174,20 +174,20 @@ discard block |
||
174 | 174 | */ |
175 | 175 | protected function loadTexts(): void |
176 | 176 | { |
177 | - if ($this->lang === $this->loadedLang) { |
|
177 | + if($this->lang === $this->loadedLang) { |
|
178 | 178 | return; |
179 | 179 | } |
180 | - if (count($this->folders) === 0) { |
|
180 | + if(count($this->folders) === 0) { |
|
181 | 181 | throw new FolderNotSetException("Folder for translations was not set."); |
182 | 182 | } |
183 | 183 | $default = $this->defaultLang; |
184 | 184 | $this->resources = $texts = []; |
185 | 185 | $mask = $this->getLanguageFilenameMask(); |
186 | - $mask = str_replace([static::DOMAIN_MASK, static::LANGUAGE_MASK,], ["*", $default,], $mask); |
|
186 | + $mask = str_replace([static::DOMAIN_MASK, static::LANGUAGE_MASK, ], ["*", $default, ], $mask); |
|
187 | 187 | $files = Finder::findFiles($mask) |
188 | 188 | ->from(...$this->folders); |
189 | 189 | /** @var \SplFileInfo $file */ |
190 | - foreach ($files as $file) { |
|
190 | + foreach($files as $file) { |
|
191 | 191 | $domain = $file->getBasename((string) Strings::after($mask, "*")); |
192 | 192 | $texts[$domain] = $this->loadDomain($domain); |
193 | 193 | } |
@@ -222,20 +222,20 @@ discard block |
||
222 | 222 | */ |
223 | 223 | public function getAvailableLanguages(): array |
224 | 224 | { |
225 | - if (count($this->folders) === 0) { |
|
225 | + if(count($this->folders) === 0) { |
|
226 | 226 | throw new FolderNotSetException("Folder for translations was not set."); |
227 | 227 | } |
228 | 228 | $languages = []; |
229 | 229 | $extension = $this->extension; |
230 | 230 | $mask = $this->getLanguageFilenameMask(); |
231 | - $mask = str_replace([static::DOMAIN_MASK, static::LANGUAGE_MASK,], "*", $mask); |
|
231 | + $mask = str_replace([static::DOMAIN_MASK, static::LANGUAGE_MASK, ], "*", $mask); |
|
232 | 232 | $files = Finder::findFiles($mask) |
233 | 233 | ->from(...$this->folders); |
234 | 234 | /** @var \SplFileInfo $file */ |
235 | - foreach ($files as $file) { |
|
235 | + foreach($files as $file) { |
|
236 | 236 | $filename = $file->getBasename(".$extension"); |
237 | 237 | $lang = (string) Strings::after($filename, "."); |
238 | - if (!in_array($lang, $languages, true)) { |
|
238 | + if(!in_array($lang, $languages, true)) { |
|
239 | 239 | $languages[] = $lang; |
240 | 240 | } |
241 | 241 | } |
@@ -50,8 +50,7 @@ |
||
50 | 50 | /** |
51 | 51 | * @param string[] $folders |
52 | 52 | */ |
53 | - public function __construct(protected LocaleResolver $resolver = new ManualLocaleResolver(), array $folders = []) |
|
54 | - { |
|
53 | + public function __construct(protected LocaleResolver $resolver = new ManualLocaleResolver(), array $folders = []) { |
|
55 | 54 | $this->setFolders($folders); |
56 | 55 | } |
57 | 56 |
@@ -109,7 +109,7 @@ |
||
109 | 109 | { |
110 | 110 | foreach ($folders as $folder) { |
111 | 111 | if (!is_dir($folder)) { |
112 | - throw new InvalidFolderException("Folder $folder does not exist."); |
|
112 | + throw new InvalidFolderException("folder $folder does not exist."); |
|
113 | 113 | } |
114 | 114 | $this->folders[] = $folder; |
115 | 115 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | |
29 | 29 | protected function loadTexts(): void |
30 | 30 | { |
31 | - if (count($this->folders) === 0) { |
|
31 | + if(count($this->folders) === 0) { |
|
32 | 32 | throw new FolderNotSetException("Folder for translations was not set."); |
33 | 33 | } |
34 | 34 | $this->resources = $texts = []; |
@@ -36,15 +36,15 @@ discard block |
||
36 | 36 | $files = Finder::findFiles($filename) |
37 | 37 | ->from(...$this->folders); |
38 | 38 | /** @var \SplFileInfo $file */ |
39 | - foreach ($files as $file) { |
|
39 | + foreach($files as $file) { |
|
40 | 40 | $texts = array_merge($texts, $this->parseFile($file->getPathname())); |
41 | - if (isset($texts["__resources"])) { |
|
41 | + if(isset($texts["__resources"])) { |
|
42 | 42 | $this->resources = array_merge($this->resources, $texts["__resources"]); |
43 | 43 | unset($texts["__resources"]); |
44 | 44 | } else { |
45 | 45 | /** @var string[] $domains */ |
46 | 46 | $domains = array_keys($texts); |
47 | - foreach ($domains as $domain) { |
|
47 | + foreach($domains as $domain) { |
|
48 | 48 | $this->addResource($file->getPathname(), $domain); |
49 | 49 | } |
50 | 50 | } |
@@ -12,8 +12,7 @@ |
||
12 | 12 | * |
13 | 13 | * @author Jakub Konečný |
14 | 14 | */ |
15 | -final class MessagesCatalogue extends FileLoader |
|
16 | -{ |
|
15 | +final class MessagesCatalogue extends FileLoader { |
|
17 | 16 | protected string $extension = "php"; |
18 | 17 | |
19 | 18 | protected function parseFile(string $filename): array |
@@ -22,7 +22,7 @@ |
||
22 | 22 | protected function parseFile(string $filename): array |
23 | 23 | { |
24 | 24 | $content = file_get_contents($filename); |
25 | - if ($content === false) { |
|
25 | + if($content === false) { |
|
26 | 26 | throw new \RuntimeException("File $filename does not exist or cannot be read."); |
27 | 27 | } |
28 | 28 | return Json::decode($content, Json::FORCE_ARRAY); |
@@ -11,8 +11,7 @@ |
||
11 | 11 | * |
12 | 12 | * @author Jakub Konečný |
13 | 13 | */ |
14 | -final class JsonLoader extends FileLoader |
|
15 | -{ |
|
14 | +final class JsonLoader extends FileLoader { |
|
16 | 15 | protected string $extension = "json"; |
17 | 16 | |
18 | 17 | /** |
@@ -23,7 +23,7 @@ |
||
23 | 23 | { |
24 | 24 | $content = file_get_contents($filename); |
25 | 25 | if ($content === false) { |
26 | - throw new \RuntimeException("File $filename does not exist or cannot be read."); |
|
26 | + throw new \RuntimeException("file $filename does not exist or cannot be read."); |
|
27 | 27 | } |
28 | 28 | return Json::decode($content, Json::FORCE_ARRAY); |
29 | 29 | } |
@@ -21,7 +21,7 @@ |
||
21 | 21 | protected function parseFile(string $filename): array |
22 | 22 | { |
23 | 23 | $content = file_get_contents($filename); |
24 | - if ($content === false) { |
|
24 | + if($content === false) { |
|
25 | 25 | throw new \RuntimeException("File $filename does not exist or cannot be read."); |
26 | 26 | } |
27 | 27 | return Neon::decode($content); |
@@ -11,8 +11,7 @@ |
||
11 | 11 | * |
12 | 12 | * @author Jakub Konečný |
13 | 13 | */ |
14 | -final class NeonLoader extends FileLoader |
|
15 | -{ |
|
14 | +final class NeonLoader extends FileLoader { |
|
16 | 15 | protected string $extension = "neon"; |
17 | 16 | |
18 | 17 | /** |
@@ -22,7 +22,7 @@ |
||
22 | 22 | { |
23 | 23 | $content = file_get_contents($filename); |
24 | 24 | if ($content === false) { |
25 | - throw new \RuntimeException("File $filename does not exist or cannot be read."); |
|
25 | + throw new \RuntimeException("file $filename does not exist or cannot be read."); |
|
26 | 26 | } |
27 | 27 | return Neon::decode($content); |
28 | 28 | } |
@@ -8,8 +8,7 @@ |
||
8 | 8 | * |
9 | 9 | * @author Jakub Konečný |
10 | 10 | */ |
11 | -interface Loader |
|
12 | -{ |
|
11 | +interface Loader { |
|
13 | 12 | public function getLang(): string; |
14 | 13 | public function setLang(string $lang): void; |
15 | 14 | public function getDefaultLang(): string; |
@@ -3,11 +3,11 @@ |
||
3 | 3 | |
4 | 4 | namespace Nexendrie\Translation\Bridges\NetteDI; |
5 | 5 | |
6 | -if (false) { // @phpstan-ignore if.alwaysFalse |
|
6 | +if(false) { // @phpstan-ignore if.alwaysFalse |
|
7 | 7 | /** @deprecated Use TranslationProvider */ |
8 | 8 | interface ITranslationProvider extends TranslationProvider |
9 | 9 | { |
10 | 10 | } |
11 | -} elseif (!interface_exists(ITranslationProvider::class)) { |
|
11 | +} elseif(!interface_exists(ITranslationProvider::class)) { |
|
12 | 12 | class_alias(TranslationProvider::class, ITranslationProvider::class); |
13 | 13 | } |
@@ -3,10 +3,10 @@ |
||
3 | 3 | |
4 | 4 | namespace Nexendrie\Translation\Bridges\NetteDI; |
5 | 5 | |
6 | -if (false) { // @phpstan-ignore if.alwaysFalse |
|
6 | +if (false) { |
|
7 | +// @phpstan-ignore if.alwaysFalse |
|
7 | 8 | /** @deprecated Use TranslationProvider */ |
8 | - interface ITranslationProvider extends TranslationProvider |
|
9 | - { |
|
9 | + interface ITranslationProvider extends TranslationProvider { |
|
10 | 10 | } |
11 | 11 | } elseif (!interface_exists(ITranslationProvider::class)) { |
12 | 12 | class_alias(TranslationProvider::class, ITranslationProvider::class); |