@@ -24,7 +24,7 @@ |
||
24 | 24 | return match (true) { |
25 | 25 | $string === $pattern => true, |
26 | 26 | !$this->isPattern($pattern) => false, |
27 | - default => (bool) \preg_match($this->getRegex($pattern), $string) |
|
27 | + default => (bool)\preg_match($this->getRegex($pattern), $string) |
|
28 | 28 | }; |
29 | 29 | } |
30 | 30 |
@@ -13,7 +13,7 @@ |
||
13 | 13 | protected string $locale, |
14 | 14 | int $code = 0, |
15 | 15 | \Throwable $previous = null |
16 | - ) { |
|
16 | + ){ |
|
17 | 17 | parent::__construct(\sprintf('Undefined locale \'%s\'', $locale), $code, $previous); |
18 | 18 | } |
19 | 19 |
@@ -33,13 +33,13 @@ discard block |
||
33 | 33 | */ |
34 | 34 | protected function say(string $string, array $options = [], string $bundle = null): string |
35 | 35 | { |
36 | - if (Translator::isMessage($string)) { |
|
36 | + if (Translator::isMessage($string)){ |
|
37 | 37 | //Cut [[ and ]] |
38 | 38 | $string = \substr($string, 2, -2); |
39 | 39 | } |
40 | 40 | |
41 | 41 | $container = ContainerScope::getContainer(); |
42 | - if (empty($container) || !$container->has(TranslatorInterface::class)) { |
|
42 | + if (empty($container) || !$container->has(TranslatorInterface::class)){ |
|
43 | 43 | return Translator::interpolate($string, $options); |
44 | 44 | } |
45 | 45 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | $translator = $container->get(TranslatorInterface::class); |
50 | 50 | |
51 | - if (\is_null($bundle)) { |
|
51 | + if (\is_null($bundle)){ |
|
52 | 52 | $bundle = $translator->getDomain(static::class); |
53 | 53 | } |
54 | 54 |
@@ -33,13 +33,15 @@ discard block |
||
33 | 33 | */ |
34 | 34 | protected function say(string $string, array $options = [], string $bundle = null): string |
35 | 35 | { |
36 | - if (Translator::isMessage($string)) { |
|
36 | + if (Translator::isMessage($string)) |
|
37 | + { |
|
37 | 38 | //Cut [[ and ]] |
38 | 39 | $string = \substr($string, 2, -2); |
39 | 40 | } |
40 | 41 | |
41 | 42 | $container = ContainerScope::getContainer(); |
42 | - if (empty($container) || !$container->has(TranslatorInterface::class)) { |
|
43 | + if (empty($container) || !$container->has(TranslatorInterface::class)) |
|
44 | + { |
|
43 | 45 | return Translator::interpolate($string, $options); |
44 | 46 | } |
45 | 47 | |
@@ -48,7 +50,8 @@ discard block |
||
48 | 50 | */ |
49 | 51 | $translator = $container->get(TranslatorInterface::class); |
50 | 52 | |
51 | - if (\is_null($bundle)) { |
|
53 | + if (\is_null($bundle)) |
|
54 | + { |
|
52 | 55 | $bundle = $translator->getDomain(static::class); |
53 | 56 | } |
54 | 57 |
@@ -8,6 +8,6 @@ |
||
8 | 8 | { |
9 | 9 | public function __construct( |
10 | 10 | public readonly string $locale, |
11 | - ) { |
|
11 | + ){ |
|
12 | 12 | } |
13 | 13 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | use Spiral\Translator\Exception\TranslatorException; |
8 | 8 | use Spiral\Translator\TranslatorInterface; |
9 | 9 | |
10 | -if (!\function_exists('l')) { |
|
10 | +if (!\function_exists('l')){ |
|
11 | 11 | /** |
12 | 12 | * Translate message using default or specific bundle name. |
13 | 13 | * |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | { |
23 | 23 | /** @psalm-suppress InternalMethod */ |
24 | 24 | $container = ContainerScope::getContainer(); |
25 | - if ($container === null || !$container->has(TranslatorInterface::class)) { |
|
25 | + if ($container === null || !$container->has(TranslatorInterface::class)){ |
|
26 | 26 | throw new ScopeException( |
27 | 27 | '`TranslatorInterface` binding is missing or container scope is not set' |
28 | 28 | ); |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
38 | -if (!\function_exists('p')) { |
|
38 | +if (!\function_exists('p')){ |
|
39 | 39 | /** |
40 | 40 | * Pluralize string using language pluralization options and specified numeric value. |
41 | 41 | * |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | { |
52 | 52 | /** @psalm-suppress InternalMethod */ |
53 | 53 | $container = ContainerScope::getContainer(); |
54 | - if (empty($container) || !$container->has(TranslatorInterface::class)) { |
|
54 | + if (empty($container) || !$container->has(TranslatorInterface::class)){ |
|
55 | 55 | throw new ScopeException( |
56 | 56 | '`TranslatorInterface` binding is missing or container scope is not set' |
57 | 57 | ); |
@@ -7,7 +7,8 @@ discard block |
||
7 | 7 | use Spiral\Translator\Exception\TranslatorException; |
8 | 8 | use Spiral\Translator\TranslatorInterface; |
9 | 9 | |
10 | -if (!\function_exists('l')) { |
|
10 | +if (!\function_exists('l')) |
|
11 | +{ |
|
11 | 12 | /** |
12 | 13 | * Translate message using default or specific bundle name. |
13 | 14 | * |
@@ -22,7 +23,8 @@ discard block |
||
22 | 23 | { |
23 | 24 | /** @psalm-suppress InternalMethod */ |
24 | 25 | $container = ContainerScope::getContainer(); |
25 | - if ($container === null || !$container->has(TranslatorInterface::class)) { |
|
26 | + if ($container === null || !$container->has(TranslatorInterface::class)) |
|
27 | + { |
|
26 | 28 | throw new ScopeException( |
27 | 29 | '`TranslatorInterface` binding is missing or container scope is not set' |
28 | 30 | ); |
@@ -35,7 +37,8 @@ discard block |
||
35 | 37 | } |
36 | 38 | } |
37 | 39 | |
38 | -if (!\function_exists('p')) { |
|
40 | +if (!\function_exists('p')) |
|
41 | +{ |
|
39 | 42 | /** |
40 | 43 | * Pluralize string using language pluralization options and specified numeric value. |
41 | 44 | * |
@@ -51,7 +54,8 @@ discard block |
||
51 | 54 | { |
52 | 55 | /** @psalm-suppress InternalMethod */ |
53 | 56 | $container = ContainerScope::getContainer(); |
54 | - if (empty($container) || !$container->has(TranslatorInterface::class)) { |
|
57 | + if (empty($container) || !$container->has(TranslatorInterface::class)) |
|
58 | + { |
|
55 | 59 | throw new ScopeException( |
56 | 60 | '`TranslatorInterface` binding is missing or container scope is not set' |
57 | 61 | ); |
@@ -31,7 +31,7 @@ |
||
31 | 31 | |
32 | 32 | public function loadCatalogue(string $locale): CatalogueInterface |
33 | 33 | { |
34 | - if (!$this->hasLocale($locale)) { |
|
34 | + if (!$this->hasLocale($locale)){ |
|
35 | 35 | throw new LocaleException($locale); |
36 | 36 | } |
37 | 37 |
@@ -31,7 +31,8 @@ |
||
31 | 31 | |
32 | 32 | public function loadCatalogue(string $locale): CatalogueInterface |
33 | 33 | { |
34 | - if (!$this->hasLocale($locale)) { |
|
34 | + if (!$this->hasLocale($locale)) |
|
35 | + { |
|
35 | 36 | throw new LocaleException($locale); |
36 | 37 | } |
37 | 38 |
@@ -24,18 +24,18 @@ discard block |
||
24 | 24 | public function __construct( |
25 | 25 | private readonly LoaderInterface $loader, |
26 | 26 | CacheInterface $cache = null |
27 | - ) { |
|
27 | + ){ |
|
28 | 28 | $this->cache = $cache ?? new NullCache(); |
29 | 29 | } |
30 | 30 | |
31 | 31 | public function getLocales(): array |
32 | 32 | { |
33 | - if ($this->locales !== []) { |
|
33 | + if ($this->locales !== []){ |
|
34 | 34 | return $this->locales; |
35 | 35 | } |
36 | 36 | |
37 | 37 | $this->locales = (array)$this->cache->getLocales(); |
38 | - if ($this->locales === []) { |
|
38 | + if ($this->locales === []){ |
|
39 | 39 | $this->locales = $this->loader->getLocales(); |
40 | 40 | $this->cache->setLocales($this->locales); |
41 | 41 | } |
@@ -45,14 +45,14 @@ discard block |
||
45 | 45 | |
46 | 46 | public function load(string $locale): CatalogueInterface |
47 | 47 | { |
48 | - if (isset($this->catalogues[$locale])) { |
|
48 | + if (isset($this->catalogues[$locale])){ |
|
49 | 49 | return $this->catalogues[$locale]; |
50 | 50 | } |
51 | 51 | |
52 | 52 | $data = (array)$this->cache->loadLocale($locale); |
53 | - if (!empty($data)) { |
|
53 | + if (!empty($data)){ |
|
54 | 54 | $this->catalogues[$locale] = new Catalogue($locale, $data); |
55 | - } else { |
|
55 | + }else{ |
|
56 | 56 | $this->catalogues[$locale] = $this->loader->loadCatalogue($locale); |
57 | 57 | } |
58 | 58 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | public function reset(): void |
81 | 81 | { |
82 | 82 | $this->cache->setLocales(null); |
83 | - foreach ($this->getLocales() as $locale) { |
|
83 | + foreach ($this->getLocales() as $locale){ |
|
84 | 84 | $this->cache->saveLocale($locale, null); |
85 | 85 | } |
86 | 86 |
@@ -30,12 +30,14 @@ discard block |
||
30 | 30 | |
31 | 31 | public function getLocales(): array |
32 | 32 | { |
33 | - if ($this->locales !== []) { |
|
33 | + if ($this->locales !== []) |
|
34 | + { |
|
34 | 35 | return $this->locales; |
35 | 36 | } |
36 | 37 | |
37 | 38 | $this->locales = (array)$this->cache->getLocales(); |
38 | - if ($this->locales === []) { |
|
39 | + if ($this->locales === []) |
|
40 | + { |
|
39 | 41 | $this->locales = $this->loader->getLocales(); |
40 | 42 | $this->cache->setLocales($this->locales); |
41 | 43 | } |
@@ -45,14 +47,18 @@ discard block |
||
45 | 47 | |
46 | 48 | public function load(string $locale): CatalogueInterface |
47 | 49 | { |
48 | - if (isset($this->catalogues[$locale])) { |
|
50 | + if (isset($this->catalogues[$locale])) |
|
51 | + { |
|
49 | 52 | return $this->catalogues[$locale]; |
50 | 53 | } |
51 | 54 | |
52 | 55 | $data = (array)$this->cache->loadLocale($locale); |
53 | - if (!empty($data)) { |
|
56 | + if (!empty($data)) |
|
57 | + { |
|
54 | 58 | $this->catalogues[$locale] = new Catalogue($locale, $data); |
55 | - } else { |
|
59 | + } |
|
60 | + else |
|
61 | + { |
|
56 | 62 | $this->catalogues[$locale] = $this->loader->loadCatalogue($locale); |
57 | 63 | } |
58 | 64 | |
@@ -80,7 +86,8 @@ discard block |
||
80 | 86 | public function reset(): void |
81 | 87 | { |
82 | 88 | $this->cache->setLocales(null); |
83 | - foreach ($this->getLocales() as $locale) { |
|
89 | + foreach ($this->getLocales() as $locale) |
|
90 | + { |
|
84 | 91 | $this->cache->saveLocale($locale, null); |
85 | 92 | } |
86 | 93 |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | public function __construct( |
20 | 20 | private readonly string $locale, |
21 | 21 | private array $data = [] |
22 | - ) { |
|
22 | + ){ |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | public function getLocale(): string |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | |
35 | 35 | public function has(string $domain, string $id): bool |
36 | 36 | { |
37 | - if (!isset($this->data[$domain])) { |
|
37 | + if (!isset($this->data[$domain])){ |
|
38 | 38 | return false; |
39 | 39 | } |
40 | 40 | |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | |
44 | 44 | public function get(string $domain, string $id): string |
45 | 45 | { |
46 | - if (!$this->has($domain, $id)) { |
|
46 | + if (!$this->has($domain, $id)){ |
|
47 | 47 | throw new CatalogueException(\sprintf("Undefined string in domain '%s'", $domain)); |
48 | 48 | } |
49 | 49 | |
@@ -66,15 +66,15 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function mergeFrom(MessageCatalogue $catalogue, bool $follow = true): void |
68 | 68 | { |
69 | - foreach ($catalogue->all() as $domain => $messages) { |
|
70 | - if (!isset($this->data[$domain])) { |
|
69 | + foreach ($catalogue->all() as $domain => $messages){ |
|
70 | + if (!isset($this->data[$domain])){ |
|
71 | 71 | $this->data[$domain] = []; |
72 | 72 | } |
73 | 73 | |
74 | - if ($follow) { |
|
74 | + if ($follow){ |
|
75 | 75 | //MessageCatalogue string has higher priority that string stored in memory |
76 | 76 | $this->data[$domain] = \array_merge($messages, $this->data[$domain]); |
77 | - } else { |
|
77 | + }else{ |
|
78 | 78 | $this->data[$domain] = \array_merge($this->data[$domain], $messages); |
79 | 79 | } |
80 | 80 | } |
@@ -34,7 +34,8 @@ discard block |
||
34 | 34 | |
35 | 35 | public function has(string $domain, string $id): bool |
36 | 36 | { |
37 | - if (!isset($this->data[$domain])) { |
|
37 | + if (!isset($this->data[$domain])) |
|
38 | + { |
|
38 | 39 | return false; |
39 | 40 | } |
40 | 41 | |
@@ -43,7 +44,8 @@ discard block |
||
43 | 44 | |
44 | 45 | public function get(string $domain, string $id): string |
45 | 46 | { |
46 | - if (!$this->has($domain, $id)) { |
|
47 | + if (!$this->has($domain, $id)) |
|
48 | + { |
|
47 | 49 | throw new CatalogueException(\sprintf("Undefined string in domain '%s'", $domain)); |
48 | 50 | } |
49 | 51 | |
@@ -66,15 +68,20 @@ discard block |
||
66 | 68 | */ |
67 | 69 | public function mergeFrom(MessageCatalogue $catalogue, bool $follow = true): void |
68 | 70 | { |
69 | - foreach ($catalogue->all() as $domain => $messages) { |
|
70 | - if (!isset($this->data[$domain])) { |
|
71 | + foreach ($catalogue->all() as $domain => $messages) |
|
72 | + { |
|
73 | + if (!isset($this->data[$domain])) |
|
74 | + { |
|
71 | 75 | $this->data[$domain] = []; |
72 | 76 | } |
73 | 77 | |
74 | - if ($follow) { |
|
78 | + if ($follow) |
|
79 | + { |
|
75 | 80 | //MessageCatalogue string has higher priority that string stored in memory |
76 | 81 | $this->data[$domain] = \array_merge($messages, $this->data[$domain]); |
77 | - } else { |
|
82 | + } |
|
83 | + else |
|
84 | + { |
|
78 | 85 | $this->data[$domain] = \array_merge($this->data[$domain], $messages); |
79 | 86 | } |
80 | 87 | } |
@@ -19,11 +19,16 @@ |
||
19 | 19 | |
20 | 20 | public function create(mixed $duration): \DateInterval |
21 | 21 | { |
22 | - try { |
|
22 | + try |
|
23 | + { |
|
23 | 24 | return $this->createOrFail($duration); |
24 | - } catch (\InvalidArgumentException $e) { |
|
25 | + } |
|
26 | + catch (\InvalidArgumentException $e) |
|
27 | + { |
|
25 | 28 | throw $e; |
26 | - } catch (\Throwable $e) { |
|
29 | + } |
|
30 | + catch (\Throwable $e) |
|
31 | + { |
|
27 | 32 | throw new \InvalidArgumentException($e->getMessage(), (int)$e->getCode(), $e); |
28 | 33 | } |
29 | 34 | } |
@@ -14,16 +14,16 @@ discard block |
||
14 | 14 | |
15 | 15 | public function __construct( |
16 | 16 | private readonly DateTimeFactoryInterface $factory = new DateTimeFactory() |
17 | - ) { |
|
17 | + ){ |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | public function create(mixed $duration): \DateInterval |
21 | 21 | { |
22 | - try { |
|
22 | + try{ |
|
23 | 23 | return $this->createOrFail($duration); |
24 | - } catch (\InvalidArgumentException $e) { |
|
24 | + }catch (\InvalidArgumentException $e){ |
|
25 | 25 | throw $e; |
26 | - } catch (\Throwable $e) { |
|
26 | + }catch (\Throwable $e){ |
|
27 | 27 | throw new \InvalidArgumentException($e->getMessage(), (int)$e->getCode(), $e); |
28 | 28 | } |
29 | 29 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $duration instanceof \DateInterval => $duration, |
45 | 45 | $duration instanceof \DateTimeInterface => $this->factory->now()->diff($duration), |
46 | 46 | \is_string($duration) => new \DateInterval($duration), |
47 | - \is_int($duration) => new \DateInterval('PT' . $duration . 'S'), |
|
47 | + \is_int($duration) => new \DateInterval('PT'.$duration.'S'), |
|
48 | 48 | $duration === null => new \DateInterval('PT0S'), |
49 | 49 | default => throw new \InvalidArgumentException( |
50 | 50 | \sprintf(self::ERROR_INVALID_INTERVAL_TYPE, \get_debug_type($duration)) |