@@ -40,7 +40,8 @@ |
||
40 | 40 | $finalizer->shouldReceive('addFinalizer')->once(); |
41 | 41 | |
42 | 42 | $this->container->bind(ConfiguratorInterface::class, new ConfigManager( |
43 | - new class() implements LoaderInterface { |
|
43 | + new class() implements LoaderInterface |
|
44 | + { |
|
44 | 45 | public function has(string $section): bool |
45 | 46 | { |
46 | 47 | return false; |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | $finalizer->shouldReceive('addFinalizer')->once(); |
32 | 32 | |
33 | 33 | $this->container->bind(ConfiguratorInterface::class, new ConfigManager( |
34 | - new class() implements LoaderInterface { |
|
34 | + new class() implements LoaderInterface{ |
|
35 | 35 | public function has(string $section): bool |
36 | 36 | { |
37 | 37 | return false; |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | return $this->container->get(LogsInterface::class)->getLogger('test'); |
166 | 166 | } |
167 | 167 | |
168 | - protected function createLogRecord(int $level): array|LogRecord |
|
168 | + protected function createLogRecord(int $level): array | LogRecord |
|
169 | 169 | { |
170 | 170 | return Logger::API === 2 |
171 | 171 | ? ['level' => $level] |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | $finalizer->shouldReceive('addFinalizer')->once(); |
33 | 33 | |
34 | 34 | $this->container->bind(ConfiguratorInterface::class, new ConfigManager( |
35 | - new class() implements LoaderInterface { |
|
35 | + new class() implements LoaderInterface{ |
|
36 | 36 | public function has(string $section): bool |
37 | 37 | { |
38 | 38 | return false; |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | ] |
84 | 84 | ])); |
85 | 85 | |
86 | - $logger = $this->container->get(LogsInterface::class)->getLogger('test');; |
|
86 | + $logger = $this->container->get(LogsInterface::class)->getLogger('test'); ; |
|
87 | 87 | |
88 | 88 | $this->assertCount(1, $logger->getProcessors()); |
89 | 89 | $this->assertInstanceOf(PsrLogMessageProcessor::class, $logger->getProcessors()[0]); |
@@ -40,7 +40,8 @@ |
||
40 | 40 | $finalizer->shouldReceive('addFinalizer')->once(); |
41 | 41 | |
42 | 42 | $this->container->bind(ConfiguratorInterface::class, new ConfigManager( |
43 | - new class() implements LoaderInterface { |
|
43 | + new class() implements LoaderInterface |
|
44 | + { |
|
44 | 45 | public function has(string $section): bool |
45 | 46 | { |
46 | 47 | return false; |
@@ -38,8 +38,10 @@ |
||
38 | 38 | public function locateCommands(): array |
39 | 39 | { |
40 | 40 | $commands = []; |
41 | - foreach ($this->classes->getScopedClasses('consoleCommands', SymfonyCommand::class) as $class) { |
|
42 | - if ($class->isAbstract()) { |
|
41 | + foreach ($this->classes->getScopedClasses('consoleCommands', SymfonyCommand::class) as $class) |
|
42 | + { |
|
43 | + if ($class->isAbstract()) |
|
44 | + { |
|
43 | 45 | continue; |
44 | 46 | } |
45 | 47 |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | private readonly ScopedClassesInterface $classes, |
18 | 18 | ContainerInterface $container, |
19 | 19 | array $interceptors = [], |
20 | - ) { |
|
20 | + ){ |
|
21 | 21 | $this->container = $container; |
22 | 22 | $this->interceptors = $interceptors; |
23 | 23 | } |
@@ -25,8 +25,8 @@ discard block |
||
25 | 25 | public function locateCommands(): array |
26 | 26 | { |
27 | 27 | $commands = []; |
28 | - foreach ($this->classes->getScopedClasses('consoleCommands', SymfonyCommand::class) as $class) { |
|
29 | - if ($class->isAbstract()) { |
|
28 | + foreach ($this->classes->getScopedClasses('consoleCommands', SymfonyCommand::class) as $class){ |
|
29 | + if ($class->isAbstract()){ |
|
30 | 30 | continue; |
31 | 31 | } |
32 | 32 |
@@ -47,7 +47,7 @@ |
||
47 | 47 | 'directories' => [], |
48 | 48 | 'scopes' => [ |
49 | 49 | 'prototypes' => [ |
50 | - 'directories' => [__DIR__ . '/Fixtures'] |
|
50 | + 'directories' => [__DIR__.'/Fixtures'] |
|
51 | 51 | ] |
52 | 52 | ] |
53 | 53 | ]))); |
@@ -76,7 +76,7 @@ |
||
76 | 76 | 'test' => $this->defaultCache, |
77 | 77 | 'array' => new ArrayStorage(), |
78 | 78 | ][$name] ?? null; |
79 | - if ($result === null) { |
|
79 | + if ($result === null){ |
|
80 | 80 | throw new NotFoundException(); |
81 | 81 | } |
82 | 82 | return $result; |
@@ -76,7 +76,8 @@ |
||
76 | 76 | 'test' => $this->defaultCache, |
77 | 77 | 'array' => new ArrayStorage(), |
78 | 78 | ][$name] ?? null; |
79 | - if ($result === null) { |
|
79 | + if ($result === null) |
|
80 | + { |
|
80 | 81 | throw new NotFoundException(); |
81 | 82 | } |
82 | 83 | return $result; |
@@ -48,7 +48,8 @@ |
||
48 | 48 | |
49 | 49 | public function testRewindAfterRead(): void |
50 | 50 | { |
51 | - if (PHP_VERSION_ID < 80000) { |
|
51 | + if (PHP_VERSION_ID < 80000) |
|
52 | + { |
|
52 | 53 | $this->markTestSkipped('See issue https://bugs.php.net/bug.php?id=79927.'); |
53 | 54 | } |
54 | 55 |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | |
49 | 49 | public function testRewindAfterRead(): void |
50 | 50 | { |
51 | - if (PHP_VERSION_ID < 80000) { |
|
51 | + if (PHP_VERSION_ID < 80000){ |
|
52 | 52 | $this->markTestSkipped('See issue https://bugs.php.net/bug.php?id=79927.'); |
53 | 53 | } |
54 | 54 | |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | $rValue = 'return-value'; |
104 | 104 | $stream = $this->createStream(self::DEFAULT_SEQUENCE, $rValue); |
105 | 105 | |
106 | - $result = (string) $stream; |
|
106 | + $result = (string)$stream; |
|
107 | 107 | |
108 | - $this->assertSame(self::DEFAULT_CONTENT_RESULT . $rValue, $result); |
|
108 | + $this->assertSame(self::DEFAULT_CONTENT_RESULT.$rValue, $result); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | public function testToStringWithReturnOnly(): void |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | $rValue = 'return-value'; |
114 | 114 | $stream = $this->createStream([], $rValue); |
115 | 115 | |
116 | - $result = (string) $stream; |
|
116 | + $result = (string)$stream; |
|
117 | 117 | |
118 | 118 | $this->assertSame($rValue, $result); |
119 | 119 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | $stream = $this->createStream(); |
124 | 124 | $stream->close(); |
125 | 125 | |
126 | - $this->assertSame('', (string) $stream); |
|
126 | + $this->assertSame('', (string)$stream); |
|
127 | 127 | |
128 | 128 | $this->expectException(RuntimeException::class); |
129 | 129 | $this->expectExceptionMessage('Unable to read stream contents.'); |
@@ -27,23 +27,23 @@ discard block |
||
27 | 27 | |
28 | 28 | public function __toString(): string |
29 | 29 | { |
30 | - try { |
|
30 | + try{ |
|
31 | 31 | return $this->getContents(); |
32 | - } catch (\Exception $e) { |
|
32 | + }catch (\Exception $e){ |
|
33 | 33 | return ''; |
34 | 34 | } |
35 | 35 | } |
36 | 36 | |
37 | 37 | public function close(): void |
38 | 38 | { |
39 | - if ($this->stream !== null) { |
|
39 | + if ($this->stream !== null){ |
|
40 | 40 | $this->detach(); |
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | 44 | public function detach() |
45 | 45 | { |
46 | - if ($this->stream === null) { |
|
46 | + if ($this->stream === null){ |
|
47 | 47 | return null; |
48 | 48 | } |
49 | 49 | $this->stream = null; |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | |
82 | 82 | public function rewind(): void |
83 | 83 | { |
84 | - if ($this->stream !== null) { |
|
84 | + if ($this->stream !== null){ |
|
85 | 85 | $this->stream->rewind(); |
86 | 86 | } |
87 | 87 | $this->caret = 0; |
@@ -105,26 +105,26 @@ discard block |
||
105 | 105 | |
106 | 106 | public function read($length): string |
107 | 107 | { |
108 | - if (!$this->readable) { |
|
108 | + if (!$this->readable){ |
|
109 | 109 | throw new RuntimeException('Cannot read from non-readable stream.'); |
110 | 110 | } |
111 | - if ($this->stream === null) { |
|
111 | + if ($this->stream === null){ |
|
112 | 112 | throw new RuntimeException('Cannot read from detached stream.'); |
113 | 113 | } |
114 | - do { |
|
115 | - if ($this->started) { |
|
114 | + do{ |
|
115 | + if ($this->started){ |
|
116 | 116 | $read = (string)$this->stream->send(null); |
117 | - } else { |
|
117 | + }else{ |
|
118 | 118 | $this->started = true; |
119 | 119 | $read = (string)$this->stream->current(); |
120 | 120 | } |
121 | - if (!$this->stream->valid()) { |
|
121 | + if (!$this->stream->valid()){ |
|
122 | 122 | $read .= $this->stream->getReturn(); |
123 | 123 | break; |
124 | 124 | } |
125 | - } while ($read === ''); |
|
125 | + }while ($read === ''); |
|
126 | 126 | $this->caret += \strlen($read); |
127 | - if (!$this->stream->valid()) { |
|
127 | + if (!$this->stream->valid()){ |
|
128 | 128 | $this->size = $this->caret; |
129 | 129 | } |
130 | 130 | return $read; |
@@ -132,19 +132,19 @@ discard block |
||
132 | 132 | |
133 | 133 | public function getContents(): string |
134 | 134 | { |
135 | - if ($this->stream === null) { |
|
135 | + if ($this->stream === null){ |
|
136 | 136 | throw new RuntimeException('Unable to read stream contents.'); |
137 | 137 | } |
138 | 138 | $content = ''; |
139 | - do { |
|
139 | + do{ |
|
140 | 140 | $content .= $this->read(PHP_INT_MAX); |
141 | - } while ($this->stream->valid()); |
|
141 | + }while ($this->stream->valid()); |
|
142 | 142 | return $content; |
143 | 143 | } |
144 | 144 | |
145 | 145 | public function getMetadata($key = null) |
146 | 146 | { |
147 | - if ($this->stream === null) { |
|
147 | + if ($this->stream === null){ |
|
148 | 148 | return $key ? null : []; |
149 | 149 | } |
150 | 150 | |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | 'eof' => $this->eof(), |
154 | 154 | ]; |
155 | 155 | |
156 | - if (null === $key) { |
|
156 | + if (null === $key){ |
|
157 | 157 | return $meta; |
158 | 158 | } |
159 | 159 |
@@ -27,23 +27,28 @@ discard block |
||
27 | 27 | |
28 | 28 | public function __toString(): string |
29 | 29 | { |
30 | - try { |
|
30 | + try |
|
31 | + { |
|
31 | 32 | return $this->getContents(); |
32 | - } catch (\Exception $e) { |
|
33 | + } |
|
34 | + catch (\Exception $e) |
|
35 | + { |
|
33 | 36 | return ''; |
34 | 37 | } |
35 | 38 | } |
36 | 39 | |
37 | 40 | public function close(): void |
38 | 41 | { |
39 | - if ($this->stream !== null) { |
|
42 | + if ($this->stream !== null) |
|
43 | + { |
|
40 | 44 | $this->detach(); |
41 | 45 | } |
42 | 46 | } |
43 | 47 | |
44 | 48 | public function detach() |
45 | 49 | { |
46 | - if ($this->stream === null) { |
|
50 | + if ($this->stream === null) |
|
51 | + { |
|
47 | 52 | return null; |
48 | 53 | } |
49 | 54 | $this->stream = null; |
@@ -81,7 +86,8 @@ discard block |
||
81 | 86 | |
82 | 87 | public function rewind(): void |
83 | 88 | { |
84 | - if ($this->stream !== null) { |
|
89 | + if ($this->stream !== null) |
|
90 | + { |
|
85 | 91 | $this->stream->rewind(); |
86 | 92 | } |
87 | 93 | $this->caret = 0; |
@@ -105,26 +111,34 @@ discard block |
||
105 | 111 | |
106 | 112 | public function read($length): string |
107 | 113 | { |
108 | - if (!$this->readable) { |
|
114 | + if (!$this->readable) |
|
115 | + { |
|
109 | 116 | throw new RuntimeException('Cannot read from non-readable stream.'); |
110 | 117 | } |
111 | - if ($this->stream === null) { |
|
118 | + if ($this->stream === null) |
|
119 | + { |
|
112 | 120 | throw new RuntimeException('Cannot read from detached stream.'); |
113 | 121 | } |
114 | - do { |
|
115 | - if ($this->started) { |
|
122 | + do |
|
123 | + { |
|
124 | + if ($this->started) |
|
125 | + { |
|
116 | 126 | $read = (string)$this->stream->send(null); |
117 | - } else { |
|
127 | + } |
|
128 | + else |
|
129 | + { |
|
118 | 130 | $this->started = true; |
119 | 131 | $read = (string)$this->stream->current(); |
120 | 132 | } |
121 | - if (!$this->stream->valid()) { |
|
133 | + if (!$this->stream->valid()) |
|
134 | + { |
|
122 | 135 | $read .= $this->stream->getReturn(); |
123 | 136 | break; |
124 | 137 | } |
125 | 138 | } while ($read === ''); |
126 | 139 | $this->caret += \strlen($read); |
127 | - if (!$this->stream->valid()) { |
|
140 | + if (!$this->stream->valid()) |
|
141 | + { |
|
128 | 142 | $this->size = $this->caret; |
129 | 143 | } |
130 | 144 | return $read; |
@@ -132,11 +146,13 @@ discard block |
||
132 | 146 | |
133 | 147 | public function getContents(): string |
134 | 148 | { |
135 | - if ($this->stream === null) { |
|
149 | + if ($this->stream === null) |
|
150 | + { |
|
136 | 151 | throw new RuntimeException('Unable to read stream contents.'); |
137 | 152 | } |
138 | 153 | $content = ''; |
139 | - do { |
|
154 | + do |
|
155 | + { |
|
140 | 156 | $content .= $this->read(PHP_INT_MAX); |
141 | 157 | } while ($this->stream->valid()); |
142 | 158 | return $content; |
@@ -144,7 +160,8 @@ discard block |
||
144 | 160 | |
145 | 161 | public function getMetadata($key = null) |
146 | 162 | { |
147 | - if ($this->stream === null) { |
|
163 | + if ($this->stream === null) |
|
164 | + { |
|
148 | 165 | return $key ? null : []; |
149 | 166 | } |
150 | 167 | |
@@ -153,7 +170,8 @@ discard block |
||
153 | 170 | 'eof' => $this->eof(), |
154 | 171 | ]; |
155 | 172 | |
156 | - if (null === $key) { |
|
173 | + if (null === $key) |
|
174 | + { |
|
157 | 175 | return $meta; |
158 | 176 | } |
159 | 177 |
@@ -23,7 +23,7 @@ |
||
23 | 23 | /** |
24 | 24 | * Default file mode for this manager. |
25 | 25 | */ |
26 | - public const DEFAULT_FILE_MODE = self::READONLY; |
|
26 | + public const DEFAULT_FILE_MODE = self::readonly; |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Files to be removed when component destructed. |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function __destruct() |
38 | 38 | { |
39 | - foreach ($this->destructFiles as $filename) { |
|
39 | + foreach ($this->destructFiles as $filename){ |
|
40 | 40 | $this->delete($filename); |
41 | 41 | } |
42 | 42 | } |
@@ -49,30 +49,30 @@ discard block |
||
49 | 49 | int $mode = null, |
50 | 50 | bool $recursivePermissions = true |
51 | 51 | ): bool { |
52 | - if (empty($mode)) { |
|
52 | + if (empty($mode)){ |
|
53 | 53 | $mode = self::DEFAULT_FILE_MODE; |
54 | 54 | } |
55 | 55 | |
56 | 56 | //Directories always executable |
57 | 57 | $mode |= 0o111; |
58 | - if (\is_dir($directory)) { |
|
58 | + if (\is_dir($directory)){ |
|
59 | 59 | //Exists :( |
60 | 60 | return $this->setPermissions($directory, $mode); |
61 | 61 | } |
62 | 62 | |
63 | - if (!$recursivePermissions) { |
|
63 | + if (!$recursivePermissions){ |
|
64 | 64 | return \mkdir($directory, $mode, true); |
65 | 65 | } |
66 | 66 | |
67 | 67 | $directoryChain = [\basename($directory)]; |
68 | 68 | |
69 | 69 | $baseDirectory = $directory; |
70 | - while (!\is_dir($baseDirectory = \dirname($baseDirectory))) { |
|
70 | + while (!\is_dir($baseDirectory = \dirname($baseDirectory))){ |
|
71 | 71 | $directoryChain[] = \basename($baseDirectory); |
72 | 72 | } |
73 | 73 | |
74 | - foreach (\array_reverse($directoryChain) as $dir) { |
|
75 | - if (!mkdir($baseDirectory = \sprintf('%s/%s', $baseDirectory, $dir))) { |
|
74 | + foreach (\array_reverse($directoryChain) as $dir){ |
|
75 | + if (!mkdir($baseDirectory = \sprintf('%s/%s', $baseDirectory, $dir))){ |
|
76 | 76 | return false; |
77 | 77 | } |
78 | 78 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | |
85 | 85 | public function read(string $filename): string |
86 | 86 | { |
87 | - if (!$this->exists($filename)) { |
|
87 | + if (!$this->exists($filename)){ |
|
88 | 88 | throw new FileNotFoundException($filename); |
89 | 89 | } |
90 | 90 | |
@@ -103,12 +103,12 @@ discard block |
||
103 | 103 | ): bool { |
104 | 104 | $mode ??= self::DEFAULT_FILE_MODE; |
105 | 105 | |
106 | - try { |
|
107 | - if ($ensureDirectory) { |
|
106 | + try{ |
|
107 | + if ($ensureDirectory){ |
|
108 | 108 | $this->ensureDirectory(\dirname($filename), $mode); |
109 | 109 | } |
110 | 110 | |
111 | - if ($this->exists($filename)) { |
|
111 | + if ($this->exists($filename)){ |
|
112 | 112 | //Forcing mode for existed file |
113 | 113 | $this->setPermissions($filename, $mode); |
114 | 114 | } |
@@ -119,12 +119,12 @@ discard block |
||
119 | 119 | $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
120 | 120 | ); |
121 | 121 | |
122 | - if ($result !== false) { |
|
122 | + if ($result !== false){ |
|
123 | 123 | //Forcing mode after file creation |
124 | 124 | $this->setPermissions($filename, $mode); |
125 | 125 | } |
126 | - } catch (\Exception $e) { |
|
127 | - throw new WriteErrorException($e->getMessage(), (int) $e->getCode(), $e); |
|
126 | + }catch (\Exception $e){ |
|
127 | + throw new WriteErrorException($e->getMessage(), (int)$e->getCode(), $e); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | return $result !== false; |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | |
142 | 142 | public function delete(string $filename): bool |
143 | 143 | { |
144 | - if ($this->exists($filename)) { |
|
144 | + if ($this->exists($filename)){ |
|
145 | 145 | $result = \unlink($filename); |
146 | 146 | |
147 | 147 | //Wiping out changes in local file cache |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | */ |
161 | 161 | public function deleteDirectory(string $directory, bool $contentOnly = false): bool |
162 | 162 | { |
163 | - if (!$this->isDirectory($directory)) { |
|
163 | + if (!$this->isDirectory($directory)){ |
|
164 | 164 | throw new FilesException(\sprintf('Undefined or invalid directory %s', $directory)); |
165 | 165 | } |
166 | 166 | |
@@ -169,15 +169,15 @@ discard block |
||
169 | 169 | \RecursiveIteratorIterator::CHILD_FIRST |
170 | 170 | ); |
171 | 171 | |
172 | - foreach ($files as $file) { |
|
173 | - if ($file->isDir()) { |
|
172 | + foreach ($files as $file){ |
|
173 | + if ($file->isDir()){ |
|
174 | 174 | \rmdir($file->getRealPath()); |
175 | - } else { |
|
175 | + }else{ |
|
176 | 176 | $this->delete($file->getRealPath()); |
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
180 | - if (!$contentOnly) { |
|
180 | + if (!$contentOnly){ |
|
181 | 181 | return \rmdir($directory); |
182 | 182 | } |
183 | 183 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | |
187 | 187 | public function move(string $filename, string $destination): bool |
188 | 188 | { |
189 | - if (!$this->exists($filename)) { |
|
189 | + if (!$this->exists($filename)){ |
|
190 | 190 | throw new FileNotFoundException($filename); |
191 | 191 | } |
192 | 192 | |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | |
196 | 196 | public function copy(string $filename, string $destination): bool |
197 | 197 | { |
198 | - if (!$this->exists($filename)) { |
|
198 | + if (!$this->exists($filename)){ |
|
199 | 199 | throw new FileNotFoundException($filename); |
200 | 200 | } |
201 | 201 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | |
205 | 205 | public function touch(string $filename, int $mode = null): bool |
206 | 206 | { |
207 | - if (!\touch($filename)) { |
|
207 | + if (!\touch($filename)){ |
|
208 | 208 | return false; |
209 | 209 | } |
210 | 210 | |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | |
219 | 219 | public function size(string $filename): int |
220 | 220 | { |
221 | - if (!$this->exists($filename)) { |
|
221 | + if (!$this->exists($filename)){ |
|
222 | 222 | throw new FileNotFoundException($filename); |
223 | 223 | } |
224 | 224 | |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | |
233 | 233 | public function md5(string $filename): string |
234 | 234 | { |
235 | - if (!$this->exists($filename)) { |
|
235 | + if (!$this->exists($filename)){ |
|
236 | 236 | throw new FileNotFoundException($filename); |
237 | 237 | } |
238 | 238 | |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | |
242 | 242 | public function time(string $filename): int |
243 | 243 | { |
244 | - if (!$this->exists($filename)) { |
|
244 | + if (!$this->exists($filename)){ |
|
245 | 245 | throw new FileNotFoundException($filename); |
246 | 246 | } |
247 | 247 | |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | |
261 | 261 | public function getPermissions(string $filename): int |
262 | 262 | { |
263 | - if (!$this->exists($filename)) { |
|
263 | + if (!$this->exists($filename)){ |
|
264 | 264 | throw new FileNotFoundException($filename); |
265 | 265 | } |
266 | 266 | |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | |
270 | 270 | public function setPermissions(string $filename, int $mode): bool |
271 | 271 | { |
272 | - if (\is_dir($filename)) { |
|
272 | + if (\is_dir($filename)){ |
|
273 | 273 | //Directories must always be executable (i.e. 664 for dir => 775) |
274 | 274 | $mode |= 0111; |
275 | 275 | } |
@@ -280,9 +280,9 @@ discard block |
||
280 | 280 | public function getFiles(string $location, string $pattern = null): array |
281 | 281 | { |
282 | 282 | $result = []; |
283 | - foreach ($this->filesIterator($location, $pattern) as $filename) { |
|
284 | - if ($this->isDirectory($filename->getPathname())) { |
|
285 | - $result = \array_merge($result, $this->getFiles($filename . DIRECTORY_SEPARATOR)); |
|
283 | + foreach ($this->filesIterator($location, $pattern) as $filename){ |
|
284 | + if ($this->isDirectory($filename->getPathname())){ |
|
285 | + $result = \array_merge($result, $this->getFiles($filename.DIRECTORY_SEPARATOR)); |
|
286 | 286 | |
287 | 287 | continue; |
288 | 288 | } |
@@ -295,13 +295,13 @@ discard block |
||
295 | 295 | |
296 | 296 | public function tempFilename(string $extension = '', string $location = null): string |
297 | 297 | { |
298 | - if (empty($location)) { |
|
298 | + if (empty($location)){ |
|
299 | 299 | $location = \sys_get_temp_dir(); |
300 | 300 | } |
301 | 301 | |
302 | 302 | $filename = \tempnam($location, 'spiral'); |
303 | 303 | |
304 | - if (!empty($extension)) { |
|
304 | + if (!empty($extension)){ |
|
305 | 305 | $old = $filename; |
306 | 306 | $filename = \sprintf('%s.%s', $filename, $extension); |
307 | 307 | \rename($old, $filename); |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | public function normalizePath(string $path, bool $asDirectory = false): string |
315 | 315 | { |
316 | 316 | $isUnc = \str_starts_with($path, '\\\\') || \str_starts_with($path, '//'); |
317 | - if ($isUnc) { |
|
317 | + if ($isUnc){ |
|
318 | 318 | $leadingSlashes = \substr($path, 0, 2); |
319 | 319 | $path = \substr($path, 2); |
320 | 320 | } |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | $path = \str_replace(['//', '\\'], '/', $path); |
323 | 323 | |
324 | 324 | //Potentially open links and ../ type directories? |
325 | - return ($isUnc ? $leadingSlashes : '') . \rtrim($path, '/') . ($asDirectory ? '/' : ''); |
|
325 | + return ($isUnc ? $leadingSlashes : '').\rtrim($path, '/').($asDirectory ? '/' : ''); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -337,21 +337,21 @@ discard block |
||
337 | 337 | $path = \explode('/', $path); |
338 | 338 | $relative = $path; |
339 | 339 | |
340 | - foreach ($from as $depth => $dir) { |
|
340 | + foreach ($from as $depth => $dir){ |
|
341 | 341 | //Find first non-matching dir |
342 | - if ($dir === $path[$depth]) { |
|
342 | + if ($dir === $path[$depth]){ |
|
343 | 343 | //Ignore this directory |
344 | 344 | \array_shift($relative); |
345 | - } else { |
|
345 | + }else{ |
|
346 | 346 | //Get number of remaining dirs to $from |
347 | 347 | $remaining = \count($from) - $depth; |
348 | - if ($remaining > 1) { |
|
348 | + if ($remaining > 1){ |
|
349 | 349 | //Add traversals up to first matching directory |
350 | 350 | $padLength = (\count($relative) + $remaining - 1) * -1; |
351 | 351 | $relative = \array_pad($relative, $padLength, '..'); |
352 | 352 | break; |
353 | 353 | } |
354 | - $relative[0] = './' . $relative[0]; |
|
354 | + $relative[0] = './'.$relative[0]; |
|
355 | 355 | } |
356 | 356 | } |
357 | 357 | |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | private function filesIterator(string $location, string $pattern = null): \GlobIterator |
362 | 362 | { |
363 | 363 | $pattern ??= '*'; |
364 | - $regexp = \rtrim($location, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . \ltrim($pattern, DIRECTORY_SEPARATOR); |
|
364 | + $regexp = \rtrim($location, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.\ltrim($pattern, DIRECTORY_SEPARATOR); |
|
365 | 365 | |
366 | 366 | return new \GlobIterator($regexp); |
367 | 367 | } |
@@ -36,7 +36,8 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function __destruct() |
38 | 38 | { |
39 | - foreach ($this->destructFiles as $filename) { |
|
39 | + foreach ($this->destructFiles as $filename) |
|
40 | + { |
|
40 | 41 | $this->delete($filename); |
41 | 42 | } |
42 | 43 | } |
@@ -49,30 +50,36 @@ discard block |
||
49 | 50 | int $mode = null, |
50 | 51 | bool $recursivePermissions = true |
51 | 52 | ): bool { |
52 | - if (empty($mode)) { |
|
53 | + if (empty($mode)) |
|
54 | + { |
|
53 | 55 | $mode = self::DEFAULT_FILE_MODE; |
54 | 56 | } |
55 | 57 | |
56 | 58 | //Directories always executable |
57 | 59 | $mode |= 0o111; |
58 | - if (\is_dir($directory)) { |
|
60 | + if (\is_dir($directory)) |
|
61 | + { |
|
59 | 62 | //Exists :( |
60 | 63 | return $this->setPermissions($directory, $mode); |
61 | 64 | } |
62 | 65 | |
63 | - if (!$recursivePermissions) { |
|
66 | + if (!$recursivePermissions) |
|
67 | + { |
|
64 | 68 | return \mkdir($directory, $mode, true); |
65 | 69 | } |
66 | 70 | |
67 | 71 | $directoryChain = [\basename($directory)]; |
68 | 72 | |
69 | 73 | $baseDirectory = $directory; |
70 | - while (!\is_dir($baseDirectory = \dirname($baseDirectory))) { |
|
74 | + while (!\is_dir($baseDirectory = \dirname($baseDirectory))) |
|
75 | + { |
|
71 | 76 | $directoryChain[] = \basename($baseDirectory); |
72 | 77 | } |
73 | 78 | |
74 | - foreach (\array_reverse($directoryChain) as $dir) { |
|
75 | - if (!mkdir($baseDirectory = \sprintf('%s/%s', $baseDirectory, $dir))) { |
|
79 | + foreach (\array_reverse($directoryChain) as $dir) |
|
80 | + { |
|
81 | + if (!mkdir($baseDirectory = \sprintf('%s/%s', $baseDirectory, $dir))) |
|
82 | + { |
|
76 | 83 | return false; |
77 | 84 | } |
78 | 85 | |
@@ -84,7 +91,8 @@ discard block |
||
84 | 91 | |
85 | 92 | public function read(string $filename): string |
86 | 93 | { |
87 | - if (!$this->exists($filename)) { |
|
94 | + if (!$this->exists($filename)) |
|
95 | + { |
|
88 | 96 | throw new FileNotFoundException($filename); |
89 | 97 | } |
90 | 98 | |
@@ -103,12 +111,15 @@ discard block |
||
103 | 111 | ): bool { |
104 | 112 | $mode ??= self::DEFAULT_FILE_MODE; |
105 | 113 | |
106 | - try { |
|
107 | - if ($ensureDirectory) { |
|
114 | + try |
|
115 | + { |
|
116 | + if ($ensureDirectory) |
|
117 | + { |
|
108 | 118 | $this->ensureDirectory(\dirname($filename), $mode); |
109 | 119 | } |
110 | 120 | |
111 | - if ($this->exists($filename)) { |
|
121 | + if ($this->exists($filename)) |
|
122 | + { |
|
112 | 123 | //Forcing mode for existed file |
113 | 124 | $this->setPermissions($filename, $mode); |
114 | 125 | } |
@@ -119,11 +130,14 @@ discard block |
||
119 | 130 | $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
120 | 131 | ); |
121 | 132 | |
122 | - if ($result !== false) { |
|
133 | + if ($result !== false) |
|
134 | + { |
|
123 | 135 | //Forcing mode after file creation |
124 | 136 | $this->setPermissions($filename, $mode); |
125 | 137 | } |
126 | - } catch (\Exception $e) { |
|
138 | + } |
|
139 | + catch (\Exception $e) |
|
140 | + { |
|
127 | 141 | throw new WriteErrorException($e->getMessage(), (int) $e->getCode(), $e); |
128 | 142 | } |
129 | 143 | |
@@ -141,7 +155,8 @@ discard block |
||
141 | 155 | |
142 | 156 | public function delete(string $filename): bool |
143 | 157 | { |
144 | - if ($this->exists($filename)) { |
|
158 | + if ($this->exists($filename)) |
|
159 | + { |
|
145 | 160 | $result = \unlink($filename); |
146 | 161 | |
147 | 162 | //Wiping out changes in local file cache |
@@ -160,7 +175,8 @@ discard block |
||
160 | 175 | */ |
161 | 176 | public function deleteDirectory(string $directory, bool $contentOnly = false): bool |
162 | 177 | { |
163 | - if (!$this->isDirectory($directory)) { |
|
178 | + if (!$this->isDirectory($directory)) |
|
179 | + { |
|
164 | 180 | throw new FilesException(\sprintf('Undefined or invalid directory %s', $directory)); |
165 | 181 | } |
166 | 182 | |
@@ -169,15 +185,20 @@ discard block |
||
169 | 185 | \RecursiveIteratorIterator::CHILD_FIRST |
170 | 186 | ); |
171 | 187 | |
172 | - foreach ($files as $file) { |
|
173 | - if ($file->isDir()) { |
|
188 | + foreach ($files as $file) |
|
189 | + { |
|
190 | + if ($file->isDir()) |
|
191 | + { |
|
174 | 192 | \rmdir($file->getRealPath()); |
175 | - } else { |
|
193 | + } |
|
194 | + else |
|
195 | + { |
|
176 | 196 | $this->delete($file->getRealPath()); |
177 | 197 | } |
178 | 198 | } |
179 | 199 | |
180 | - if (!$contentOnly) { |
|
200 | + if (!$contentOnly) |
|
201 | + { |
|
181 | 202 | return \rmdir($directory); |
182 | 203 | } |
183 | 204 | |
@@ -186,7 +207,8 @@ discard block |
||
186 | 207 | |
187 | 208 | public function move(string $filename, string $destination): bool |
188 | 209 | { |
189 | - if (!$this->exists($filename)) { |
|
210 | + if (!$this->exists($filename)) |
|
211 | + { |
|
190 | 212 | throw new FileNotFoundException($filename); |
191 | 213 | } |
192 | 214 | |
@@ -195,7 +217,8 @@ discard block |
||
195 | 217 | |
196 | 218 | public function copy(string $filename, string $destination): bool |
197 | 219 | { |
198 | - if (!$this->exists($filename)) { |
|
220 | + if (!$this->exists($filename)) |
|
221 | + { |
|
199 | 222 | throw new FileNotFoundException($filename); |
200 | 223 | } |
201 | 224 | |
@@ -204,7 +227,8 @@ discard block |
||
204 | 227 | |
205 | 228 | public function touch(string $filename, int $mode = null): bool |
206 | 229 | { |
207 | - if (!\touch($filename)) { |
|
230 | + if (!\touch($filename)) |
|
231 | + { |
|
208 | 232 | return false; |
209 | 233 | } |
210 | 234 | |
@@ -218,7 +242,8 @@ discard block |
||
218 | 242 | |
219 | 243 | public function size(string $filename): int |
220 | 244 | { |
221 | - if (!$this->exists($filename)) { |
|
245 | + if (!$this->exists($filename)) |
|
246 | + { |
|
222 | 247 | throw new FileNotFoundException($filename); |
223 | 248 | } |
224 | 249 | |
@@ -232,7 +257,8 @@ discard block |
||
232 | 257 | |
233 | 258 | public function md5(string $filename): string |
234 | 259 | { |
235 | - if (!$this->exists($filename)) { |
|
260 | + if (!$this->exists($filename)) |
|
261 | + { |
|
236 | 262 | throw new FileNotFoundException($filename); |
237 | 263 | } |
238 | 264 | |
@@ -241,7 +267,8 @@ discard block |
||
241 | 267 | |
242 | 268 | public function time(string $filename): int |
243 | 269 | { |
244 | - if (!$this->exists($filename)) { |
|
270 | + if (!$this->exists($filename)) |
|
271 | + { |
|
245 | 272 | throw new FileNotFoundException($filename); |
246 | 273 | } |
247 | 274 | |
@@ -260,7 +287,8 @@ discard block |
||
260 | 287 | |
261 | 288 | public function getPermissions(string $filename): int |
262 | 289 | { |
263 | - if (!$this->exists($filename)) { |
|
290 | + if (!$this->exists($filename)) |
|
291 | + { |
|
264 | 292 | throw new FileNotFoundException($filename); |
265 | 293 | } |
266 | 294 | |
@@ -269,7 +297,8 @@ discard block |
||
269 | 297 | |
270 | 298 | public function setPermissions(string $filename, int $mode): bool |
271 | 299 | { |
272 | - if (\is_dir($filename)) { |
|
300 | + if (\is_dir($filename)) |
|
301 | + { |
|
273 | 302 | //Directories must always be executable (i.e. 664 for dir => 775) |
274 | 303 | $mode |= 0111; |
275 | 304 | } |
@@ -280,8 +309,10 @@ discard block |
||
280 | 309 | public function getFiles(string $location, string $pattern = null): array |
281 | 310 | { |
282 | 311 | $result = []; |
283 | - foreach ($this->filesIterator($location, $pattern) as $filename) { |
|
284 | - if ($this->isDirectory($filename->getPathname())) { |
|
312 | + foreach ($this->filesIterator($location, $pattern) as $filename) |
|
313 | + { |
|
314 | + if ($this->isDirectory($filename->getPathname())) |
|
315 | + { |
|
285 | 316 | $result = \array_merge($result, $this->getFiles($filename . DIRECTORY_SEPARATOR)); |
286 | 317 | |
287 | 318 | continue; |
@@ -295,13 +326,15 @@ discard block |
||
295 | 326 | |
296 | 327 | public function tempFilename(string $extension = '', string $location = null): string |
297 | 328 | { |
298 | - if (empty($location)) { |
|
329 | + if (empty($location)) |
|
330 | + { |
|
299 | 331 | $location = \sys_get_temp_dir(); |
300 | 332 | } |
301 | 333 | |
302 | 334 | $filename = \tempnam($location, 'spiral'); |
303 | 335 | |
304 | - if (!empty($extension)) { |
|
336 | + if (!empty($extension)) |
|
337 | + { |
|
305 | 338 | $old = $filename; |
306 | 339 | $filename = \sprintf('%s.%s', $filename, $extension); |
307 | 340 | \rename($old, $filename); |
@@ -314,7 +347,8 @@ discard block |
||
314 | 347 | public function normalizePath(string $path, bool $asDirectory = false): string |
315 | 348 | { |
316 | 349 | $isUnc = \str_starts_with($path, '\\\\') || \str_starts_with($path, '//'); |
317 | - if ($isUnc) { |
|
350 | + if ($isUnc) |
|
351 | + { |
|
318 | 352 | $leadingSlashes = \substr($path, 0, 2); |
319 | 353 | $path = \substr($path, 2); |
320 | 354 | } |
@@ -337,15 +371,20 @@ discard block |
||
337 | 371 | $path = \explode('/', $path); |
338 | 372 | $relative = $path; |
339 | 373 | |
340 | - foreach ($from as $depth => $dir) { |
|
374 | + foreach ($from as $depth => $dir) |
|
375 | + { |
|
341 | 376 | //Find first non-matching dir |
342 | - if ($dir === $path[$depth]) { |
|
377 | + if ($dir === $path[$depth]) |
|
378 | + { |
|
343 | 379 | //Ignore this directory |
344 | 380 | \array_shift($relative); |
345 | - } else { |
|
381 | + } |
|
382 | + else |
|
383 | + { |
|
346 | 384 | //Get number of remaining dirs to $from |
347 | 385 | $remaining = \count($from) - $depth; |
348 | - if ($remaining > 1) { |
|
386 | + if ($remaining > 1) |
|
387 | + { |
|
349 | 388 | //Add traversals up to first matching directory |
350 | 389 | $padLength = (\count($relative) + $remaining - 1) * -1; |
351 | 390 | $relative = \array_pad($relative, $padLength, '..'); |
@@ -23,7 +23,7 @@ |
||
23 | 23 | public const RUNTIME = 0666; |
24 | 24 | |
25 | 25 | //Only owner can write |
26 | - public const READONLY = 0644; |
|
26 | + public const readonly = 0644; |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * Few size constants for better size manipulations. |