@@ -90,7 +90,8 @@ discard block |
||
90 | 90 | |
91 | 91 | $this->configureIO($input, $output); |
92 | 92 | |
93 | - if ($command !== null) { |
|
93 | + if ($command !== null) |
|
94 | + { |
|
94 | 95 | $input = new InputProxy($input, ['firstArgument' => $command]); |
95 | 96 | } |
96 | 97 | |
@@ -107,7 +108,8 @@ discard block |
||
107 | 108 | */ |
108 | 109 | public function getApplication(): Application |
109 | 110 | { |
110 | - if ($this->application !== null) { |
|
111 | + if ($this->application !== null) |
|
112 | + { |
|
111 | 113 | return $this->application; |
112 | 114 | } |
113 | 115 | |
@@ -115,7 +117,8 @@ discard block |
||
115 | 117 | $this->application->setCatchExceptions(false); |
116 | 118 | $this->application->setAutoExit(false); |
117 | 119 | |
118 | - if ($this->locator !== null) { |
|
120 | + if ($this->locator !== null) |
|
121 | + { |
|
119 | 122 | $this->addCommands($this->locator->locateCommands()); |
120 | 123 | } |
121 | 124 | |
@@ -128,8 +131,10 @@ discard block |
||
128 | 131 | |
129 | 132 | private function addCommands(iterable $commands): void |
130 | 133 | { |
131 | - foreach ($commands as $command) { |
|
132 | - if ($command instanceof Command) { |
|
134 | + foreach ($commands as $command) |
|
135 | + { |
|
136 | + if ($command instanceof Command) |
|
137 | + { |
|
133 | 138 | $command->setContainer($this->container); |
134 | 139 | } |
135 | 140 | |
@@ -144,27 +149,36 @@ discard block |
||
144 | 149 | */ |
145 | 150 | private function configureIO(InputInterface $input, OutputInterface $output): void |
146 | 151 | { |
147 | - if (true === $input->hasParameterOption(['--ansi'], true)) { |
|
152 | + if (true === $input->hasParameterOption(['--ansi'], true)) |
|
153 | + { |
|
148 | 154 | $output->setDecorated(true); |
149 | - } elseif (true === $input->hasParameterOption(['--no-ansi'], true)) { |
|
155 | + } |
|
156 | + elseif (true === $input->hasParameterOption(['--no-ansi'], true)) |
|
157 | + { |
|
150 | 158 | $output->setDecorated(false); |
151 | 159 | } |
152 | 160 | |
153 | - if (true === $input->hasParameterOption(['--no-interaction', '-n'], true)) { |
|
161 | + if (true === $input->hasParameterOption(['--no-interaction', '-n'], true)) |
|
162 | + { |
|
154 | 163 | $input->setInteractive(false); |
155 | - } elseif (\function_exists('posix_isatty')) { |
|
164 | + } |
|
165 | + elseif (\function_exists('posix_isatty')) |
|
166 | + { |
|
156 | 167 | $inputStream = null; |
157 | 168 | |
158 | - if ($input instanceof StreamableInputInterface) { |
|
169 | + if ($input instanceof StreamableInputInterface) |
|
170 | + { |
|
159 | 171 | $inputStream = $input->getStream(); |
160 | 172 | } |
161 | 173 | |
162 | - if (!@posix_isatty($inputStream) && false === getenv('SHELL_INTERACTIVE')) { |
|
174 | + if (!@posix_isatty($inputStream) && false === getenv('SHELL_INTERACTIVE')) |
|
175 | + { |
|
163 | 176 | $input->setInteractive(false); |
164 | 177 | } |
165 | 178 | } |
166 | 179 | |
167 | - switch ($shellVerbosity = (int)getenv('SHELL_VERBOSITY')) { |
|
180 | + switch ($shellVerbosity = (int)getenv('SHELL_VERBOSITY')) |
|
181 | + { |
|
168 | 182 | case -1: |
169 | 183 | $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); |
170 | 184 | break; |
@@ -187,7 +201,9 @@ discard block |
||
187 | 201 | ) { |
188 | 202 | $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); |
189 | 203 | $shellVerbosity = -1; |
190 | - } else { |
|
204 | + } |
|
205 | + else |
|
206 | + { |
|
191 | 207 | if ( |
192 | 208 | $input->hasParameterOption('-vvv', true) |
193 | 209 | || $input->hasParameterOption('--verbose=3', true) |
@@ -195,14 +211,16 @@ discard block |
||
195 | 211 | ) { |
196 | 212 | $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG); |
197 | 213 | $shellVerbosity = 3; |
198 | - } elseif ( |
|
214 | + } |
|
215 | + elseif ( |
|
199 | 216 | $input->hasParameterOption('-vv', true) |
200 | 217 | || $input->hasParameterOption('--verbose=2', true) |
201 | 218 | || 2 === $input->getParameterOption('--verbose', false, true) |
202 | 219 | ) { |
203 | 220 | $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); |
204 | 221 | $shellVerbosity = 2; |
205 | - } elseif ( |
|
222 | + } |
|
223 | + elseif ( |
|
206 | 224 | $input->hasParameterOption('-v', true) |
207 | 225 | || $input->hasParameterOption('--verbose=1', true) |
208 | 226 | || $input->hasParameterOption('--verbose', true) |
@@ -213,7 +231,8 @@ discard block |
||
213 | 231 | } |
214 | 232 | } |
215 | 233 | |
216 | - if (-1 === $shellVerbosity) { |
|
234 | + if (-1 === $shellVerbosity) |
|
235 | + { |
|
217 | 236 | $input->setInteractive(false); |
218 | 237 | } |
219 | 238 |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function getCommands(): array |
50 | 50 | { |
51 | - if (!array_key_exists('commands', $this->config)) { |
|
51 | + if (!array_key_exists('commands', $this->config)){ |
|
52 | 52 | //Legacy config support |
53 | 53 | return []; |
54 | 54 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | public function configureSequence(): Generator |
67 | 67 | { |
68 | 68 | $sequence = $this->config['configure'] ?? $this->config['configureSequence'] ?? []; |
69 | - foreach ($sequence as $item) { |
|
69 | + foreach ($sequence as $item){ |
|
70 | 70 | yield $this->parseSequence($item); |
71 | 71 | } |
72 | 72 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | public function updateSequence(): Generator |
82 | 82 | { |
83 | 83 | $sequence = $this->config['update'] ?? $this->config['updateSequence'] ?? []; |
84 | - foreach ($sequence as $item) { |
|
84 | + foreach ($sequence as $item){ |
|
85 | 85 | yield $this->parseSequence($item); |
86 | 86 | } |
87 | 87 | } |
@@ -93,15 +93,15 @@ discard block |
||
93 | 93 | */ |
94 | 94 | protected function parseSequence($item): SequenceInterface |
95 | 95 | { |
96 | - if ($item instanceof SequenceInterface) { |
|
96 | + if ($item instanceof SequenceInterface){ |
|
97 | 97 | return $item; |
98 | 98 | } |
99 | 99 | |
100 | - if (is_string($item)) { |
|
100 | + if (is_string($item)){ |
|
101 | 101 | return new CallableSequence($item); |
102 | 102 | } |
103 | 103 | |
104 | - if (is_array($item) && isset($item['command'])) { |
|
104 | + if (is_array($item) && isset($item['command'])){ |
|
105 | 105 | return new CommandSequence( |
106 | 106 | $item['command'], |
107 | 107 | $item['options'] ?? [], |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | ); |
111 | 111 | } |
112 | 112 | |
113 | - if (is_array($item) && isset($item['invoke'])) { |
|
113 | + if (is_array($item) && isset($item['invoke'])){ |
|
114 | 114 | return new CallableSequence( |
115 | 115 | $item['invoke'], |
116 | 116 | $item['parameters'] ?? [], |
@@ -48,7 +48,8 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function getCommands(): array |
50 | 50 | { |
51 | - if (!array_key_exists('commands', $this->config)) { |
|
51 | + if (!array_key_exists('commands', $this->config)) |
|
52 | + { |
|
52 | 53 | //Legacy config support |
53 | 54 | return []; |
54 | 55 | } |
@@ -66,7 +67,8 @@ discard block |
||
66 | 67 | public function configureSequence(): Generator |
67 | 68 | { |
68 | 69 | $sequence = $this->config['configure'] ?? $this->config['configureSequence'] ?? []; |
69 | - foreach ($sequence as $item) { |
|
70 | + foreach ($sequence as $item) |
|
71 | + { |
|
70 | 72 | yield $this->parseSequence($item); |
71 | 73 | } |
72 | 74 | } |
@@ -81,7 +83,8 @@ discard block |
||
81 | 83 | public function updateSequence(): Generator |
82 | 84 | { |
83 | 85 | $sequence = $this->config['update'] ?? $this->config['updateSequence'] ?? []; |
84 | - foreach ($sequence as $item) { |
|
86 | + foreach ($sequence as $item) |
|
87 | + { |
|
85 | 88 | yield $this->parseSequence($item); |
86 | 89 | } |
87 | 90 | } |
@@ -93,15 +96,18 @@ discard block |
||
93 | 96 | */ |
94 | 97 | protected function parseSequence($item): SequenceInterface |
95 | 98 | { |
96 | - if ($item instanceof SequenceInterface) { |
|
99 | + if ($item instanceof SequenceInterface) |
|
100 | + { |
|
97 | 101 | return $item; |
98 | 102 | } |
99 | 103 | |
100 | - if (is_string($item)) { |
|
104 | + if (is_string($item)) |
|
105 | + { |
|
101 | 106 | return new CallableSequence($item); |
102 | 107 | } |
103 | 108 | |
104 | - if (is_array($item) && isset($item['command'])) { |
|
109 | + if (is_array($item) && isset($item['command'])) |
|
110 | + { |
|
105 | 111 | return new CommandSequence( |
106 | 112 | $item['command'], |
107 | 113 | $item['options'] ?? [], |
@@ -110,7 +116,8 @@ discard block |
||
110 | 116 | ); |
111 | 117 | } |
112 | 118 | |
113 | - if (is_array($item) && isset($item['invoke'])) { |
|
119 | + if (is_array($item) && isset($item['invoke'])) |
|
120 | + { |
|
114 | 121 | return new CallableSequence( |
115 | 122 | $item['invoke'], |
116 | 123 | $item['parameters'] ?? [], |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | array $parameters = [], |
36 | 36 | string $header = '', |
37 | 37 | string $footer = '' |
38 | - ) { |
|
38 | + ){ |
|
39 | 39 | $this->function = $function; |
40 | 40 | |
41 | 41 | parent::__construct($header, $footer); |
@@ -47,18 +47,18 @@ discard block |
||
47 | 47 | public function execute(ContainerInterface $container, OutputInterface $output): void |
48 | 48 | { |
49 | 49 | $function = $this->function; |
50 | - if (is_string($function) && strpos($function, ':') !== false) { |
|
50 | + if (is_string($function) && strpos($function, ':') !== false){ |
|
51 | 51 | $function = explode(':', str_replace('::', ':', $function)); |
52 | 52 | } |
53 | 53 | |
54 | - if (is_array($function) && isset($function[0]) && !is_object($function[0])) { |
|
54 | + if (is_array($function) && isset($function[0]) && !is_object($function[0])){ |
|
55 | 55 | $function[0] = $container->get($function[0]); |
56 | 56 | } |
57 | 57 | |
58 | 58 | /** @var ResolverInterface $resolver */ |
59 | 59 | $resolver = $container->get(ResolverInterface::class); |
60 | 60 | |
61 | - if (is_array($function)) { |
|
61 | + if (is_array($function)){ |
|
62 | 62 | $reflection = new ReflectionMethod($function[0], $function[1]); |
63 | 63 | $reflection->invokeArgs($function[0], $resolver->resolveArguments($reflection, [ |
64 | 64 | 'output' => $output, |
@@ -47,18 +47,21 @@ |
||
47 | 47 | public function execute(ContainerInterface $container, OutputInterface $output): void |
48 | 48 | { |
49 | 49 | $function = $this->function; |
50 | - if (is_string($function) && strpos($function, ':') !== false) { |
|
50 | + if (is_string($function) && strpos($function, ':') !== false) |
|
51 | + { |
|
51 | 52 | $function = explode(':', str_replace('::', ':', $function)); |
52 | 53 | } |
53 | 54 | |
54 | - if (is_array($function) && isset($function[0]) && !is_object($function[0])) { |
|
55 | + if (is_array($function) && isset($function[0]) && !is_object($function[0])) |
|
56 | + { |
|
55 | 57 | $function[0] = $container->get($function[0]); |
56 | 58 | } |
57 | 59 | |
58 | 60 | /** @var ResolverInterface $resolver */ |
59 | 61 | $resolver = $container->get(ResolverInterface::class); |
60 | 62 | |
61 | - if (is_array($function)) { |
|
63 | + if (is_array($function)) |
|
64 | + { |
|
62 | 65 | $reflection = new ReflectionMethod($function[0], $function[1]); |
63 | 66 | $reflection->invokeArgs($function[0], $resolver->resolveArguments($reflection, [ |
64 | 67 | 'output' => $output, |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function __destruct() |
50 | 50 | { |
51 | - foreach ($this->destructFiles as $filename) { |
|
51 | + foreach ($this->destructFiles as $filename){ |
|
52 | 52 | $this->delete($filename); |
53 | 53 | } |
54 | 54 | } |
@@ -63,30 +63,30 @@ discard block |
||
63 | 63 | int $mode = null, |
64 | 64 | bool $recursivePermissions = true |
65 | 65 | ): bool { |
66 | - if (empty($mode)) { |
|
66 | + if (empty($mode)){ |
|
67 | 67 | $mode = self::DEFAULT_FILE_MODE; |
68 | 68 | } |
69 | 69 | |
70 | 70 | //Directories always executable |
71 | 71 | $mode = $mode | 0111; |
72 | - if (is_dir($directory)) { |
|
72 | + if (is_dir($directory)){ |
|
73 | 73 | //Exists :( |
74 | 74 | return $this->setPermissions($directory, $mode); |
75 | 75 | } |
76 | 76 | |
77 | - if (!$recursivePermissions) { |
|
77 | + if (!$recursivePermissions){ |
|
78 | 78 | return mkdir($directory, $mode, true); |
79 | 79 | } |
80 | 80 | |
81 | 81 | $directoryChain = [basename($directory)]; |
82 | 82 | |
83 | 83 | $baseDirectory = $directory; |
84 | - while (!is_dir($baseDirectory = dirname($baseDirectory))) { |
|
84 | + while (!is_dir($baseDirectory = dirname($baseDirectory))){ |
|
85 | 85 | $directoryChain[] = basename($baseDirectory); |
86 | 86 | } |
87 | 87 | |
88 | - foreach (array_reverse($directoryChain) as $directory) { |
|
89 | - if (!mkdir($baseDirectory = "{$baseDirectory}/{$directory}")) { |
|
88 | + foreach (array_reverse($directoryChain) as $directory){ |
|
89 | + if (!mkdir($baseDirectory = "{$baseDirectory}/{$directory}")){ |
|
90 | 90 | return false; |
91 | 91 | } |
92 | 92 | |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function read(string $filename): string |
103 | 103 | { |
104 | - if (!$this->exists($filename)) { |
|
104 | + if (!$this->exists($filename)){ |
|
105 | 105 | throw new FileNotFoundException($filename); |
106 | 106 | } |
107 | 107 | |
@@ -122,12 +122,12 @@ discard block |
||
122 | 122 | ): bool { |
123 | 123 | $mode ??= self::DEFAULT_FILE_MODE; |
124 | 124 | |
125 | - try { |
|
126 | - if ($ensureDirectory) { |
|
125 | + try{ |
|
126 | + if ($ensureDirectory){ |
|
127 | 127 | $this->ensureDirectory(dirname($filename), $mode); |
128 | 128 | } |
129 | 129 | |
130 | - if ($this->exists($filename)) { |
|
130 | + if ($this->exists($filename)){ |
|
131 | 131 | //Forcing mode for existed file |
132 | 132 | $this->setPermissions($filename, $mode); |
133 | 133 | } |
@@ -138,11 +138,11 @@ discard block |
||
138 | 138 | $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
139 | 139 | ); |
140 | 140 | |
141 | - if ($result !== false) { |
|
141 | + if ($result !== false){ |
|
142 | 142 | //Forcing mode after file creation |
143 | 143 | $this->setPermissions($filename, $mode); |
144 | 144 | } |
145 | - } catch (Exception $e) { |
|
145 | + }catch (Exception $e){ |
|
146 | 146 | throw new WriteErrorException($e->getMessage(), $e->getCode(), $e); |
147 | 147 | } |
148 | 148 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function delete(string $filename) |
168 | 168 | { |
169 | - if ($this->exists($filename)) { |
|
169 | + if ($this->exists($filename)){ |
|
170 | 170 | $result = unlink($filename); |
171 | 171 | |
172 | 172 | //Wiping out changes in local file cache |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | */ |
189 | 189 | public function deleteDirectory(string $directory, bool $contentOnly = false): void |
190 | 190 | { |
191 | - if (!$this->isDirectory($directory)) { |
|
191 | + if (!$this->isDirectory($directory)){ |
|
192 | 192 | throw new FilesException("Undefined or invalid directory {$directory}"); |
193 | 193 | } |
194 | 194 | |
@@ -197,15 +197,15 @@ discard block |
||
197 | 197 | RecursiveIteratorIterator::CHILD_FIRST |
198 | 198 | ); |
199 | 199 | |
200 | - foreach ($files as $file) { |
|
201 | - if ($file->isDir()) { |
|
200 | + foreach ($files as $file){ |
|
201 | + if ($file->isDir()){ |
|
202 | 202 | rmdir($file->getRealPath()); |
203 | - } else { |
|
203 | + }else{ |
|
204 | 204 | $this->delete($file->getRealPath()); |
205 | 205 | } |
206 | 206 | } |
207 | 207 | |
208 | - if (!$contentOnly) { |
|
208 | + if (!$contentOnly){ |
|
209 | 209 | rmdir($directory); |
210 | 210 | } |
211 | 211 | } |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | */ |
216 | 216 | public function move(string $filename, string $destination): bool |
217 | 217 | { |
218 | - if (!$this->exists($filename)) { |
|
218 | + if (!$this->exists($filename)){ |
|
219 | 219 | throw new FileNotFoundException($filename); |
220 | 220 | } |
221 | 221 | |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | */ |
228 | 228 | public function copy(string $filename, string $destination): bool |
229 | 229 | { |
230 | - if (!$this->exists($filename)) { |
|
230 | + if (!$this->exists($filename)){ |
|
231 | 231 | throw new FileNotFoundException($filename); |
232 | 232 | } |
233 | 233 | |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | */ |
240 | 240 | public function touch(string $filename, int $mode = null): bool |
241 | 241 | { |
242 | - if (!touch($filename)) { |
|
242 | + if (!touch($filename)){ |
|
243 | 243 | return false; |
244 | 244 | } |
245 | 245 | |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | */ |
260 | 260 | public function size(string $filename): int |
261 | 261 | { |
262 | - if (!$this->exists($filename)) { |
|
262 | + if (!$this->exists($filename)){ |
|
263 | 263 | throw new FileNotFoundException($filename); |
264 | 264 | } |
265 | 265 | |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | */ |
280 | 280 | public function md5(string $filename): string |
281 | 281 | { |
282 | - if (!$this->exists($filename)) { |
|
282 | + if (!$this->exists($filename)){ |
|
283 | 283 | throw new FileNotFoundException($filename); |
284 | 284 | } |
285 | 285 | |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | */ |
292 | 292 | public function time(string $filename): int |
293 | 293 | { |
294 | - if (!$this->exists($filename)) { |
|
294 | + if (!$this->exists($filename)){ |
|
295 | 295 | throw new FileNotFoundException($filename); |
296 | 296 | } |
297 | 297 | |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | */ |
320 | 320 | public function getPermissions(string $filename): int |
321 | 321 | { |
322 | - if (!$this->exists($filename)) { |
|
322 | + if (!$this->exists($filename)){ |
|
323 | 323 | throw new FileNotFoundException($filename); |
324 | 324 | } |
325 | 325 | |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | */ |
332 | 332 | public function setPermissions(string $filename, int $mode) |
333 | 333 | { |
334 | - if (is_dir($filename)) { |
|
334 | + if (is_dir($filename)){ |
|
335 | 335 | //Directories must always be executable (i.e. 664 for dir => 775) |
336 | 336 | $mode |= 0111; |
337 | 337 | } |
@@ -345,9 +345,9 @@ discard block |
||
345 | 345 | public function getFiles(string $location, string $pattern = null): array |
346 | 346 | { |
347 | 347 | $result = []; |
348 | - foreach ($this->filesIterator($location, $pattern) as $filename) { |
|
349 | - if ($this->isDirectory($filename->getPathname())) { |
|
350 | - $result = array_merge($result, $this->getFiles($filename . DIRECTORY_SEPARATOR)); |
|
348 | + foreach ($this->filesIterator($location, $pattern) as $filename){ |
|
349 | + if ($this->isDirectory($filename->getPathname())){ |
|
350 | + $result = array_merge($result, $this->getFiles($filename.DIRECTORY_SEPARATOR)); |
|
351 | 351 | |
352 | 352 | continue; |
353 | 353 | } |
@@ -363,13 +363,13 @@ discard block |
||
363 | 363 | */ |
364 | 364 | public function tempFilename(string $extension = '', string $location = null): string |
365 | 365 | { |
366 | - if (empty($location)) { |
|
366 | + if (empty($location)){ |
|
367 | 367 | $location = sys_get_temp_dir(); |
368 | 368 | } |
369 | 369 | |
370 | 370 | $filename = tempnam($location, 'spiral'); |
371 | 371 | |
372 | - if (!empty($extension)) { |
|
372 | + if (!empty($extension)){ |
|
373 | 373 | [$old, $filename] = [$filename, "{$filename}.{$extension}"]; |
374 | 374 | rename($old, $filename); |
375 | 375 | $this->destructFiles[] = $filename; |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | $path = str_replace(['//', '\\'], '/', $path); |
387 | 387 | |
388 | 388 | //Potentially open links and ../ type directories? |
389 | - return rtrim($path, '/') . ($asDirectory ? '/' : ''); |
|
389 | + return rtrim($path, '/').($asDirectory ? '/' : ''); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | /** |
@@ -403,21 +403,21 @@ discard block |
||
403 | 403 | $path = explode('/', $path); |
404 | 404 | $relative = $path; |
405 | 405 | |
406 | - foreach ($from as $depth => $dir) { |
|
406 | + foreach ($from as $depth => $dir){ |
|
407 | 407 | //Find first non-matching dir |
408 | - if ($dir === $path[$depth]) { |
|
408 | + if ($dir === $path[$depth]){ |
|
409 | 409 | //Ignore this directory |
410 | 410 | array_shift($relative); |
411 | - } else { |
|
411 | + }else{ |
|
412 | 412 | //Get number of remaining dirs to $from |
413 | 413 | $remaining = count($from) - $depth; |
414 | - if ($remaining > 1) { |
|
414 | + if ($remaining > 1){ |
|
415 | 415 | //Add traversals up to first matching directory |
416 | 416 | $padLength = (count($relative) + $remaining - 1) * -1; |
417 | 417 | $relative = array_pad($relative, $padLength, '..'); |
418 | 418 | break; |
419 | 419 | } |
420 | - $relative[0] = './' . $relative[0]; |
|
420 | + $relative[0] = './'.$relative[0]; |
|
421 | 421 | } |
422 | 422 | } |
423 | 423 | |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | private function filesIterator(string $location, string $pattern = null): GlobIterator |
432 | 432 | { |
433 | 433 | $pattern ??= '*'; |
434 | - $regexp = rtrim($location, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($pattern, DIRECTORY_SEPARATOR); |
|
434 | + $regexp = rtrim($location, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.ltrim($pattern, DIRECTORY_SEPARATOR); |
|
435 | 435 | |
436 | 436 | return new GlobIterator($regexp); |
437 | 437 | } |
@@ -48,7 +48,8 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function __destruct() |
50 | 50 | { |
51 | - foreach ($this->destructFiles as $filename) { |
|
51 | + foreach ($this->destructFiles as $filename) |
|
52 | + { |
|
52 | 53 | $this->delete($filename); |
53 | 54 | } |
54 | 55 | } |
@@ -63,30 +64,36 @@ discard block |
||
63 | 64 | int $mode = null, |
64 | 65 | bool $recursivePermissions = true |
65 | 66 | ): bool { |
66 | - if (empty($mode)) { |
|
67 | + if (empty($mode)) |
|
68 | + { |
|
67 | 69 | $mode = self::DEFAULT_FILE_MODE; |
68 | 70 | } |
69 | 71 | |
70 | 72 | //Directories always executable |
71 | 73 | $mode = $mode | 0111; |
72 | - if (is_dir($directory)) { |
|
74 | + if (is_dir($directory)) |
|
75 | + { |
|
73 | 76 | //Exists :( |
74 | 77 | return $this->setPermissions($directory, $mode); |
75 | 78 | } |
76 | 79 | |
77 | - if (!$recursivePermissions) { |
|
80 | + if (!$recursivePermissions) |
|
81 | + { |
|
78 | 82 | return mkdir($directory, $mode, true); |
79 | 83 | } |
80 | 84 | |
81 | 85 | $directoryChain = [basename($directory)]; |
82 | 86 | |
83 | 87 | $baseDirectory = $directory; |
84 | - while (!is_dir($baseDirectory = dirname($baseDirectory))) { |
|
88 | + while (!is_dir($baseDirectory = dirname($baseDirectory))) |
|
89 | + { |
|
85 | 90 | $directoryChain[] = basename($baseDirectory); |
86 | 91 | } |
87 | 92 | |
88 | - foreach (array_reverse($directoryChain) as $directory) { |
|
89 | - if (!mkdir($baseDirectory = "{$baseDirectory}/{$directory}")) { |
|
93 | + foreach (array_reverse($directoryChain) as $directory) |
|
94 | + { |
|
95 | + if (!mkdir($baseDirectory = "{$baseDirectory}/{$directory}")) |
|
96 | + { |
|
90 | 97 | return false; |
91 | 98 | } |
92 | 99 | |
@@ -101,7 +108,8 @@ discard block |
||
101 | 108 | */ |
102 | 109 | public function read(string $filename): string |
103 | 110 | { |
104 | - if (!$this->exists($filename)) { |
|
111 | + if (!$this->exists($filename)) |
|
112 | + { |
|
105 | 113 | throw new FileNotFoundException($filename); |
106 | 114 | } |
107 | 115 | |
@@ -122,12 +130,15 @@ discard block |
||
122 | 130 | ): bool { |
123 | 131 | $mode ??= self::DEFAULT_FILE_MODE; |
124 | 132 | |
125 | - try { |
|
126 | - if ($ensureDirectory) { |
|
133 | + try |
|
134 | + { |
|
135 | + if ($ensureDirectory) |
|
136 | + { |
|
127 | 137 | $this->ensureDirectory(dirname($filename), $mode); |
128 | 138 | } |
129 | 139 | |
130 | - if ($this->exists($filename)) { |
|
140 | + if ($this->exists($filename)) |
|
141 | + { |
|
131 | 142 | //Forcing mode for existed file |
132 | 143 | $this->setPermissions($filename, $mode); |
133 | 144 | } |
@@ -138,11 +149,14 @@ discard block |
||
138 | 149 | $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
139 | 150 | ); |
140 | 151 | |
141 | - if ($result !== false) { |
|
152 | + if ($result !== false) |
|
153 | + { |
|
142 | 154 | //Forcing mode after file creation |
143 | 155 | $this->setPermissions($filename, $mode); |
144 | 156 | } |
145 | - } catch (Exception $e) { |
|
157 | + } |
|
158 | + catch (Exception $e) |
|
159 | + { |
|
146 | 160 | throw new WriteErrorException($e->getMessage(), $e->getCode(), $e); |
147 | 161 | } |
148 | 162 | |
@@ -166,7 +180,8 @@ discard block |
||
166 | 180 | */ |
167 | 181 | public function delete(string $filename) |
168 | 182 | { |
169 | - if ($this->exists($filename)) { |
|
183 | + if ($this->exists($filename)) |
|
184 | + { |
|
170 | 185 | $result = unlink($filename); |
171 | 186 | |
172 | 187 | //Wiping out changes in local file cache |
@@ -188,7 +203,8 @@ discard block |
||
188 | 203 | */ |
189 | 204 | public function deleteDirectory(string $directory, bool $contentOnly = false): void |
190 | 205 | { |
191 | - if (!$this->isDirectory($directory)) { |
|
206 | + if (!$this->isDirectory($directory)) |
|
207 | + { |
|
192 | 208 | throw new FilesException("Undefined or invalid directory {$directory}"); |
193 | 209 | } |
194 | 210 | |
@@ -197,15 +213,20 @@ discard block |
||
197 | 213 | RecursiveIteratorIterator::CHILD_FIRST |
198 | 214 | ); |
199 | 215 | |
200 | - foreach ($files as $file) { |
|
201 | - if ($file->isDir()) { |
|
216 | + foreach ($files as $file) |
|
217 | + { |
|
218 | + if ($file->isDir()) |
|
219 | + { |
|
202 | 220 | rmdir($file->getRealPath()); |
203 | - } else { |
|
221 | + } |
|
222 | + else |
|
223 | + { |
|
204 | 224 | $this->delete($file->getRealPath()); |
205 | 225 | } |
206 | 226 | } |
207 | 227 | |
208 | - if (!$contentOnly) { |
|
228 | + if (!$contentOnly) |
|
229 | + { |
|
209 | 230 | rmdir($directory); |
210 | 231 | } |
211 | 232 | } |
@@ -215,7 +236,8 @@ discard block |
||
215 | 236 | */ |
216 | 237 | public function move(string $filename, string $destination): bool |
217 | 238 | { |
218 | - if (!$this->exists($filename)) { |
|
239 | + if (!$this->exists($filename)) |
|
240 | + { |
|
219 | 241 | throw new FileNotFoundException($filename); |
220 | 242 | } |
221 | 243 | |
@@ -227,7 +249,8 @@ discard block |
||
227 | 249 | */ |
228 | 250 | public function copy(string $filename, string $destination): bool |
229 | 251 | { |
230 | - if (!$this->exists($filename)) { |
|
252 | + if (!$this->exists($filename)) |
|
253 | + { |
|
231 | 254 | throw new FileNotFoundException($filename); |
232 | 255 | } |
233 | 256 | |
@@ -239,7 +262,8 @@ discard block |
||
239 | 262 | */ |
240 | 263 | public function touch(string $filename, int $mode = null): bool |
241 | 264 | { |
242 | - if (!touch($filename)) { |
|
265 | + if (!touch($filename)) |
|
266 | + { |
|
243 | 267 | return false; |
244 | 268 | } |
245 | 269 | |
@@ -259,7 +283,8 @@ discard block |
||
259 | 283 | */ |
260 | 284 | public function size(string $filename): int |
261 | 285 | { |
262 | - if (!$this->exists($filename)) { |
|
286 | + if (!$this->exists($filename)) |
|
287 | + { |
|
263 | 288 | throw new FileNotFoundException($filename); |
264 | 289 | } |
265 | 290 | |
@@ -279,7 +304,8 @@ discard block |
||
279 | 304 | */ |
280 | 305 | public function md5(string $filename): string |
281 | 306 | { |
282 | - if (!$this->exists($filename)) { |
|
307 | + if (!$this->exists($filename)) |
|
308 | + { |
|
283 | 309 | throw new FileNotFoundException($filename); |
284 | 310 | } |
285 | 311 | |
@@ -291,7 +317,8 @@ discard block |
||
291 | 317 | */ |
292 | 318 | public function time(string $filename): int |
293 | 319 | { |
294 | - if (!$this->exists($filename)) { |
|
320 | + if (!$this->exists($filename)) |
|
321 | + { |
|
295 | 322 | throw new FileNotFoundException($filename); |
296 | 323 | } |
297 | 324 | |
@@ -319,7 +346,8 @@ discard block |
||
319 | 346 | */ |
320 | 347 | public function getPermissions(string $filename): int |
321 | 348 | { |
322 | - if (!$this->exists($filename)) { |
|
349 | + if (!$this->exists($filename)) |
|
350 | + { |
|
323 | 351 | throw new FileNotFoundException($filename); |
324 | 352 | } |
325 | 353 | |
@@ -331,7 +359,8 @@ discard block |
||
331 | 359 | */ |
332 | 360 | public function setPermissions(string $filename, int $mode) |
333 | 361 | { |
334 | - if (is_dir($filename)) { |
|
362 | + if (is_dir($filename)) |
|
363 | + { |
|
335 | 364 | //Directories must always be executable (i.e. 664 for dir => 775) |
336 | 365 | $mode |= 0111; |
337 | 366 | } |
@@ -345,8 +374,10 @@ discard block |
||
345 | 374 | public function getFiles(string $location, string $pattern = null): array |
346 | 375 | { |
347 | 376 | $result = []; |
348 | - foreach ($this->filesIterator($location, $pattern) as $filename) { |
|
349 | - if ($this->isDirectory($filename->getPathname())) { |
|
377 | + foreach ($this->filesIterator($location, $pattern) as $filename) |
|
378 | + { |
|
379 | + if ($this->isDirectory($filename->getPathname())) |
|
380 | + { |
|
350 | 381 | $result = array_merge($result, $this->getFiles($filename . DIRECTORY_SEPARATOR)); |
351 | 382 | |
352 | 383 | continue; |
@@ -363,13 +394,15 @@ discard block |
||
363 | 394 | */ |
364 | 395 | public function tempFilename(string $extension = '', string $location = null): string |
365 | 396 | { |
366 | - if (empty($location)) { |
|
397 | + if (empty($location)) |
|
398 | + { |
|
367 | 399 | $location = sys_get_temp_dir(); |
368 | 400 | } |
369 | 401 | |
370 | 402 | $filename = tempnam($location, 'spiral'); |
371 | 403 | |
372 | - if (!empty($extension)) { |
|
404 | + if (!empty($extension)) |
|
405 | + { |
|
373 | 406 | [$old, $filename] = [$filename, "{$filename}.{$extension}"]; |
374 | 407 | rename($old, $filename); |
375 | 408 | $this->destructFiles[] = $filename; |
@@ -403,15 +436,20 @@ discard block |
||
403 | 436 | $path = explode('/', $path); |
404 | 437 | $relative = $path; |
405 | 438 | |
406 | - foreach ($from as $depth => $dir) { |
|
439 | + foreach ($from as $depth => $dir) |
|
440 | + { |
|
407 | 441 | //Find first non-matching dir |
408 | - if ($dir === $path[$depth]) { |
|
442 | + if ($dir === $path[$depth]) |
|
443 | + { |
|
409 | 444 | //Ignore this directory |
410 | 445 | array_shift($relative); |
411 | - } else { |
|
446 | + } |
|
447 | + else |
|
448 | + { |
|
412 | 449 | //Get number of remaining dirs to $from |
413 | 450 | $remaining = count($from) - $depth; |
414 | - if ($remaining > 1) { |
|
451 | + if ($remaining > 1) |
|
452 | + { |
|
415 | 453 | //Add traversals up to first matching directory |
416 | 454 | $padLength = (count($relative) + $remaining - 1) * -1; |
417 | 455 | $relative = array_pad($relative, $padLength, '..'); |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | $schema = $this->constant('SCHEMA')->getValue(); |
50 | 50 | $validates = $this->constant('VALIDATES')->getValue(); |
51 | 51 | |
52 | - if (!isset($this->mapping[$type])) { |
|
53 | - $schema[$field] = ($source ?? self::DEFAULT_SOURCE) . ':' . ($origin ?: $field); |
|
52 | + if (!isset($this->mapping[$type])){ |
|
53 | + $schema[$field] = ($source ?? self::DEFAULT_SOURCE).':'.($origin ?: $field); |
|
54 | 54 | |
55 | 55 | $this->constant('SCHEMA')->setValue($schema); |
56 | 56 | |
@@ -61,9 +61,9 @@ discard block |
||
61 | 61 | |
62 | 62 | //Source can depend on type |
63 | 63 | $source ??= $definition['source']; |
64 | - $schema[$field] = $source . ':' . ($origin ?: $field); |
|
64 | + $schema[$field] = $source.':'.($origin ?: $field); |
|
65 | 65 | |
66 | - if (!empty($definition['validates'])) { |
|
66 | + if (!empty($definition['validates'])){ |
|
67 | 67 | //Pre-defined validation |
68 | 68 | $validates[$field] = $definition['validates']; |
69 | 69 | } |
@@ -49,7 +49,8 @@ discard block |
||
49 | 49 | $schema = $this->constant('SCHEMA')->getValue(); |
50 | 50 | $validates = $this->constant('VALIDATES')->getValue(); |
51 | 51 | |
52 | - if (!isset($this->mapping[$type])) { |
|
52 | + if (!isset($this->mapping[$type])) |
|
53 | + { |
|
53 | 54 | $schema[$field] = ($source ?? self::DEFAULT_SOURCE) . ':' . ($origin ?: $field); |
54 | 55 | |
55 | 56 | $this->constant('SCHEMA')->setValue($schema); |
@@ -63,7 +64,8 @@ discard block |
||
63 | 64 | $source ??= $definition['source']; |
64 | 65 | $schema[$field] = $source . ':' . ($origin ?: $field); |
65 | 66 | |
66 | - if (!empty($definition['validates'])) { |
|
67 | + if (!empty($definition['validates'])) |
|
68 | + { |
|
67 | 69 | //Pre-defined validation |
68 | 70 | $validates[$field] = $definition['validates']; |
69 | 71 | } |
@@ -76,9 +76,9 @@ discard block |
||
76 | 76 | $console->addCommand(MiddlewareCommand::class); |
77 | 77 | $console->addCommand(MigrationCommand::class, true); |
78 | 78 | |
79 | - try { |
|
79 | + try{ |
|
80 | 80 | $defaultNamespace = (new ReflectionClass($this->kernel))->getNamespaceName(); |
81 | - } catch (ReflectionException $e) { |
|
81 | + }catch (ReflectionException $e){ |
|
82 | 82 | $defaultNamespace = ''; |
83 | 83 | } |
84 | 84 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * Base directory for generated classes, class will be automatically localed into sub directory |
98 | 98 | * using given namespace. |
99 | 99 | */ |
100 | - 'directory' => directory('app') . 'src/', |
|
100 | + 'directory' => directory('app').'src/', |
|
101 | 101 | |
102 | 102 | /* |
103 | 103 | * Default namespace to be applied for every generated class. By default uses Kernel namespace |
@@ -76,9 +76,12 @@ |
||
76 | 76 | $console->addCommand(MiddlewareCommand::class); |
77 | 77 | $console->addCommand(MigrationCommand::class, true); |
78 | 78 | |
79 | - try { |
|
79 | + try |
|
80 | + { |
|
80 | 81 | $defaultNamespace = (new ReflectionClass($this->kernel))->getNamespaceName(); |
81 | - } catch (ReflectionException $e) { |
|
82 | + } |
|
83 | + catch (ReflectionException $e) |
|
84 | + { |
|
82 | 85 | $defaultNamespace = ''; |
83 | 86 | } |
84 | 87 |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | namespace Spiral\Scaffolder; |
13 | 13 | |
14 | -if (!function_exists('trimPostfix')) { |
|
14 | +if (!function_exists('trimPostfix')){ |
|
15 | 15 | /** |
16 | 16 | * @param string $name |
17 | 17 | * @param string $postfix |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | } |
27 | 27 | } |
28 | 28 | |
29 | -if (!function_exists('isAssociativeArray')) { |
|
29 | +if (!function_exists('isAssociativeArray')){ |
|
30 | 30 | /** |
31 | 31 | * @param array $array |
32 | 32 | * @return bool |
@@ -35,12 +35,12 @@ discard block |
||
35 | 35 | function isAssociativeArray(array $array): bool |
36 | 36 | { |
37 | 37 | $keys = []; |
38 | - foreach ($array as $key => $_) { |
|
39 | - if (!is_int($key)) { |
|
38 | + foreach ($array as $key => $_){ |
|
39 | + if (!is_int($key)){ |
|
40 | 40 | return true; |
41 | 41 | } |
42 | 42 | |
43 | - if ($key !== count($keys)) { |
|
43 | + if ($key !== count($keys)){ |
|
44 | 44 | return true; |
45 | 45 | } |
46 | 46 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | } |
52 | 52 | } |
53 | 53 | |
54 | -if (!function_exists('defineArrayType')) { |
|
54 | +if (!function_exists('defineArrayType')){ |
|
55 | 55 | /** |
56 | 56 | * @param array $array |
57 | 57 | * @param string|null $failureType |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | function defineArrayType(array $array, string $failureType = null): ?string |
62 | 62 | { |
63 | - $types = array_map(static fn($value): string => gettype($value), $array); |
|
63 | + $types = array_map(static fn($value) : string => gettype($value), $array); |
|
64 | 64 | |
65 | 65 | $types = array_unique($types); |
66 | 66 |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function hasField(string $name): bool |
74 | 74 | { |
75 | - if (!array_key_exists($name, $this->fields)) { |
|
75 | + if (!array_key_exists($name, $this->fields)){ |
|
76 | 76 | return false; |
77 | 77 | } |
78 | 78 | |
@@ -88,14 +88,14 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function setField(string $name, $value, bool $filter = true): void |
90 | 90 | { |
91 | - if ($value instanceof ValueInterface) { |
|
91 | + if ($value instanceof ValueInterface){ |
|
92 | 92 | //In case of non scalar values filters must be bypassed (check accessor compatibility?) |
93 | 93 | $this->fields[$name] = clone $value; |
94 | 94 | |
95 | 95 | return; |
96 | 96 | } |
97 | 97 | |
98 | - if (!$filter || (is_null($value) && $this->isNullable($name))) { |
|
98 | + if (!$filter || (is_null($value) && $this->isNullable($name))){ |
|
99 | 99 | //Bypassing all filters |
100 | 100 | $this->fields[$name] = $value; |
101 | 101 | |
@@ -105,10 +105,10 @@ discard block |
||
105 | 105 | //Checking if field have accessor |
106 | 106 | $accessor = $this->getMutator($name, ModelSchema::MUTATOR_ACCESSOR); |
107 | 107 | |
108 | - if ($accessor !== null) { |
|
108 | + if ($accessor !== null){ |
|
109 | 109 | //Setting value thought associated accessor |
110 | 110 | $this->thoughValue($accessor, $name, $value); |
111 | - } else { |
|
111 | + }else{ |
|
112 | 112 | //Setting value thought setter filter (if any) |
113 | 113 | $this->setMutated($name, $value); |
114 | 114 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | { |
126 | 126 | $value = $this->hasField($name) ? $this->fields[$name] : $default; |
127 | 127 | |
128 | - if ($value instanceof ValueInterface || (is_null($value) && $this->isNullable($name))) { |
|
128 | + if ($value instanceof ValueInterface || (is_null($value) && $this->isNullable($name))){ |
|
129 | 129 | //Direct access to value when value is accessor or null and declared as nullable |
130 | 130 | return $value; |
131 | 131 | } |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | //Checking if field have accessor (decorator) |
134 | 134 | $accessor = $this->getMutator($name, ModelSchema::MUTATOR_ACCESSOR); |
135 | 135 | |
136 | - if (!empty($accessor)) { |
|
136 | + if (!empty($accessor)){ |
|
137 | 137 | return $this->fields[$name] = $this->createValue($accessor, $name, $value); |
138 | 138 | } |
139 | 139 | |
@@ -153,15 +153,15 @@ discard block |
||
153 | 153 | */ |
154 | 154 | public function setFields(iterable $fields = [], bool $all = false) |
155 | 155 | { |
156 | - if (!\is_array($fields) && !$fields instanceof Traversable) { |
|
156 | + if (!\is_array($fields) && !$fields instanceof Traversable){ |
|
157 | 157 | return $this; |
158 | 158 | } |
159 | 159 | |
160 | - foreach ($fields as $name => $value) { |
|
161 | - if ($all || $this->isFillable($name)) { |
|
162 | - try { |
|
160 | + foreach ($fields as $name => $value){ |
|
161 | + if ($all || $this->isFillable($name)){ |
|
162 | + try{ |
|
163 | 163 | $this->setField($name, $value, true); |
164 | - } catch (AccessExceptionInterface $e) { |
|
164 | + }catch (AccessExceptionInterface $e){ |
|
165 | 165 | // We are suppressing field setting exceptions |
166 | 166 | } |
167 | 167 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | public function getFields(bool $filter = true): array |
183 | 183 | { |
184 | 184 | $result = []; |
185 | - foreach ($this->fields as $name => $_) { |
|
185 | + foreach ($this->fields as $name => $_){ |
|
186 | 186 | $result[$name] = $this->getField($name, null, $filter); |
187 | 187 | } |
188 | 188 | |
@@ -247,10 +247,10 @@ discard block |
||
247 | 247 | public function getValue(): array |
248 | 248 | { |
249 | 249 | $result = []; |
250 | - foreach ($this->fields as $field => $value) { |
|
251 | - if ($value instanceof ValueInterface) { |
|
250 | + foreach ($this->fields as $field => $value){ |
|
251 | + if ($value instanceof ValueInterface){ |
|
252 | 252 | $result[$field] = $value->getValue(); |
253 | - } else { |
|
253 | + }else{ |
|
254 | 254 | $result[$field] = $value; |
255 | 255 | } |
256 | 256 | } |
@@ -332,9 +332,9 @@ discard block |
||
332 | 332 | $value, |
333 | 333 | array $context = [] |
334 | 334 | ): ValueInterface { |
335 | - if (!is_string($type) || !class_exists($type)) { |
|
335 | + if (!is_string($type) || !class_exists($type)){ |
|
336 | 336 | throw new EntityException( |
337 | - "Unable to create accessor for field `{$name}` in " . static::class |
|
337 | + "Unable to create accessor for field `{$name}` in ".static::class |
|
338 | 338 | ); |
339 | 339 | } |
340 | 340 | |
@@ -352,10 +352,10 @@ discard block |
||
352 | 352 | { |
353 | 353 | $getter = $this->getMutator($name, ModelSchema::MUTATOR_GETTER); |
354 | 354 | |
355 | - if ($filter && !empty($getter)) { |
|
356 | - try { |
|
355 | + if ($filter && !empty($getter)){ |
|
356 | + try{ |
|
357 | 357 | return call_user_func($getter, $value); |
358 | - } catch (Exception $e) { |
|
358 | + }catch (Exception $e){ |
|
359 | 359 | //Trying to filter null value, every filter must support it |
360 | 360 | return call_user_func($getter, null); |
361 | 361 | } |
@@ -373,13 +373,13 @@ discard block |
||
373 | 373 | { |
374 | 374 | $setter = $this->getMutator($name, ModelSchema::MUTATOR_SETTER); |
375 | 375 | |
376 | - if (!empty($setter)) { |
|
377 | - try { |
|
376 | + if (!empty($setter)){ |
|
377 | + try{ |
|
378 | 378 | $this->fields[$name] = call_user_func($setter, $value); |
379 | - } catch (Exception $e) { |
|
379 | + }catch (Exception $e){ |
|
380 | 380 | //Exceptional situation, we are choosing to keep original field value |
381 | 381 | } |
382 | - } else { |
|
382 | + }else{ |
|
383 | 383 | $this->fields[$name] = $value; |
384 | 384 | } |
385 | 385 | } |
@@ -392,13 +392,13 @@ discard block |
||
392 | 392 | */ |
393 | 393 | private function thoughValue($type, string $name, $value): void |
394 | 394 | { |
395 | - if (array_key_exists($name, $this->fields)) { |
|
395 | + if (array_key_exists($name, $this->fields)){ |
|
396 | 396 | $field = $this->fields[$name]; |
397 | - } else { |
|
397 | + }else{ |
|
398 | 398 | $field = null; |
399 | 399 | } |
400 | 400 | |
401 | - if (empty($field) || !($field instanceof ValueInterface)) { |
|
401 | + if (empty($field) || !($field instanceof ValueInterface)){ |
|
402 | 402 | //New field representation |
403 | 403 | $field = $this->createValue($type, $name, $value); |
404 | 404 |
@@ -72,7 +72,8 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function hasField(string $name): bool |
74 | 74 | { |
75 | - if (!array_key_exists($name, $this->fields)) { |
|
75 | + if (!array_key_exists($name, $this->fields)) |
|
76 | + { |
|
76 | 77 | return false; |
77 | 78 | } |
78 | 79 | |
@@ -88,14 +89,16 @@ discard block |
||
88 | 89 | */ |
89 | 90 | public function setField(string $name, $value, bool $filter = true): void |
90 | 91 | { |
91 | - if ($value instanceof ValueInterface) { |
|
92 | + if ($value instanceof ValueInterface) |
|
93 | + { |
|
92 | 94 | //In case of non scalar values filters must be bypassed (check accessor compatibility?) |
93 | 95 | $this->fields[$name] = clone $value; |
94 | 96 | |
95 | 97 | return; |
96 | 98 | } |
97 | 99 | |
98 | - if (!$filter || (is_null($value) && $this->isNullable($name))) { |
|
100 | + if (!$filter || (is_null($value) && $this->isNullable($name))) |
|
101 | + { |
|
99 | 102 | //Bypassing all filters |
100 | 103 | $this->fields[$name] = $value; |
101 | 104 | |
@@ -105,10 +108,13 @@ discard block |
||
105 | 108 | //Checking if field have accessor |
106 | 109 | $accessor = $this->getMutator($name, ModelSchema::MUTATOR_ACCESSOR); |
107 | 110 | |
108 | - if ($accessor !== null) { |
|
111 | + if ($accessor !== null) |
|
112 | + { |
|
109 | 113 | //Setting value thought associated accessor |
110 | 114 | $this->thoughValue($accessor, $name, $value); |
111 | - } else { |
|
115 | + } |
|
116 | + else |
|
117 | + { |
|
112 | 118 | //Setting value thought setter filter (if any) |
113 | 119 | $this->setMutated($name, $value); |
114 | 120 | } |
@@ -125,7 +131,8 @@ discard block |
||
125 | 131 | { |
126 | 132 | $value = $this->hasField($name) ? $this->fields[$name] : $default; |
127 | 133 | |
128 | - if ($value instanceof ValueInterface || (is_null($value) && $this->isNullable($name))) { |
|
134 | + if ($value instanceof ValueInterface || (is_null($value) && $this->isNullable($name))) |
|
135 | + { |
|
129 | 136 | //Direct access to value when value is accessor or null and declared as nullable |
130 | 137 | return $value; |
131 | 138 | } |
@@ -133,7 +140,8 @@ discard block |
||
133 | 140 | //Checking if field have accessor (decorator) |
134 | 141 | $accessor = $this->getMutator($name, ModelSchema::MUTATOR_ACCESSOR); |
135 | 142 | |
136 | - if (!empty($accessor)) { |
|
143 | + if (!empty($accessor)) |
|
144 | + { |
|
137 | 145 | return $this->fields[$name] = $this->createValue($accessor, $name, $value); |
138 | 146 | } |
139 | 147 | |
@@ -153,15 +161,21 @@ discard block |
||
153 | 161 | */ |
154 | 162 | public function setFields(iterable $fields = [], bool $all = false) |
155 | 163 | { |
156 | - if (!\is_array($fields) && !$fields instanceof Traversable) { |
|
164 | + if (!\is_array($fields) && !$fields instanceof Traversable) |
|
165 | + { |
|
157 | 166 | return $this; |
158 | 167 | } |
159 | 168 | |
160 | - foreach ($fields as $name => $value) { |
|
161 | - if ($all || $this->isFillable($name)) { |
|
162 | - try { |
|
169 | + foreach ($fields as $name => $value) |
|
170 | + { |
|
171 | + if ($all || $this->isFillable($name)) |
|
172 | + { |
|
173 | + try |
|
174 | + { |
|
163 | 175 | $this->setField($name, $value, true); |
164 | - } catch (AccessExceptionInterface $e) { |
|
176 | + } |
|
177 | + catch (AccessExceptionInterface $e) |
|
178 | + { |
|
165 | 179 | // We are suppressing field setting exceptions |
166 | 180 | } |
167 | 181 | } |
@@ -182,7 +196,8 @@ discard block |
||
182 | 196 | public function getFields(bool $filter = true): array |
183 | 197 | { |
184 | 198 | $result = []; |
185 | - foreach ($this->fields as $name => $_) { |
|
199 | + foreach ($this->fields as $name => $_) |
|
200 | + { |
|
186 | 201 | $result[$name] = $this->getField($name, null, $filter); |
187 | 202 | } |
188 | 203 | |
@@ -247,10 +262,14 @@ discard block |
||
247 | 262 | public function getValue(): array |
248 | 263 | { |
249 | 264 | $result = []; |
250 | - foreach ($this->fields as $field => $value) { |
|
251 | - if ($value instanceof ValueInterface) { |
|
265 | + foreach ($this->fields as $field => $value) |
|
266 | + { |
|
267 | + if ($value instanceof ValueInterface) |
|
268 | + { |
|
252 | 269 | $result[$field] = $value->getValue(); |
253 | - } else { |
|
270 | + } |
|
271 | + else |
|
272 | + { |
|
254 | 273 | $result[$field] = $value; |
255 | 274 | } |
256 | 275 | } |
@@ -332,7 +351,8 @@ discard block |
||
332 | 351 | $value, |
333 | 352 | array $context = [] |
334 | 353 | ): ValueInterface { |
335 | - if (!is_string($type) || !class_exists($type)) { |
|
354 | + if (!is_string($type) || !class_exists($type)) |
|
355 | + { |
|
336 | 356 | throw new EntityException( |
337 | 357 | "Unable to create accessor for field `{$name}` in " . static::class |
338 | 358 | ); |
@@ -352,10 +372,14 @@ discard block |
||
352 | 372 | { |
353 | 373 | $getter = $this->getMutator($name, ModelSchema::MUTATOR_GETTER); |
354 | 374 | |
355 | - if ($filter && !empty($getter)) { |
|
356 | - try { |
|
375 | + if ($filter && !empty($getter)) |
|
376 | + { |
|
377 | + try |
|
378 | + { |
|
357 | 379 | return call_user_func($getter, $value); |
358 | - } catch (Exception $e) { |
|
380 | + } |
|
381 | + catch (Exception $e) |
|
382 | + { |
|
359 | 383 | //Trying to filter null value, every filter must support it |
360 | 384 | return call_user_func($getter, null); |
361 | 385 | } |
@@ -373,13 +397,19 @@ discard block |
||
373 | 397 | { |
374 | 398 | $setter = $this->getMutator($name, ModelSchema::MUTATOR_SETTER); |
375 | 399 | |
376 | - if (!empty($setter)) { |
|
377 | - try { |
|
400 | + if (!empty($setter)) |
|
401 | + { |
|
402 | + try |
|
403 | + { |
|
378 | 404 | $this->fields[$name] = call_user_func($setter, $value); |
379 | - } catch (Exception $e) { |
|
405 | + } |
|
406 | + catch (Exception $e) |
|
407 | + { |
|
380 | 408 | //Exceptional situation, we are choosing to keep original field value |
381 | 409 | } |
382 | - } else { |
|
410 | + } |
|
411 | + else |
|
412 | + { |
|
383 | 413 | $this->fields[$name] = $value; |
384 | 414 | } |
385 | 415 | } |
@@ -392,13 +422,17 @@ discard block |
||
392 | 422 | */ |
393 | 423 | private function thoughValue($type, string $name, $value): void |
394 | 424 | { |
395 | - if (array_key_exists($name, $this->fields)) { |
|
425 | + if (array_key_exists($name, $this->fields)) |
|
426 | + { |
|
396 | 427 | $field = $this->fields[$name]; |
397 | - } else { |
|
428 | + } |
|
429 | + else |
|
430 | + { |
|
398 | 431 | $field = null; |
399 | 432 | } |
400 | 433 | |
401 | - if (empty($field) || !($field instanceof ValueInterface)) { |
|
434 | + if (empty($field) || !($field instanceof ValueInterface)) |
|
435 | + { |
|
402 | 436 | //New field representation |
403 | 437 | $field = $this->createValue($type, $name, $value); |
404 | 438 |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | { |
32 | 32 | $rules = is_array($rules) ? $rules : [$rules]; |
33 | 33 | |
34 | - foreach ($rules as $rule) { |
|
35 | - if ($rule instanceof Closure) { |
|
34 | + foreach ($rules as $rule){ |
|
35 | + if ($rule instanceof Closure){ |
|
36 | 36 | yield null => $rule; |
37 | 37 | continue; |
38 | 38 | } |
@@ -46,17 +46,17 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function parseCheck($chunk) |
48 | 48 | { |
49 | - if (is_string($chunk)) { |
|
49 | + if (is_string($chunk)){ |
|
50 | 50 | $function = str_replace('::', ':', $chunk); |
51 | - } else { |
|
52 | - if (!is_array($chunk) || !isset($chunk[0])) { |
|
51 | + }else{ |
|
52 | + if (!is_array($chunk) || !isset($chunk[0])){ |
|
53 | 53 | throw new ParserException('Validation rule does not define any check.'); |
54 | 54 | } |
55 | 55 | |
56 | 56 | $function = $chunk[0]; |
57 | 57 | } |
58 | 58 | |
59 | - if (is_string($function)) { |
|
59 | + if (is_string($function)){ |
|
60 | 60 | return str_replace('::', ':', $function); |
61 | 61 | } |
62 | 62 | |
@@ -68,18 +68,18 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function parseArgs($chunk): array |
70 | 70 | { |
71 | - if (!is_array($chunk)) { |
|
71 | + if (!is_array($chunk)){ |
|
72 | 72 | return []; |
73 | 73 | } |
74 | 74 | |
75 | - foreach (self::ARGUMENTS as $index) { |
|
76 | - if (isset($chunk[$index])) { |
|
75 | + foreach (self::ARGUMENTS as $index){ |
|
76 | + if (isset($chunk[$index])){ |
|
77 | 77 | return $chunk[$index]; |
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | 81 | unset($chunk[0]); |
82 | - foreach (array_merge(self::MESSAGES, self::CONDITIONS) as $index) { |
|
82 | + foreach (array_merge(self::MESSAGES, self::CONDITIONS) as $index){ |
|
83 | 83 | unset($chunk[$index]); |
84 | 84 | } |
85 | 85 | |
@@ -91,12 +91,12 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function parseMessage($chunk): ?string |
93 | 93 | { |
94 | - if (!is_array($chunk)) { |
|
94 | + if (!is_array($chunk)){ |
|
95 | 95 | return null; |
96 | 96 | } |
97 | 97 | |
98 | - foreach (self::MESSAGES as $index) { |
|
99 | - if (isset($chunk[$index])) { |
|
98 | + foreach (self::MESSAGES as $index){ |
|
99 | + if (isset($chunk[$index])){ |
|
100 | 100 | return $chunk[$index]; |
101 | 101 | } |
102 | 102 | } |
@@ -109,13 +109,13 @@ discard block |
||
109 | 109 | */ |
110 | 110 | public function parseConditions($chunk): array |
111 | 111 | { |
112 | - foreach (self::CONDITIONS as $index) { |
|
113 | - if (isset($chunk[$index])) { |
|
112 | + foreach (self::CONDITIONS as $index){ |
|
113 | + if (isset($chunk[$index])){ |
|
114 | 114 | $conditions = []; |
115 | - foreach ((array)$chunk[$index] as $key => $value) { |
|
116 | - if (is_numeric($key)) { |
|
115 | + foreach ((array)$chunk[$index] as $key => $value){ |
|
116 | + if (is_numeric($key)){ |
|
117 | 117 | $conditions[$value] = []; |
118 | - } else { |
|
118 | + }else{ |
|
119 | 119 | $conditions[$key] = (array)$value; |
120 | 120 | } |
121 | 121 | } |
@@ -31,8 +31,10 @@ discard block |
||
31 | 31 | { |
32 | 32 | $rules = is_array($rules) ? $rules : [$rules]; |
33 | 33 | |
34 | - foreach ($rules as $rule) { |
|
35 | - if ($rule instanceof Closure) { |
|
34 | + foreach ($rules as $rule) |
|
35 | + { |
|
36 | + if ($rule instanceof Closure) |
|
37 | + { |
|
36 | 38 | yield null => $rule; |
37 | 39 | continue; |
38 | 40 | } |
@@ -46,17 +48,22 @@ discard block |
||
46 | 48 | */ |
47 | 49 | public function parseCheck($chunk) |
48 | 50 | { |
49 | - if (is_string($chunk)) { |
|
51 | + if (is_string($chunk)) |
|
52 | + { |
|
50 | 53 | $function = str_replace('::', ':', $chunk); |
51 | - } else { |
|
52 | - if (!is_array($chunk) || !isset($chunk[0])) { |
|
54 | + } |
|
55 | + else |
|
56 | + { |
|
57 | + if (!is_array($chunk) || !isset($chunk[0])) |
|
58 | + { |
|
53 | 59 | throw new ParserException('Validation rule does not define any check.'); |
54 | 60 | } |
55 | 61 | |
56 | 62 | $function = $chunk[0]; |
57 | 63 | } |
58 | 64 | |
59 | - if (is_string($function)) { |
|
65 | + if (is_string($function)) |
|
66 | + { |
|
60 | 67 | return str_replace('::', ':', $function); |
61 | 68 | } |
62 | 69 | |
@@ -68,18 +75,22 @@ discard block |
||
68 | 75 | */ |
69 | 76 | public function parseArgs($chunk): array |
70 | 77 | { |
71 | - if (!is_array($chunk)) { |
|
78 | + if (!is_array($chunk)) |
|
79 | + { |
|
72 | 80 | return []; |
73 | 81 | } |
74 | 82 | |
75 | - foreach (self::ARGUMENTS as $index) { |
|
76 | - if (isset($chunk[$index])) { |
|
83 | + foreach (self::ARGUMENTS as $index) |
|
84 | + { |
|
85 | + if (isset($chunk[$index])) |
|
86 | + { |
|
77 | 87 | return $chunk[$index]; |
78 | 88 | } |
79 | 89 | } |
80 | 90 | |
81 | 91 | unset($chunk[0]); |
82 | - foreach (array_merge(self::MESSAGES, self::CONDITIONS) as $index) { |
|
92 | + foreach (array_merge(self::MESSAGES, self::CONDITIONS) as $index) |
|
93 | + { |
|
83 | 94 | unset($chunk[$index]); |
84 | 95 | } |
85 | 96 | |
@@ -91,12 +102,15 @@ discard block |
||
91 | 102 | */ |
92 | 103 | public function parseMessage($chunk): ?string |
93 | 104 | { |
94 | - if (!is_array($chunk)) { |
|
105 | + if (!is_array($chunk)) |
|
106 | + { |
|
95 | 107 | return null; |
96 | 108 | } |
97 | 109 | |
98 | - foreach (self::MESSAGES as $index) { |
|
99 | - if (isset($chunk[$index])) { |
|
110 | + foreach (self::MESSAGES as $index) |
|
111 | + { |
|
112 | + if (isset($chunk[$index])) |
|
113 | + { |
|
100 | 114 | return $chunk[$index]; |
101 | 115 | } |
102 | 116 | } |
@@ -109,13 +123,19 @@ discard block |
||
109 | 123 | */ |
110 | 124 | public function parseConditions($chunk): array |
111 | 125 | { |
112 | - foreach (self::CONDITIONS as $index) { |
|
113 | - if (isset($chunk[$index])) { |
|
126 | + foreach (self::CONDITIONS as $index) |
|
127 | + { |
|
128 | + if (isset($chunk[$index])) |
|
129 | + { |
|
114 | 130 | $conditions = []; |
115 | - foreach ((array)$chunk[$index] as $key => $value) { |
|
116 | - if (is_numeric($key)) { |
|
131 | + foreach ((array)$chunk[$index] as $key => $value) |
|
132 | + { |
|
133 | + if (is_numeric($key)) |
|
134 | + { |
|
117 | 135 | $conditions[$value] = []; |
118 | - } else { |
|
136 | + } |
|
137 | + else |
|
138 | + { |
|
119 | 139 | $conditions[$key] = (array)$value; |
120 | 140 | } |
121 | 141 | } |