@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function getLocales(): array |
50 | 50 | { |
51 | - if (!is_dir($this->config->getLocalesDirectory())) { |
|
51 | + if (!is_dir($this->config->getLocalesDirectory())){ |
|
52 | 52 | return []; |
53 | 53 | } |
54 | 54 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | /** |
61 | 61 | * @var \Symfony\Component\Finder\SplFileInfo $directory |
62 | 62 | */ |
63 | - foreach ($finder->directories()->getIterator() as $directory) { |
|
63 | + foreach ($finder->directories()->getIterator() as $directory){ |
|
64 | 64 | $locales[] = $directory->getFilename(); |
65 | 65 | } |
66 | 66 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | $locale = preg_replace('/[^a-zA-Z_]/', '', mb_strtolower($locale)); |
76 | 76 | $catalogue = new Catalogue($locale); |
77 | 77 | |
78 | - if (!$this->hasLocale($locale)) { |
|
78 | + if (!$this->hasLocale($locale)){ |
|
79 | 79 | return $catalogue; |
80 | 80 | } |
81 | 81 | |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | /** |
86 | 86 | * @var SplFileInfo $file |
87 | 87 | */ |
88 | - foreach ($finder->getIterator() as $file) { |
|
88 | + foreach ($finder->getIterator() as $file){ |
|
89 | 89 | $this->getLogger()->info( |
90 | 90 | sprintf( |
91 | 91 | "found locale domain file '%s'", |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | //Per application agreement domain name must present in filename |
98 | 98 | $domain = strstr($file->getFilename(), '.', true); |
99 | 99 | |
100 | - if (!$this->config->hasLoader($file->getExtension())) { |
|
100 | + if (!$this->config->hasLoader($file->getExtension())){ |
|
101 | 101 | $this->getLogger()->warning( |
102 | 102 | sprintf( |
103 | 103 | "unable to load domain file '%s', no loader found", |
@@ -48,7 +48,8 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function getLocales(): array |
50 | 50 | { |
51 | - if (!is_dir($this->config->getLocalesDirectory())) { |
|
51 | + if (!is_dir($this->config->getLocalesDirectory())) |
|
52 | + { |
|
52 | 53 | return []; |
53 | 54 | } |
54 | 55 | |
@@ -60,7 +61,8 @@ discard block |
||
60 | 61 | /** |
61 | 62 | * @var \Symfony\Component\Finder\SplFileInfo $directory |
62 | 63 | */ |
63 | - foreach ($finder->directories()->getIterator() as $directory) { |
|
64 | + foreach ($finder->directories()->getIterator() as $directory) |
|
65 | + { |
|
64 | 66 | $locales[] = $directory->getFilename(); |
65 | 67 | } |
66 | 68 | |
@@ -75,7 +77,8 @@ discard block |
||
75 | 77 | $locale = preg_replace('/[^a-zA-Z_]/', '', mb_strtolower($locale)); |
76 | 78 | $catalogue = new Catalogue($locale); |
77 | 79 | |
78 | - if (!$this->hasLocale($locale)) { |
|
80 | + if (!$this->hasLocale($locale)) |
|
81 | + { |
|
79 | 82 | return $catalogue; |
80 | 83 | } |
81 | 84 | |
@@ -85,7 +88,8 @@ discard block |
||
85 | 88 | /** |
86 | 89 | * @var SplFileInfo $file |
87 | 90 | */ |
88 | - foreach ($finder->getIterator() as $file) { |
|
91 | + foreach ($finder->getIterator() as $file) |
|
92 | + { |
|
89 | 93 | $this->getLogger()->info( |
90 | 94 | sprintf( |
91 | 95 | "found locale domain file '%s'", |
@@ -97,7 +101,8 @@ discard block |
||
97 | 101 | //Per application agreement domain name must present in filename |
98 | 102 | $domain = strstr($file->getFilename(), '.', true); |
99 | 103 | |
100 | - if (!$this->config->hasLoader($file->getExtension())) { |
|
104 | + if (!$this->config->hasLoader($file->getExtension())) |
|
105 | + { |
|
101 | 106 | $this->getLogger()->warning( |
102 | 107 | sprintf( |
103 | 108 | "unable to load domain file '%s', no loader found", |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | use Spiral\Translator\Exception\TranslatorException; |
15 | 15 | use Spiral\Translator\TranslatorInterface; |
16 | 16 | |
17 | -if (!function_exists('l')) { |
|
17 | +if (!function_exists('l')){ |
|
18 | 18 | /** |
19 | 19 | * Translate message using default or specific bundle name. |
20 | 20 | * |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | function l(string $string, array $options = [], string $domain = null): string |
35 | 35 | { |
36 | 36 | $container = ContainerScope::getContainer(); |
37 | - if (empty($container) || !$container->has(TranslatorInterface::class)) { |
|
37 | + if (empty($container) || !$container->has(TranslatorInterface::class)){ |
|
38 | 38 | throw new ScopeException( |
39 | 39 | '`TranslatorInterface` binding is missing or container scope is not set' |
40 | 40 | ); |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
50 | -if (!function_exists('p')) { |
|
50 | +if (!function_exists('p')){ |
|
51 | 51 | /** |
52 | 52 | * Pluralize string using language pluralization options and specified numeric value. |
53 | 53 | * |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | function p(string $string, int $number, array $options = [], string $domain = null): string |
68 | 68 | { |
69 | 69 | $container = ContainerScope::getContainer(); |
70 | - if (empty($container) || !$container->has(TranslatorInterface::class)) { |
|
70 | + if (empty($container) || !$container->has(TranslatorInterface::class)){ |
|
71 | 71 | throw new ScopeException( |
72 | 72 | '`TranslatorInterface` binding is missing or container scope is not set' |
73 | 73 | ); |
@@ -14,7 +14,8 @@ discard block |
||
14 | 14 | use Spiral\Translator\Exception\TranslatorException; |
15 | 15 | use Spiral\Translator\TranslatorInterface; |
16 | 16 | |
17 | -if (!function_exists('l')) { |
|
17 | +if (!function_exists('l')) |
|
18 | +{ |
|
18 | 19 | /** |
19 | 20 | * Translate message using default or specific bundle name. |
20 | 21 | * |
@@ -34,7 +35,8 @@ discard block |
||
34 | 35 | function l(string $string, array $options = [], string $domain = null): string |
35 | 36 | { |
36 | 37 | $container = ContainerScope::getContainer(); |
37 | - if (empty($container) || !$container->has(TranslatorInterface::class)) { |
|
38 | + if (empty($container) || !$container->has(TranslatorInterface::class)) |
|
39 | + { |
|
38 | 40 | throw new ScopeException( |
39 | 41 | '`TranslatorInterface` binding is missing or container scope is not set' |
40 | 42 | ); |
@@ -47,7 +49,8 @@ discard block |
||
47 | 49 | } |
48 | 50 | } |
49 | 51 | |
50 | -if (!function_exists('p')) { |
|
52 | +if (!function_exists('p')) |
|
53 | +{ |
|
51 | 54 | /** |
52 | 55 | * Pluralize string using language pluralization options and specified numeric value. |
53 | 56 | * |
@@ -67,7 +70,8 @@ discard block |
||
67 | 70 | function p(string $string, int $number, array $options = [], string $domain = null): string |
68 | 71 | { |
69 | 72 | $container = ContainerScope::getContainer(); |
70 | - if (empty($container) || !$container->has(TranslatorInterface::class)) { |
|
73 | + if (empty($container) || !$container->has(TranslatorInterface::class)) |
|
74 | + { |
|
71 | 75 | throw new ScopeException( |
72 | 76 | '`TranslatorInterface` binding is missing or container scope is not set' |
73 | 77 | ); |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | TranslatorConfig $config, |
45 | 45 | CatalogueManagerInterface $catalogueManager, |
46 | 46 | IdentityTranslator $identityTranslator = null |
47 | - ) { |
|
47 | + ){ |
|
48 | 48 | $this->config = $config; |
49 | 49 | $this->identityTranslator = $identityTranslator ?? new IdentityTranslator(); |
50 | 50 | $this->catalogueManager = $catalogueManager; |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function setLocale(string $locale): void |
70 | 70 | { |
71 | - if (!$this->catalogueManager->has($locale)) { |
|
71 | + if (!$this->catalogueManager->has($locale)){ |
|
72 | 72 | throw new LocaleException($locale); |
73 | 73 | } |
74 | 74 | |
@@ -124,11 +124,11 @@ discard block |
||
124 | 124 | array $parameters = [], |
125 | 125 | $domain = null, |
126 | 126 | $locale = null |
127 | - ) { |
|
127 | + ){ |
|
128 | 128 | $domain = $domain ?? $this->config->getDefaultDomain(); |
129 | 129 | $locale = $locale ?? $this->locale; |
130 | 130 | |
131 | - try { |
|
131 | + try{ |
|
132 | 132 | $message = $this->get($locale, $domain, $id); |
133 | 133 | |
134 | 134 | $pluralized = $this->identityTranslator->trans( |
@@ -137,12 +137,12 @@ discard block |
||
137 | 137 | null, |
138 | 138 | $locale |
139 | 139 | ); |
140 | - } catch (\InvalidArgumentException $e) { |
|
140 | + }catch (\InvalidArgumentException $e){ |
|
141 | 141 | //Wrapping into more explanatory exception |
142 | 142 | throw new PluralizationException($e->getMessage(), $e->getCode(), $e); |
143 | 143 | } |
144 | 144 | |
145 | - if (empty($parameters['n']) && is_numeric($number)) { |
|
145 | + if (empty($parameters['n']) && is_numeric($number)){ |
|
146 | 146 | $parameters['n'] = $number; |
147 | 147 | } |
148 | 148 | |
@@ -168,18 +168,18 @@ discard block |
||
168 | 168 | string $postfix = '}' |
169 | 169 | ): string { |
170 | 170 | $replaces = []; |
171 | - foreach ($values as $key => $value) { |
|
171 | + foreach ($values as $key => $value){ |
|
172 | 172 | $value = (is_array($value) || $value instanceof \Closure) ? '' : $value; |
173 | 173 | |
174 | - if (is_object($value)) { |
|
175 | - if (method_exists($value, '__toString')) { |
|
174 | + if (is_object($value)){ |
|
175 | + if (method_exists($value, '__toString')){ |
|
176 | 176 | $value = $value->__toString(); |
177 | - } else { |
|
177 | + }else{ |
|
178 | 178 | $value = ''; |
179 | 179 | } |
180 | 180 | } |
181 | 181 | |
182 | - $replaces[$prefix . $key . $postfix] = $value; |
|
182 | + $replaces[$prefix.$key.$postfix] = $value; |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | return strtr($string, $replaces); |
@@ -207,18 +207,18 @@ discard block |
||
207 | 207 | */ |
208 | 208 | protected function get(string &$locale, string $domain, string $string): string |
209 | 209 | { |
210 | - if ($this->catalogueManager->get($locale)->has($domain, $string)) { |
|
210 | + if ($this->catalogueManager->get($locale)->has($domain, $string)){ |
|
211 | 211 | return $this->catalogueManager->get($locale)->get($domain, $string); |
212 | 212 | } |
213 | 213 | |
214 | 214 | $locale = $this->config->getFallbackLocale(); |
215 | 215 | |
216 | - if ($this->catalogueManager->get($locale)->has($domain, $string)) { |
|
216 | + if ($this->catalogueManager->get($locale)->has($domain, $string)){ |
|
217 | 217 | return $this->catalogueManager->get($locale)->get($domain, $string); |
218 | 218 | } |
219 | 219 | |
220 | 220 | // we can automatically register message |
221 | - if ($this->config->isAutoRegisterMessages()) { |
|
221 | + if ($this->config->isAutoRegisterMessages()){ |
|
222 | 222 | $this->catalogueManager->get($locale)->set($domain, $string, $string); |
223 | 223 | $this->catalogueManager->save($locale); |
224 | 224 | } |
@@ -68,7 +68,8 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function setLocale(string $locale): void |
70 | 70 | { |
71 | - if (!$this->catalogueManager->has($locale)) { |
|
71 | + if (!$this->catalogueManager->has($locale)) |
|
72 | + { |
|
72 | 73 | throw new LocaleException($locale); |
73 | 74 | } |
74 | 75 | |
@@ -128,7 +129,8 @@ discard block |
||
128 | 129 | $domain = $domain ?? $this->config->getDefaultDomain(); |
129 | 130 | $locale = $locale ?? $this->locale; |
130 | 131 | |
131 | - try { |
|
132 | + try |
|
133 | + { |
|
132 | 134 | $message = $this->get($locale, $domain, $id); |
133 | 135 | |
134 | 136 | $pluralized = $this->identityTranslator->trans( |
@@ -137,12 +139,15 @@ discard block |
||
137 | 139 | null, |
138 | 140 | $locale |
139 | 141 | ); |
140 | - } catch (\InvalidArgumentException $e) { |
|
142 | + } |
|
143 | + catch (\InvalidArgumentException $e) |
|
144 | + { |
|
141 | 145 | //Wrapping into more explanatory exception |
142 | 146 | throw new PluralizationException($e->getMessage(), $e->getCode(), $e); |
143 | 147 | } |
144 | 148 | |
145 | - if (empty($parameters['n']) && is_numeric($number)) { |
|
149 | + if (empty($parameters['n']) && is_numeric($number)) |
|
150 | + { |
|
146 | 151 | $parameters['n'] = $number; |
147 | 152 | } |
148 | 153 | |
@@ -168,13 +173,18 @@ discard block |
||
168 | 173 | string $postfix = '}' |
169 | 174 | ): string { |
170 | 175 | $replaces = []; |
171 | - foreach ($values as $key => $value) { |
|
176 | + foreach ($values as $key => $value) |
|
177 | + { |
|
172 | 178 | $value = (is_array($value) || $value instanceof \Closure) ? '' : $value; |
173 | 179 | |
174 | - if (is_object($value)) { |
|
175 | - if (method_exists($value, '__toString')) { |
|
180 | + if (is_object($value)) |
|
181 | + { |
|
182 | + if (method_exists($value, '__toString')) |
|
183 | + { |
|
176 | 184 | $value = $value->__toString(); |
177 | - } else { |
|
185 | + } |
|
186 | + else |
|
187 | + { |
|
178 | 188 | $value = ''; |
179 | 189 | } |
180 | 190 | } |
@@ -207,18 +217,21 @@ discard block |
||
207 | 217 | */ |
208 | 218 | protected function get(string &$locale, string $domain, string $string): string |
209 | 219 | { |
210 | - if ($this->catalogueManager->get($locale)->has($domain, $string)) { |
|
220 | + if ($this->catalogueManager->get($locale)->has($domain, $string)) |
|
221 | + { |
|
211 | 222 | return $this->catalogueManager->get($locale)->get($domain, $string); |
212 | 223 | } |
213 | 224 | |
214 | 225 | $locale = $this->config->getFallbackLocale(); |
215 | 226 | |
216 | - if ($this->catalogueManager->get($locale)->has($domain, $string)) { |
|
227 | + if ($this->catalogueManager->get($locale)->has($domain, $string)) |
|
228 | + { |
|
217 | 229 | return $this->catalogueManager->get($locale)->get($domain, $string); |
218 | 230 | } |
219 | 231 | |
220 | 232 | // we can automatically register message |
221 | - if ($this->config->isAutoRegisterMessages()) { |
|
233 | + if ($this->config->isAutoRegisterMessages()) |
|
234 | + { |
|
222 | 235 | $this->catalogueManager->get($locale)->set($domain, $string, $string); |
223 | 236 | $this->catalogueManager->save($locale); |
224 | 237 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function registerMessage(string $domain, string $string, bool $resolveDomain = true): void |
63 | 63 | { |
64 | - if ($resolveDomain) { |
|
64 | + if ($resolveDomain){ |
|
65 | 65 | $domain = $this->config->resolveDomain($domain); |
66 | 66 | } |
67 | 67 | |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function indexClasses(ClassesInterface $locator): void |
84 | 84 | { |
85 | - foreach ($locator->getClasses(TranslatorTrait::class) as $class) { |
|
85 | + foreach ($locator->getClasses(TranslatorTrait::class) as $class){ |
|
86 | 86 | $strings = $this->fetchMessages($class, true); |
87 | - foreach ($strings as $string) { |
|
87 | + foreach ($strings as $string){ |
|
88 | 88 | $this->registerMessage($class->getName(), $string); |
89 | 89 | } |
90 | 90 | } |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | */ |
119 | 119 | private function registerInvocations(array $invocations): void |
120 | 120 | { |
121 | - foreach ($invocations as $invocation) { |
|
122 | - if ($invocation->getArgument(0)->getType() != ReflectionArgument::STRING) { |
|
121 | + foreach ($invocations as $invocation){ |
|
122 | + if ($invocation->getArgument(0)->getType() != ReflectionArgument::STRING){ |
|
123 | 123 | //We can only index invocations with constant string arguments |
124 | 124 | continue; |
125 | 125 | } |
@@ -142,20 +142,20 @@ discard block |
||
142 | 142 | { |
143 | 143 | $target = $reflection->getDefaultProperties() + $reflection->getConstants(); |
144 | 144 | |
145 | - foreach ($reflection->getProperties() as $property) { |
|
146 | - if (is_string($property->getDocComment()) && strpos($property->getDocComment(), '@do-not-index')) { |
|
145 | + foreach ($reflection->getProperties() as $property){ |
|
146 | + if (is_string($property->getDocComment()) && strpos($property->getDocComment(), '@do-not-index')){ |
|
147 | 147 | unset($target[$property->getName()]); |
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
151 | 151 | $strings = []; |
152 | 152 | array_walk_recursive($target, function ($value) use (&$strings): void { |
153 | - if (is_string($value) && Translator::isMessage($value)) { |
|
153 | + if (is_string($value) && Translator::isMessage($value)){ |
|
154 | 154 | $strings[] = $this->prepareMessage($value); |
155 | 155 | } |
156 | 156 | }); |
157 | 157 | |
158 | - if ($inherit && $reflection->getParentClass()) { |
|
158 | + if ($inherit && $reflection->getParentClass()){ |
|
159 | 159 | //Joining strings data with parent class values (inheritance ON) - resolved into same |
160 | 160 | //domain on export |
161 | 161 | $strings = array_merge( |
@@ -178,27 +178,27 @@ discard block |
||
178 | 178 | //Translation using default bundle |
179 | 179 | $domain = $this->config->getDefaultDomain(); |
180 | 180 | |
181 | - if ($invocation->getName() === 'say') { |
|
181 | + if ($invocation->getName() === 'say'){ |
|
182 | 182 | //Let's try to confirm domain |
183 | 183 | $domain = $this->config->resolveDomain($invocation->getClass()); |
184 | 184 | } |
185 | 185 | |
186 | 186 | //`l` and `p`, `say` functions |
187 | 187 | $argument = null; |
188 | - switch (strtolower($invocation->getName())) { |
|
188 | + switch (strtolower($invocation->getName())){ |
|
189 | 189 | case 'say': |
190 | 190 | case 'l': |
191 | - if ($invocation->countArguments() >= 3) { |
|
191 | + if ($invocation->countArguments() >= 3){ |
|
192 | 192 | $argument = $invocation->getArgument(2); |
193 | 193 | } |
194 | 194 | break; |
195 | 195 | case 'p': |
196 | - if ($invocation->countArguments() >= 4) { |
|
196 | + if ($invocation->countArguments() >= 4){ |
|
197 | 197 | $argument = $invocation->getArgument(3); |
198 | 198 | } |
199 | 199 | } |
200 | 200 | |
201 | - if (!empty($argument) && $argument->getType() === ReflectionArgument::STRING) { |
|
201 | + if (!empty($argument) && $argument->getType() === ReflectionArgument::STRING){ |
|
202 | 202 | //Domain specified in arguments |
203 | 203 | $domain = $this->config->resolveDomain($argument->stringValue()); |
204 | 204 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | */ |
215 | 215 | private function prepareMessage(string $string): string |
216 | 216 | { |
217 | - if (Translator::isMessage($string)) { |
|
217 | + if (Translator::isMessage($string)){ |
|
218 | 218 | $string = substr($string, 2, -2); |
219 | 219 | } |
220 | 220 |
@@ -61,7 +61,8 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function registerMessage(string $domain, string $string, bool $resolveDomain = true): void |
63 | 63 | { |
64 | - if ($resolveDomain) { |
|
64 | + if ($resolveDomain) |
|
65 | + { |
|
65 | 66 | $domain = $this->config->resolveDomain($domain); |
66 | 67 | } |
67 | 68 | |
@@ -82,9 +83,11 @@ discard block |
||
82 | 83 | */ |
83 | 84 | public function indexClasses(ClassesInterface $locator): void |
84 | 85 | { |
85 | - foreach ($locator->getClasses(TranslatorTrait::class) as $class) { |
|
86 | + foreach ($locator->getClasses(TranslatorTrait::class) as $class) |
|
87 | + { |
|
86 | 88 | $strings = $this->fetchMessages($class, true); |
87 | - foreach ($strings as $string) { |
|
89 | + foreach ($strings as $string) |
|
90 | + { |
|
88 | 91 | $this->registerMessage($class->getName(), $string); |
89 | 92 | } |
90 | 93 | } |
@@ -118,8 +121,10 @@ discard block |
||
118 | 121 | */ |
119 | 122 | private function registerInvocations(array $invocations): void |
120 | 123 | { |
121 | - foreach ($invocations as $invocation) { |
|
122 | - if ($invocation->getArgument(0)->getType() != ReflectionArgument::STRING) { |
|
124 | + foreach ($invocations as $invocation) |
|
125 | + { |
|
126 | + if ($invocation->getArgument(0)->getType() != ReflectionArgument::STRING) |
|
127 | + { |
|
123 | 128 | //We can only index invocations with constant string arguments |
124 | 129 | continue; |
125 | 130 | } |
@@ -142,20 +147,24 @@ discard block |
||
142 | 147 | { |
143 | 148 | $target = $reflection->getDefaultProperties() + $reflection->getConstants(); |
144 | 149 | |
145 | - foreach ($reflection->getProperties() as $property) { |
|
146 | - if (is_string($property->getDocComment()) && strpos($property->getDocComment(), '@do-not-index')) { |
|
150 | + foreach ($reflection->getProperties() as $property) |
|
151 | + { |
|
152 | + if (is_string($property->getDocComment()) && strpos($property->getDocComment(), '@do-not-index')) |
|
153 | + { |
|
147 | 154 | unset($target[$property->getName()]); |
148 | 155 | } |
149 | 156 | } |
150 | 157 | |
151 | 158 | $strings = []; |
152 | 159 | array_walk_recursive($target, function ($value) use (&$strings): void { |
153 | - if (is_string($value) && Translator::isMessage($value)) { |
|
160 | + if (is_string($value) && Translator::isMessage($value)) |
|
161 | + { |
|
154 | 162 | $strings[] = $this->prepareMessage($value); |
155 | 163 | } |
156 | 164 | }); |
157 | 165 | |
158 | - if ($inherit && $reflection->getParentClass()) { |
|
166 | + if ($inherit && $reflection->getParentClass()) |
|
167 | + { |
|
159 | 168 | //Joining strings data with parent class values (inheritance ON) - resolved into same |
160 | 169 | //domain on export |
161 | 170 | $strings = array_merge( |
@@ -178,27 +187,32 @@ discard block |
||
178 | 187 | //Translation using default bundle |
179 | 188 | $domain = $this->config->getDefaultDomain(); |
180 | 189 | |
181 | - if ($invocation->getName() === 'say') { |
|
190 | + if ($invocation->getName() === 'say') |
|
191 | + { |
|
182 | 192 | //Let's try to confirm domain |
183 | 193 | $domain = $this->config->resolveDomain($invocation->getClass()); |
184 | 194 | } |
185 | 195 | |
186 | 196 | //`l` and `p`, `say` functions |
187 | 197 | $argument = null; |
188 | - switch (strtolower($invocation->getName())) { |
|
198 | + switch (strtolower($invocation->getName())) |
|
199 | + { |
|
189 | 200 | case 'say': |
190 | 201 | case 'l': |
191 | - if ($invocation->countArguments() >= 3) { |
|
202 | + if ($invocation->countArguments() >= 3) |
|
203 | + { |
|
192 | 204 | $argument = $invocation->getArgument(2); |
193 | 205 | } |
194 | 206 | break; |
195 | 207 | case 'p': |
196 | - if ($invocation->countArguments() >= 4) { |
|
208 | + if ($invocation->countArguments() >= 4) |
|
209 | + { |
|
197 | 210 | $argument = $invocation->getArgument(3); |
198 | 211 | } |
199 | 212 | } |
200 | 213 | |
201 | - if (!empty($argument) && $argument->getType() === ReflectionArgument::STRING) { |
|
214 | + if (!empty($argument) && $argument->getType() === ReflectionArgument::STRING) |
|
215 | + { |
|
202 | 216 | //Domain specified in arguments |
203 | 217 | $domain = $this->config->resolveDomain($argument->stringValue()); |
204 | 218 | } |
@@ -214,7 +228,8 @@ discard block |
||
214 | 228 | */ |
215 | 229 | private function prepareMessage(string $string): string |
216 | 230 | { |
217 | - if (Translator::isMessage($string)) { |
|
231 | + if (Translator::isMessage($string)) |
|
232 | + { |
|
218 | 233 | $string = substr($string, 2, -2); |
219 | 234 | } |
220 | 235 |
@@ -77,7 +77,7 @@ |
||
77 | 77 | $container = new Container(); |
78 | 78 | $container->bind(TranslatorConfig::class, new TranslatorConfig([ |
79 | 79 | 'locale' => 'en', |
80 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
80 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
81 | 81 | 'loaders' => [ |
82 | 82 | 'php' => PhpFileLoader::class, |
83 | 83 | 'po' => PoFileLoader::class, |
@@ -44,7 +44,7 @@ |
||
44 | 44 | |
45 | 45 | $this->container->bind(TranslatorConfig::class, new TranslatorConfig([ |
46 | 46 | 'locale' => 'en', |
47 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
47 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
48 | 48 | 'loaders' => [ |
49 | 49 | 'php' => PhpFileLoader::class, |
50 | 50 | 'po' => PoFileLoader::class, |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | public function testHasLocale(): void |
26 | 26 | { |
27 | 27 | $loader = new CatalogueLoader(new TranslatorConfig([ |
28 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
28 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
29 | 29 | ])); |
30 | 30 | |
31 | 31 | $this->assertTrue($loader->hasLocale('ru')); |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | public function testGetLocales(): void |
36 | 36 | { |
37 | 37 | $loader = new CatalogueLoader(new TranslatorConfig([ |
38 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
38 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
39 | 39 | ])); |
40 | 40 | |
41 | 41 | $compared = $loader->getLocales(); |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | public function testLoadCatalogue(): void |
50 | 50 | { |
51 | 51 | $loader = new CatalogueLoader(new TranslatorConfig([ |
52 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
52 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
53 | 53 | 'loaders' => [ |
54 | 54 | 'php' => PhpFileLoader::class, |
55 | 55 | 'po' => PoFileLoader::class, |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | public function testLoadCatalogueNoLoader(): void |
90 | 90 | { |
91 | 91 | $loader = new CatalogueLoader(new TranslatorConfig([ |
92 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
92 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
93 | 93 | 'loaders' => [ |
94 | 94 | 'php' => PhpFileLoader::class, |
95 | 95 | ], |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | $cache->shouldReceive('setLocales')->andReturn(null); |
32 | 32 | |
33 | 33 | $manager = new CatalogueManager(new CatalogueLoader(new TranslatorConfig([ |
34 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
34 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
35 | 35 | 'loaders' => [ |
36 | 36 | 'php' => PhpFileLoader::class, |
37 | 37 | 'po' => PoFileLoader::class, |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | $cache->shouldNotReceive('setLocales')->andReturn(null); |
50 | 50 | |
51 | 51 | $manager = new CatalogueManager(new CatalogueLoader(new TranslatorConfig([ |
52 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
52 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
53 | 53 | 'loaders' => [ |
54 | 54 | 'php' => PhpFileLoader::class, |
55 | 55 | 'po' => PoFileLoader::class, |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | $cache->shouldReceive('getLocales')->andReturn(['en', 'ru']); |
67 | 67 | |
68 | 68 | $manager = new CatalogueManager(new CatalogueLoader(new TranslatorConfig([ |
69 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
69 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
70 | 70 | 'loaders' => [ |
71 | 71 | 'php' => PhpFileLoader::class, |
72 | 72 | 'po' => PoFileLoader::class, |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | ]); |
130 | 130 | |
131 | 131 | $manager = new CatalogueManager(new CatalogueLoader(new TranslatorConfig([ |
132 | - 'directory' => __DIR__ . '/fixtures/locales/', |
|
132 | + 'directory' => __DIR__.'/fixtures/locales/', |
|
133 | 133 | 'loaders' => [ |
134 | 134 | 'php' => PhpFileLoader::class, |
135 | 135 | 'po' => PoFileLoader::class, |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | { |
76 | 76 | $value = $this->data[$field] ?? $default; |
77 | 77 | |
78 | - if (is_object($value) && method_exists($value, 'getValue')) { |
|
78 | + if (is_object($value) && method_exists($value, 'getValue')){ |
|
79 | 79 | return $value->getValue(); |
80 | 80 | } |
81 | 81 | |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | */ |
88 | 88 | public function hasValue(string $field): bool |
89 | 89 | { |
90 | - if (is_array($this->data)) { |
|
90 | + if (is_array($this->data)){ |
|
91 | 91 | return array_key_exists($field, $this->data); |
92 | 92 | } |
93 | 93 | |
@@ -151,30 +151,30 @@ discard block |
||
151 | 151 | */ |
152 | 152 | protected function validate(): void |
153 | 153 | { |
154 | - if ($this->errors !== []) { |
|
154 | + if ($this->errors !== []){ |
|
155 | 155 | // already validated |
156 | 156 | return; |
157 | 157 | } |
158 | 158 | |
159 | 159 | $this->errors = []; |
160 | 160 | |
161 | - foreach ($this->rules as $field => $rules) { |
|
161 | + foreach ($this->rules as $field => $rules){ |
|
162 | 162 | $hasValue = $this->hasValue($field); |
163 | 163 | $value = $this->getValue($field); |
164 | 164 | |
165 | - foreach ($this->provider->getRules($rules) as $rule) { |
|
166 | - if (!$hasValue && $rule->ignoreEmpty($value) && !$rule->hasConditions()) { |
|
165 | + foreach ($this->provider->getRules($rules) as $rule){ |
|
166 | + if (!$hasValue && $rule->ignoreEmpty($value) && !$rule->hasConditions()){ |
|
167 | 167 | continue; |
168 | 168 | } |
169 | 169 | |
170 | - foreach ($rule->getConditions() as $condition) { |
|
171 | - if (!$condition->isMet($this, $field, $value)) { |
|
170 | + foreach ($rule->getConditions() as $condition){ |
|
171 | + if (!$condition->isMet($this, $field, $value)){ |
|
172 | 172 | // condition is not met, skipping validation |
173 | 173 | continue 2; |
174 | 174 | } |
175 | 175 | } |
176 | 176 | |
177 | - if (!$rule->validate($this, $field, $value)) { |
|
177 | + if (!$rule->validate($this, $field, $value)){ |
|
178 | 178 | // got error, jump to next field |
179 | 179 | $this->errors[$field] = $rule->getMessage($field, $value); |
180 | 180 | break; |
@@ -75,7 +75,8 @@ discard block |
||
75 | 75 | { |
76 | 76 | $value = $this->data[$field] ?? $default; |
77 | 77 | |
78 | - if (is_object($value) && method_exists($value, 'getValue')) { |
|
78 | + if (is_object($value) && method_exists($value, 'getValue')) |
|
79 | + { |
|
79 | 80 | return $value->getValue(); |
80 | 81 | } |
81 | 82 | |
@@ -87,7 +88,8 @@ discard block |
||
87 | 88 | */ |
88 | 89 | public function hasValue(string $field): bool |
89 | 90 | { |
90 | - if (is_array($this->data)) { |
|
91 | + if (is_array($this->data)) |
|
92 | + { |
|
91 | 93 | return array_key_exists($field, $this->data); |
92 | 94 | } |
93 | 95 | |
@@ -151,30 +153,37 @@ discard block |
||
151 | 153 | */ |
152 | 154 | protected function validate(): void |
153 | 155 | { |
154 | - if ($this->errors !== []) { |
|
156 | + if ($this->errors !== []) |
|
157 | + { |
|
155 | 158 | // already validated |
156 | 159 | return; |
157 | 160 | } |
158 | 161 | |
159 | 162 | $this->errors = []; |
160 | 163 | |
161 | - foreach ($this->rules as $field => $rules) { |
|
164 | + foreach ($this->rules as $field => $rules) |
|
165 | + { |
|
162 | 166 | $hasValue = $this->hasValue($field); |
163 | 167 | $value = $this->getValue($field); |
164 | 168 | |
165 | - foreach ($this->provider->getRules($rules) as $rule) { |
|
166 | - if (!$hasValue && $rule->ignoreEmpty($value) && !$rule->hasConditions()) { |
|
169 | + foreach ($this->provider->getRules($rules) as $rule) |
|
170 | + { |
|
171 | + if (!$hasValue && $rule->ignoreEmpty($value) && !$rule->hasConditions()) |
|
172 | + { |
|
167 | 173 | continue; |
168 | 174 | } |
169 | 175 | |
170 | - foreach ($rule->getConditions() as $condition) { |
|
171 | - if (!$condition->isMet($this, $field, $value)) { |
|
176 | + foreach ($rule->getConditions() as $condition) |
|
177 | + { |
|
178 | + if (!$condition->isMet($this, $field, $value)) |
|
179 | + { |
|
172 | 180 | // condition is not met, skipping validation |
173 | 181 | continue 2; |
174 | 182 | } |
175 | 183 | } |
176 | 184 | |
177 | - if (!$rule->validate($this, $field, $value)) { |
|
185 | + if (!$rule->validate($this, $field, $value)) |
|
186 | + { |
|
178 | 187 | // got error, jump to next field |
179 | 188 | $this->errors[$field] = $rule->getMessage($field, $value); |
180 | 189 | break; |