@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | { |
55 | 55 | $manager = new CacheManager($config, $container); |
56 | 56 | |
57 | - foreach ($config->getAliases() as $alias => $storageName) { |
|
57 | + foreach ($config->getAliases() as $alias => $storageName){ |
|
58 | 58 | $container->bind($alias, static fn(CacheManager $manager) => $manager->storage($storageName)); |
59 | 59 | } |
60 | 60 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | ], |
75 | 75 | 'file' => [ |
76 | 76 | 'type' => 'file', |
77 | - 'path' => $dirs->get('runtime') . 'cache', |
|
77 | + 'path' => $dirs->get('runtime').'cache', |
|
78 | 78 | ], |
79 | 79 | ], |
80 | 80 | 'typeAliases' => [ |
@@ -54,7 +54,8 @@ |
||
54 | 54 | { |
55 | 55 | $manager = new CacheManager($config, $container); |
56 | 56 | |
57 | - foreach ($config->getAliases() as $alias => $storageName) { |
|
57 | + foreach ($config->getAliases() as $alias => $storageName) |
|
58 | + { |
|
58 | 59 | $container->bind($alias, static fn(CacheManager $manager) => $manager->storage($storageName)); |
59 | 60 | } |
60 | 61 |
@@ -27,21 +27,21 @@ discard block |
||
27 | 27 | |
28 | 28 | public function createInjection(ReflectionClass $class, string $context = null): CacheInterface |
29 | 29 | { |
30 | - try { |
|
31 | - if ($context === null) { |
|
30 | + try{ |
|
31 | + if ($context === null){ |
|
32 | 32 | $connection = $this->provider->storage(); |
33 | - } else { |
|
33 | + }else{ |
|
34 | 34 | // Get Cache by context |
35 | - try { |
|
35 | + try{ |
|
36 | 36 | $connection = $this->provider->storage($context); |
37 | - } catch (InvalidArgumentException $e) { |
|
37 | + }catch (InvalidArgumentException $e){ |
|
38 | 38 | // Case when context doesn't match to configured connections |
39 | 39 | return $this->provider->storage(); |
40 | 40 | } |
41 | 41 | } |
42 | 42 | |
43 | 43 | $this->matchType($class, $context, $connection); |
44 | - } catch (Throwable $e) { |
|
44 | + }catch (Throwable $e){ |
|
45 | 45 | throw new ContainerException(sprintf("Can't inject the required cache. %s", $e->getMessage()), 0, $e); |
46 | 46 | } |
47 | 47 | |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | private function matchType(ReflectionClass $class, ?string $context, CacheInterface $connection): void |
57 | 57 | { |
58 | 58 | $className = $class->getName(); |
59 | - if ($className !== CacheInterface::class && !$connection instanceof $className) { |
|
59 | + if ($className !== CacheInterface::class && !$connection instanceof $className){ |
|
60 | 60 | throw new RuntimeException( |
61 | 61 | \sprintf( |
62 | 62 | "The cache obtained by the context `%s` doesn't match the type `%s`.", |
@@ -27,21 +27,30 @@ discard block |
||
27 | 27 | |
28 | 28 | public function createInjection(ReflectionClass $class, string $context = null): CacheInterface |
29 | 29 | { |
30 | - try { |
|
31 | - if ($context === null) { |
|
30 | + try |
|
31 | + { |
|
32 | + if ($context === null) |
|
33 | + { |
|
32 | 34 | $connection = $this->provider->storage(); |
33 | - } else { |
|
35 | + } |
|
36 | + else |
|
37 | + { |
|
34 | 38 | // Get Cache by context |
35 | - try { |
|
39 | + try |
|
40 | + { |
|
36 | 41 | $connection = $this->provider->storage($context); |
37 | - } catch (InvalidArgumentException $e) { |
|
42 | + } |
|
43 | + catch (InvalidArgumentException $e) |
|
44 | + { |
|
38 | 45 | // Case when context doesn't match to configured connections |
39 | 46 | return $this->provider->storage(); |
40 | 47 | } |
41 | 48 | } |
42 | 49 | |
43 | 50 | $this->matchType($class, $context, $connection); |
44 | - } catch (Throwable $e) { |
|
51 | + } |
|
52 | + catch (Throwable $e) |
|
53 | + { |
|
45 | 54 | throw new ContainerException(sprintf("Can't inject the required cache. %s", $e->getMessage()), 0, $e); |
46 | 55 | } |
47 | 56 | |
@@ -56,7 +65,8 @@ discard block |
||
56 | 65 | private function matchType(ReflectionClass $class, ?string $context, CacheInterface $connection): void |
57 | 66 | { |
58 | 67 | $className = $class->getName(); |
59 | - if ($className !== CacheInterface::class && !$connection instanceof $className) { |
|
68 | + if ($className !== CacheInterface::class && !$connection instanceof $className) |
|
69 | + { |
|
60 | 70 | throw new RuntimeException( |
61 | 71 | \sprintf( |
62 | 72 | "The cache obtained by the context `%s` doesn't match the type `%s`.", |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | { |
36 | 36 | return $this->files->write( |
37 | 37 | $this->makePath($key), |
38 | - $this->ttlToTimestamp($ttl) . serialize($value), |
|
38 | + $this->ttlToTimestamp($ttl).serialize($value), |
|
39 | 39 | null, |
40 | 40 | true |
41 | 41 | ); |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | |
44 | 44 | public function delete($key): bool |
45 | 45 | { |
46 | - if ($this->has($key)) { |
|
46 | + if ($this->has($key)){ |
|
47 | 47 | return $this->files->delete($this->makePath($key)); |
48 | 48 | } |
49 | 49 | |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | |
53 | 53 | public function clear(): bool |
54 | 54 | { |
55 | - if (!$this->files->isDirectory($this->path)) { |
|
55 | + if (!$this->files->isDirectory($this->path)){ |
|
56 | 56 | return false; |
57 | 57 | } |
58 | 58 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | { |
66 | 66 | $result = []; |
67 | 67 | |
68 | - foreach ($keys as $key) { |
|
68 | + foreach ($keys as $key){ |
|
69 | 69 | $result[$key] = $this->get($key, $default); |
70 | 70 | } |
71 | 71 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | { |
77 | 77 | $state = null; |
78 | 78 | |
79 | - foreach ($values as $key => $value) { |
|
79 | + foreach ($values as $key => $value){ |
|
80 | 80 | $result = $this->set($key, $value, $ttl); |
81 | 81 | $state = is_null($state) ? $result : $result && $state; |
82 | 82 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | public function deleteMultiple($keys) |
88 | 88 | { |
89 | 89 | $state = null; |
90 | - foreach ($keys as $key) { |
|
90 | + foreach ($keys as $key){ |
|
91 | 91 | $result = $this->delete($key); |
92 | 92 | $state = is_null($state) ? $result : $result && $state; |
93 | 93 | } |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | { |
108 | 108 | $parts = array_slice(str_split($hash = sha1($key), 2), 0, 2); |
109 | 109 | |
110 | - return $this->path . '/' . implode('/', $parts) . '/' . $hash; |
|
110 | + return $this->path.'/'.implode('/', $parts).'/'.$hash; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -117,25 +117,25 @@ discard block |
||
117 | 117 | { |
118 | 118 | $path = $this->makePath($key); |
119 | 119 | |
120 | - try { |
|
121 | - $expire = (int) substr( |
|
120 | + try{ |
|
121 | + $expire = (int)substr( |
|
122 | 122 | $contents = $this->files->read($path), |
123 | 123 | 0, |
124 | 124 | 10 |
125 | 125 | ); |
126 | - } catch (FileNotFoundException $e) { |
|
126 | + }catch (FileNotFoundException $e){ |
|
127 | 127 | return $this->makeEmptyPayload(); |
128 | 128 | } |
129 | 129 | |
130 | - if (time() >= $expire) { |
|
130 | + if (time() >= $expire){ |
|
131 | 131 | $this->delete($key); |
132 | 132 | |
133 | 133 | return $this->makeEmptyPayload(); |
134 | 134 | } |
135 | 135 | |
136 | - try { |
|
136 | + try{ |
|
137 | 137 | $data = unserialize(substr($contents, 10)); |
138 | - } catch (Exception $e) { |
|
138 | + }catch (Exception $e){ |
|
139 | 139 | $this->delete($key); |
140 | 140 | |
141 | 141 | return $this->makeEmptyPayload(); |
@@ -43,7 +43,8 @@ discard block |
||
43 | 43 | |
44 | 44 | public function delete($key): bool |
45 | 45 | { |
46 | - if ($this->has($key)) { |
|
46 | + if ($this->has($key)) |
|
47 | + { |
|
47 | 48 | return $this->files->delete($this->makePath($key)); |
48 | 49 | } |
49 | 50 | |
@@ -52,7 +53,8 @@ discard block |
||
52 | 53 | |
53 | 54 | public function clear(): bool |
54 | 55 | { |
55 | - if (!$this->files->isDirectory($this->path)) { |
|
56 | + if (!$this->files->isDirectory($this->path)) |
|
57 | + { |
|
56 | 58 | return false; |
57 | 59 | } |
58 | 60 | |
@@ -65,7 +67,8 @@ discard block |
||
65 | 67 | { |
66 | 68 | $result = []; |
67 | 69 | |
68 | - foreach ($keys as $key) { |
|
70 | + foreach ($keys as $key) |
|
71 | + { |
|
69 | 72 | $result[$key] = $this->get($key, $default); |
70 | 73 | } |
71 | 74 | |
@@ -76,7 +79,8 @@ discard block |
||
76 | 79 | { |
77 | 80 | $state = null; |
78 | 81 | |
79 | - foreach ($values as $key => $value) { |
|
82 | + foreach ($values as $key => $value) |
|
83 | + { |
|
80 | 84 | $result = $this->set($key, $value, $ttl); |
81 | 85 | $state = is_null($state) ? $result : $result && $state; |
82 | 86 | } |
@@ -87,7 +91,8 @@ discard block |
||
87 | 91 | public function deleteMultiple($keys) |
88 | 92 | { |
89 | 93 | $state = null; |
90 | - foreach ($keys as $key) { |
|
94 | + foreach ($keys as $key) |
|
95 | + { |
|
91 | 96 | $result = $this->delete($key); |
92 | 97 | $state = is_null($state) ? $result : $result && $state; |
93 | 98 | } |
@@ -117,25 +122,32 @@ discard block |
||
117 | 122 | { |
118 | 123 | $path = $this->makePath($key); |
119 | 124 | |
120 | - try { |
|
125 | + try |
|
126 | + { |
|
121 | 127 | $expire = (int) substr( |
122 | 128 | $contents = $this->files->read($path), |
123 | 129 | 0, |
124 | 130 | 10 |
125 | 131 | ); |
126 | - } catch (FileNotFoundException $e) { |
|
132 | + } |
|
133 | + catch (FileNotFoundException $e) |
|
134 | + { |
|
127 | 135 | return $this->makeEmptyPayload(); |
128 | 136 | } |
129 | 137 | |
130 | - if (time() >= $expire) { |
|
138 | + if (time() >= $expire) |
|
139 | + { |
|
131 | 140 | $this->delete($key); |
132 | 141 | |
133 | 142 | return $this->makeEmptyPayload(); |
134 | 143 | } |
135 | 144 | |
136 | - try { |
|
145 | + try |
|
146 | + { |
|
137 | 147 | $data = unserialize(substr($contents, 10)); |
138 | - } catch (Exception $e) { |
|
148 | + } |
|
149 | + catch (Exception $e) |
|
150 | + { |
|
139 | 151 | $this->delete($key); |
140 | 152 | |
141 | 153 | return $this->makeEmptyPayload(); |
@@ -33,21 +33,21 @@ |
||
33 | 33 | */ |
34 | 34 | private function ttlToTimestamp($ttl): int |
35 | 35 | { |
36 | - if ($ttl === null) { |
|
36 | + if ($ttl === null){ |
|
37 | 37 | return $this->ttl + time(); |
38 | 38 | } |
39 | 39 | |
40 | - if ($ttl instanceof DateInterval) { |
|
40 | + if ($ttl instanceof DateInterval){ |
|
41 | 41 | return $this->now() |
42 | 42 | ->add($ttl) |
43 | 43 | ->getTimestamp(); |
44 | 44 | } |
45 | 45 | |
46 | - if ($ttl instanceof DateTimeInterface) { |
|
46 | + if ($ttl instanceof DateTimeInterface){ |
|
47 | 47 | return $ttl->getTimestamp(); |
48 | 48 | } |
49 | 49 | |
50 | - if (\is_int($ttl)) { |
|
50 | + if (\is_int($ttl)){ |
|
51 | 51 | $now = $this->now(); |
52 | 52 | |
53 | 53 | return $now->getTimestamp() + $ttl; |
@@ -33,21 +33,25 @@ |
||
33 | 33 | */ |
34 | 34 | private function ttlToTimestamp($ttl): int |
35 | 35 | { |
36 | - if ($ttl === null) { |
|
36 | + if ($ttl === null) |
|
37 | + { |
|
37 | 38 | return $this->ttl + time(); |
38 | 39 | } |
39 | 40 | |
40 | - if ($ttl instanceof DateInterval) { |
|
41 | + if ($ttl instanceof DateInterval) |
|
42 | + { |
|
41 | 43 | return $this->now() |
42 | 44 | ->add($ttl) |
43 | 45 | ->getTimestamp(); |
44 | 46 | } |
45 | 47 | |
46 | - if ($ttl instanceof DateTimeInterface) { |
|
48 | + if ($ttl instanceof DateTimeInterface) |
|
49 | + { |
|
47 | 50 | return $ttl->getTimestamp(); |
48 | 51 | } |
49 | 52 | |
50 | - if (\is_int($ttl)) { |
|
53 | + if (\is_int($ttl)) |
|
54 | + { |
|
51 | 55 | $now = $this->now(); |
52 | 56 | |
53 | 57 | return $now->getTimestamp() + $ttl; |
@@ -33,9 +33,9 @@ |
||
33 | 33 | */ |
34 | 34 | public function loadFile(string $section, string $filename): array |
35 | 35 | { |
36 | - try { |
|
36 | + try{ |
|
37 | 37 | return ContainerScope::runScope($this->container, fn() => require $filename); |
38 | - } catch (Throwable $e) { |
|
38 | + }catch (Throwable $e){ |
|
39 | 39 | throw new LoaderException($e->getMessage(), $e->getCode(), $e); |
40 | 40 | } |
41 | 41 | } |
@@ -33,9 +33,12 @@ |
||
33 | 33 | */ |
34 | 34 | public function loadFile(string $section, string $filename): array |
35 | 35 | { |
36 | - try { |
|
36 | + try |
|
37 | + { |
|
37 | 38 | return ContainerScope::runScope($this->container, fn() => require $filename); |
38 | - } catch (Throwable $e) { |
|
39 | + } |
|
40 | + catch (Throwable $e) |
|
41 | + { |
|
39 | 42 | throw new LoaderException($e->getMessage(), $e->getCode(), $e); |
40 | 43 | } |
41 | 44 | } |
@@ -62,11 +62,11 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function setDefaults(string $section, array $data): void |
64 | 64 | { |
65 | - if (isset($this->defaults[$section])) { |
|
65 | + if (isset($this->defaults[$section])){ |
|
66 | 66 | throw new ConfiguratorException("Unable to set default config `{$section}` more than once."); |
67 | 67 | } |
68 | 68 | |
69 | - if (isset($this->data[$section])) { |
|
69 | + if (isset($this->data[$section])){ |
|
70 | 70 | throw new ConfigDeliveredException("Unable to set default config `{$section}`, config has been loaded."); |
71 | 71 | } |
72 | 72 | |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function modify(string $section, PatchInterface $patch): array |
80 | 80 | { |
81 | - if (isset($this->instances[$section])) { |
|
82 | - if ($this->strict) { |
|
81 | + if (isset($this->instances[$section])){ |
|
82 | + if ($this->strict){ |
|
83 | 83 | throw new ConfigDeliveredException( |
84 | 84 | "Unable to patch config `{$section}`, config object has already been delivered." |
85 | 85 | ); |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | |
91 | 91 | $data = $this->getConfig($section); |
92 | 92 | |
93 | - try { |
|
93 | + try{ |
|
94 | 94 | return $this->data[$section] = $patch->patch($data); |
95 | - } catch (PatchException $e) { |
|
95 | + }catch (PatchException $e){ |
|
96 | 96 | throw new PatchException("Unable to modify config `{$section}`.", $e->getCode(), $e); |
97 | 97 | } |
98 | 98 | } |
@@ -102,18 +102,18 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function getConfig(string $section = null): array |
104 | 104 | { |
105 | - if (isset($this->data[$section])) { |
|
105 | + if (isset($this->data[$section])){ |
|
106 | 106 | return $this->data[$section]; |
107 | 107 | } |
108 | 108 | |
109 | - if (isset($this->defaults[$section])) { |
|
109 | + if (isset($this->defaults[$section])){ |
|
110 | 110 | $data = []; |
111 | - if ($this->loader->has($section)) { |
|
111 | + if ($this->loader->has($section)){ |
|
112 | 112 | $data = $this->loader->load($section); |
113 | 113 | } |
114 | 114 | |
115 | 115 | $data = array_merge($this->defaults[$section], $data); |
116 | - } else { |
|
116 | + }else{ |
|
117 | 117 | $data = $this->loader->load($section); |
118 | 118 | } |
119 | 119 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | public function createInjection(ReflectionClass $class, string $context = null) |
127 | 127 | { |
128 | 128 | $config = $class->getConstant('CONFIG'); |
129 | - if (isset($this->instances[$config])) { |
|
129 | + if (isset($this->instances[$config])){ |
|
130 | 130 | return $this->instances[$config]; |
131 | 131 | } |
132 | 132 |
@@ -62,11 +62,13 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function setDefaults(string $section, array $data): void |
64 | 64 | { |
65 | - if (isset($this->defaults[$section])) { |
|
65 | + if (isset($this->defaults[$section])) |
|
66 | + { |
|
66 | 67 | throw new ConfiguratorException("Unable to set default config `{$section}` more than once."); |
67 | 68 | } |
68 | 69 | |
69 | - if (isset($this->data[$section])) { |
|
70 | + if (isset($this->data[$section])) |
|
71 | + { |
|
70 | 72 | throw new ConfigDeliveredException("Unable to set default config `{$section}`, config has been loaded."); |
71 | 73 | } |
72 | 74 | |
@@ -78,8 +80,10 @@ discard block |
||
78 | 80 | */ |
79 | 81 | public function modify(string $section, PatchInterface $patch): array |
80 | 82 | { |
81 | - if (isset($this->instances[$section])) { |
|
82 | - if ($this->strict) { |
|
83 | + if (isset($this->instances[$section])) |
|
84 | + { |
|
85 | + if ($this->strict) |
|
86 | + { |
|
83 | 87 | throw new ConfigDeliveredException( |
84 | 88 | "Unable to patch config `{$section}`, config object has already been delivered." |
85 | 89 | ); |
@@ -90,9 +94,12 @@ discard block |
||
90 | 94 | |
91 | 95 | $data = $this->getConfig($section); |
92 | 96 | |
93 | - try { |
|
97 | + try |
|
98 | + { |
|
94 | 99 | return $this->data[$section] = $patch->patch($data); |
95 | - } catch (PatchException $e) { |
|
100 | + } |
|
101 | + catch (PatchException $e) |
|
102 | + { |
|
96 | 103 | throw new PatchException("Unable to modify config `{$section}`.", $e->getCode(), $e); |
97 | 104 | } |
98 | 105 | } |
@@ -102,18 +109,23 @@ discard block |
||
102 | 109 | */ |
103 | 110 | public function getConfig(string $section = null): array |
104 | 111 | { |
105 | - if (isset($this->data[$section])) { |
|
112 | + if (isset($this->data[$section])) |
|
113 | + { |
|
106 | 114 | return $this->data[$section]; |
107 | 115 | } |
108 | 116 | |
109 | - if (isset($this->defaults[$section])) { |
|
117 | + if (isset($this->defaults[$section])) |
|
118 | + { |
|
110 | 119 | $data = []; |
111 | - if ($this->loader->has($section)) { |
|
120 | + if ($this->loader->has($section)) |
|
121 | + { |
|
112 | 122 | $data = $this->loader->load($section); |
113 | 123 | } |
114 | 124 | |
115 | 125 | $data = array_merge($this->defaults[$section], $data); |
116 | - } else { |
|
126 | + } |
|
127 | + else |
|
128 | + { |
|
117 | 129 | $data = $this->loader->load($section); |
118 | 130 | } |
119 | 131 | |
@@ -126,7 +138,8 @@ discard block |
||
126 | 138 | public function createInjection(ReflectionClass $class, string $context = null) |
127 | 139 | { |
128 | 140 | $config = $class->getConstant('CONFIG'); |
129 | - if (isset($this->instances[$config])) { |
|
141 | + if (isset($this->instances[$config])) |
|
142 | + { |
|
130 | 143 | return $this->instances[$config]; |
131 | 144 | } |
132 | 145 |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | TranslatorConfig $config, |
39 | 39 | CatalogueManagerInterface $catalogueManager, |
40 | 40 | IdentityTranslator $identityTranslator = null |
41 | - ) { |
|
41 | + ){ |
|
42 | 42 | $this->config = $config; |
43 | 43 | $this->identityTranslator = $identityTranslator ?? new IdentityTranslator(); |
44 | 44 | $this->catalogueManager = $catalogueManager; |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function setLocale(string $locale): void |
64 | 64 | { |
65 | - if (!$this->catalogueManager->has($locale)) { |
|
65 | + if (!$this->catalogueManager->has($locale)){ |
|
66 | 66 | throw new LocaleException($locale); |
67 | 67 | } |
68 | 68 | |
@@ -118,11 +118,11 @@ discard block |
||
118 | 118 | array $parameters = [], |
119 | 119 | $domain = null, |
120 | 120 | $locale = null |
121 | - ) { |
|
121 | + ){ |
|
122 | 122 | $domain ??= $this->config->getDefaultDomain(); |
123 | 123 | $locale ??= $this->locale; |
124 | 124 | |
125 | - try { |
|
125 | + try{ |
|
126 | 126 | $message = $this->get($locale, $domain, $id); |
127 | 127 | |
128 | 128 | $pluralized = $this->identityTranslator->trans( |
@@ -131,12 +131,12 @@ discard block |
||
131 | 131 | null, |
132 | 132 | $locale |
133 | 133 | ); |
134 | - } catch (InvalidArgumentException $e) { |
|
134 | + }catch (InvalidArgumentException $e){ |
|
135 | 135 | //Wrapping into more explanatory exception |
136 | 136 | throw new PluralizationException($e->getMessage(), $e->getCode(), $e); |
137 | 137 | } |
138 | 138 | |
139 | - if (empty($parameters['n']) && is_numeric($number)) { |
|
139 | + if (empty($parameters['n']) && is_numeric($number)){ |
|
140 | 140 | $parameters['n'] = $number; |
141 | 141 | } |
142 | 142 | |
@@ -161,18 +161,18 @@ discard block |
||
161 | 161 | string $postfix = '}' |
162 | 162 | ): string { |
163 | 163 | $replaces = []; |
164 | - foreach ($values as $key => $value) { |
|
164 | + foreach ($values as $key => $value){ |
|
165 | 165 | $value = (is_array($value) || $value instanceof Closure) ? '' : $value; |
166 | 166 | |
167 | - if (is_object($value)) { |
|
168 | - if (method_exists($value, '__toString')) { |
|
167 | + if (is_object($value)){ |
|
168 | + if (method_exists($value, '__toString')){ |
|
169 | 169 | $value = $value->__toString(); |
170 | - } else { |
|
170 | + }else{ |
|
171 | 171 | $value = ''; |
172 | 172 | } |
173 | 173 | } |
174 | 174 | |
175 | - $replaces[$prefix . $key . $postfix] = $value; |
|
175 | + $replaces[$prefix.$key.$postfix] = $value; |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | return strtr($string, $replaces); |
@@ -192,18 +192,18 @@ discard block |
||
192 | 192 | */ |
193 | 193 | protected function get(string &$locale, string $domain, string $string): string |
194 | 194 | { |
195 | - if ($this->catalogueManager->get($locale)->has($domain, $string)) { |
|
195 | + if ($this->catalogueManager->get($locale)->has($domain, $string)){ |
|
196 | 196 | return $this->catalogueManager->get($locale)->get($domain, $string); |
197 | 197 | } |
198 | 198 | |
199 | 199 | $locale = $this->config->getFallbackLocale(); |
200 | 200 | |
201 | - if ($this->catalogueManager->get($locale)->has($domain, $string)) { |
|
201 | + if ($this->catalogueManager->get($locale)->has($domain, $string)){ |
|
202 | 202 | return $this->catalogueManager->get($locale)->get($domain, $string); |
203 | 203 | } |
204 | 204 | |
205 | 205 | // we can automatically register message |
206 | - if ($this->config->isAutoRegisterMessages()) { |
|
206 | + if ($this->config->isAutoRegisterMessages()){ |
|
207 | 207 | $this->catalogueManager->get($locale)->set($domain, $string, $string); |
208 | 208 | $this->catalogueManager->save($locale); |
209 | 209 | } |
@@ -62,7 +62,8 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function setLocale(string $locale): void |
64 | 64 | { |
65 | - if (!$this->catalogueManager->has($locale)) { |
|
65 | + if (!$this->catalogueManager->has($locale)) |
|
66 | + { |
|
66 | 67 | throw new LocaleException($locale); |
67 | 68 | } |
68 | 69 | |
@@ -122,7 +123,8 @@ discard block |
||
122 | 123 | $domain ??= $this->config->getDefaultDomain(); |
123 | 124 | $locale ??= $this->locale; |
124 | 125 | |
125 | - try { |
|
126 | + try |
|
127 | + { |
|
126 | 128 | $message = $this->get($locale, $domain, $id); |
127 | 129 | |
128 | 130 | $pluralized = $this->identityTranslator->trans( |
@@ -131,12 +133,15 @@ discard block |
||
131 | 133 | null, |
132 | 134 | $locale |
133 | 135 | ); |
134 | - } catch (InvalidArgumentException $e) { |
|
136 | + } |
|
137 | + catch (InvalidArgumentException $e) |
|
138 | + { |
|
135 | 139 | //Wrapping into more explanatory exception |
136 | 140 | throw new PluralizationException($e->getMessage(), $e->getCode(), $e); |
137 | 141 | } |
138 | 142 | |
139 | - if (empty($parameters['n']) && is_numeric($number)) { |
|
143 | + if (empty($parameters['n']) && is_numeric($number)) |
|
144 | + { |
|
140 | 145 | $parameters['n'] = $number; |
141 | 146 | } |
142 | 147 | |
@@ -161,13 +166,18 @@ discard block |
||
161 | 166 | string $postfix = '}' |
162 | 167 | ): string { |
163 | 168 | $replaces = []; |
164 | - foreach ($values as $key => $value) { |
|
169 | + foreach ($values as $key => $value) |
|
170 | + { |
|
165 | 171 | $value = (is_array($value) || $value instanceof Closure) ? '' : $value; |
166 | 172 | |
167 | - if (is_object($value)) { |
|
168 | - if (method_exists($value, '__toString')) { |
|
173 | + if (is_object($value)) |
|
174 | + { |
|
175 | + if (method_exists($value, '__toString')) |
|
176 | + { |
|
169 | 177 | $value = $value->__toString(); |
170 | - } else { |
|
178 | + } |
|
179 | + else |
|
180 | + { |
|
171 | 181 | $value = ''; |
172 | 182 | } |
173 | 183 | } |
@@ -192,18 +202,21 @@ discard block |
||
192 | 202 | */ |
193 | 203 | protected function get(string &$locale, string $domain, string $string): string |
194 | 204 | { |
195 | - if ($this->catalogueManager->get($locale)->has($domain, $string)) { |
|
205 | + if ($this->catalogueManager->get($locale)->has($domain, $string)) |
|
206 | + { |
|
196 | 207 | return $this->catalogueManager->get($locale)->get($domain, $string); |
197 | 208 | } |
198 | 209 | |
199 | 210 | $locale = $this->config->getFallbackLocale(); |
200 | 211 | |
201 | - if ($this->catalogueManager->get($locale)->has($domain, $string)) { |
|
212 | + if ($this->catalogueManager->get($locale)->has($domain, $string)) |
|
213 | + { |
|
202 | 214 | return $this->catalogueManager->get($locale)->get($domain, $string); |
203 | 215 | } |
204 | 216 | |
205 | 217 | // we can automatically register message |
206 | - if ($this->config->isAutoRegisterMessages()) { |
|
218 | + if ($this->config->isAutoRegisterMessages()) |
|
219 | + { |
|
207 | 220 | $this->catalogueManager->get($locale)->set($domain, $string, $string); |
208 | 221 | $this->catalogueManager->save($locale); |
209 | 222 | } |
@@ -111,7 +111,7 @@ |
||
111 | 111 | */ |
112 | 112 | private function iterableToArray(iterable $meta): array |
113 | 113 | { |
114 | - if ($meta instanceof Traversable) { |
|
114 | + if ($meta instanceof Traversable){ |
|
115 | 115 | return \iterator_to_array($meta, false); |
116 | 116 | } |
117 | 117 |
@@ -111,7 +111,8 @@ |
||
111 | 111 | */ |
112 | 112 | private function iterableToArray(iterable $meta): array |
113 | 113 | { |
114 | - if ($meta instanceof Traversable) { |
|
114 | + if ($meta instanceof Traversable) |
|
115 | + { |
|
115 | 116 | return \iterator_to_array($meta, false); |
116 | 117 | } |
117 | 118 |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | use Attribute; |
15 | 15 | use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; |
16 | 16 | |
17 | - if (!\interface_exists(NamedArgumentConstructorAnnotation::class)) { |
|
17 | + if (!\interface_exists(NamedArgumentConstructorAnnotation::class)){ |
|
18 | 18 | /** |
19 | 19 | * Marker interface for PHP7/PHP8 compatible support for named |
20 | 20 | * arguments (and constructor property promotion). |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | |
33 | 33 | namespace Doctrine\Common\Annotations\Annotation { |
34 | 34 | |
35 | - if (!\class_exists(NamedArgumentConstructor::class, false)) { |
|
35 | + if (!\class_exists(NamedArgumentConstructor::class, false)){ |
|
36 | 36 | /** |
37 | 37 | * Annotation that indicates that the annotated class should be |
38 | 38 | * constructed with a named argument call. |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | |
53 | 53 | use JetBrains\PhpStorm\ExpectedValues; |
54 | 54 | |
55 | - if (!\class_exists(Attribute::class, false)) { |
|
55 | + if (!\class_exists(Attribute::class, false)){ |
|
56 | 56 | #[Attribute(Attribute::TARGET_CLASS)] |
57 | 57 | final class Attribute |
58 | 58 | { |
@@ -14,7 +14,8 @@ discard block |
||
14 | 14 | use Attribute; |
15 | 15 | use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; |
16 | 16 | |
17 | - if (!\interface_exists(NamedArgumentConstructorAnnotation::class)) { |
|
17 | + if (!\interface_exists(NamedArgumentConstructorAnnotation::class)) |
|
18 | + { |
|
18 | 19 | /** |
19 | 20 | * Marker interface for PHP7/PHP8 compatible support for named |
20 | 21 | * arguments (and constructor property promotion). |
@@ -32,7 +33,8 @@ discard block |
||
32 | 33 | |
33 | 34 | namespace Doctrine\Common\Annotations\Annotation { |
34 | 35 | |
35 | - if (!\class_exists(NamedArgumentConstructor::class, false)) { |
|
36 | + if (!\class_exists(NamedArgumentConstructor::class, false)) |
|
37 | + { |
|
36 | 38 | /** |
37 | 39 | * Annotation that indicates that the annotated class should be |
38 | 40 | * constructed with a named argument call. |
@@ -52,7 +54,8 @@ discard block |
||
52 | 54 | |
53 | 55 | use JetBrains\PhpStorm\ExpectedValues; |
54 | 56 | |
55 | - if (!\class_exists(Attribute::class, false)) { |
|
57 | + if (!\class_exists(Attribute::class, false)) |
|
58 | + { |
|
56 | 59 | #[Attribute(Attribute::TARGET_CLASS)] |
57 | 60 | final class Attribute |
58 | 61 | { |