@@ -43,13 +43,13 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public static function factory($path) : JSONFile |
45 | 45 | { |
46 | - if($path instanceof self) { |
|
46 | + if ($path instanceof self) { |
|
47 | 47 | return $path; |
48 | 48 | } |
49 | 49 | |
50 | 50 | $instance = self::createInstance($path); |
51 | 51 | |
52 | - if($instance instanceof self) { |
|
52 | + if ($instance instanceof self) { |
|
53 | 53 | return $instance; |
54 | 54 | } |
55 | 55 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | |
129 | 129 | private function convertEncoding(string $contents) : string |
130 | 130 | { |
131 | - if(!empty($this->targetEncoding)) |
|
131 | + if (!empty($this->targetEncoding)) |
|
132 | 132 | { |
133 | 133 | return (string)mb_convert_encoding( |
134 | 134 | $contents, |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | { |
151 | 151 | $options = null; |
152 | 152 | |
153 | - if($pretty) |
|
153 | + if ($pretty) |
|
154 | 154 | { |
155 | 155 | $options = JSON_PRETTY_PRINT; |
156 | 156 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | |
97 | 97 | $path = realpath($this->path); |
98 | 98 | |
99 | - if($path !== false) |
|
99 | + if ($path !== false) |
|
100 | 100 | { |
101 | 101 | return FileHelper::normalizePath($path); |
102 | 102 | } |
@@ -115,14 +115,14 @@ discard block |
||
115 | 115 | * @return $this |
116 | 116 | * @throws FileHelper_Exception |
117 | 117 | */ |
118 | - private function requireTrue(bool $condition, string $conditionLabel, ?int $errorCode=null) : self |
|
118 | + private function requireTrue(bool $condition, string $conditionLabel, ?int $errorCode = null) : self |
|
119 | 119 | { |
120 | - if($condition === true) |
|
120 | + if ($condition === true) |
|
121 | 121 | { |
122 | 122 | return $this; |
123 | 123 | } |
124 | 124 | |
125 | - if($errorCode === null) |
|
125 | + if ($errorCode === null) |
|
126 | 126 | { |
127 | 127 | $errorCode = FileHelper::ERROR_FILE_DOES_NOT_EXIST; |
128 | 128 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * @return $this |
140 | 140 | * @throws FileHelper_Exception |
141 | 141 | */ |
142 | - public function requireExists(?int $errorCode=null) : self |
|
142 | + public function requireExists(?int $errorCode = null) : self |
|
143 | 143 | { |
144 | 144 | return $this->requireTrue( |
145 | 145 | !empty($this->path) && realpath($this->path) !== false, |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @return $this |
154 | 154 | * @throws FileHelper_Exception |
155 | 155 | */ |
156 | - public function requireReadable(?int $errorCode=null) : self |
|
156 | + public function requireReadable(?int $errorCode = null) : self |
|
157 | 157 | { |
158 | 158 | $this->requireExists($errorCode); |
159 | 159 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | * @return $this |
170 | 170 | * @throws FileHelper_Exception |
171 | 171 | */ |
172 | - public function requireWritable(?int $errorCode=null) : self |
|
172 | + public function requireWritable(?int $errorCode = null) : self |
|
173 | 173 | { |
174 | 174 | return $this->requireTrue( |
175 | 175 | $this->isWritable(), |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | */ |
187 | 187 | public function requireIsFile() : FileInfo |
188 | 188 | { |
189 | - if($this instanceof FileInfo) |
|
189 | + if ($this instanceof FileInfo) |
|
190 | 190 | { |
191 | 191 | return $this; |
192 | 192 | } |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | public function requireIsFolder() : FolderInfo |
211 | 211 | { |
212 | - if($this instanceof FolderInfo) |
|
212 | + if ($this instanceof FolderInfo) |
|
213 | 213 | { |
214 | 214 | return $this; |
215 | 215 | } |
@@ -230,12 +230,12 @@ discard block |
||
230 | 230 | */ |
231 | 231 | public static function type2string($path) : string |
232 | 232 | { |
233 | - if($path instanceof PathInfoInterface) |
|
233 | + if ($path instanceof PathInfoInterface) |
|
234 | 234 | { |
235 | 235 | return $path->getPath(); |
236 | 236 | } |
237 | 237 | |
238 | - if($path instanceof SplFileInfo) |
|
238 | + if ($path instanceof SplFileInfo) |
|
239 | 239 | { |
240 | 240 | return $path->getPathname(); |
241 | 241 | } |
@@ -257,19 +257,19 @@ discard block |
||
257 | 257 | */ |
258 | 258 | public static function resolveType($path) : PathInfoInterface |
259 | 259 | { |
260 | - if($path instanceof PathInfoInterface) |
|
260 | + if ($path instanceof PathInfoInterface) |
|
261 | 261 | { |
262 | 262 | return $path; |
263 | 263 | } |
264 | 264 | |
265 | 265 | $path = self::type2string($path); |
266 | 266 | |
267 | - if(FolderInfo::is_dir($path)) |
|
267 | + if (FolderInfo::is_dir($path)) |
|
268 | 268 | { |
269 | 269 | return FolderInfo::factory($path); |
270 | 270 | } |
271 | 271 | |
272 | - if(FileInfo::is_file($path)) |
|
272 | + if (FileInfo::is_file($path)) |
|
273 | 273 | { |
274 | 274 | return FileInfo::factory($path); |
275 | 275 | } |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | public function getModifiedDate() : ?DateTime |
328 | 328 | { |
329 | 329 | $time = filemtime($this->getPath()); |
330 | - if($time === false) { |
|
330 | + if ($time === false) { |
|
331 | 331 | return null; |
332 | 332 | } |
333 | 333 |
@@ -112,25 +112,25 @@ |
||
112 | 112 | |
113 | 113 | $result = array(); |
114 | 114 | preg_match_all('/namespace\s+([^;]+);/ix', $code, $result, PREG_PATTERN_ORDER); |
115 | - if(isset($result[0][0])) { |
|
115 | + if (isset($result[0][0])) { |
|
116 | 116 | $this->namespace = trim($result[1][0]); |
117 | 117 | } |
118 | 118 | |
119 | 119 | $result = array(); |
120 | 120 | preg_match_all('/(abstract|final)\s+(class|trait)\s+([\sa-z\d\\\\_,]+){|(class|trait)\s+([\sa-z\d\\\\_,]+){/ix', $code, $result, PREG_PATTERN_ORDER); |
121 | 121 | |
122 | - if(!isset($result[0][0])) { |
|
122 | + if (!isset($result[0][0])) { |
|
123 | 123 | return; |
124 | 124 | } |
125 | 125 | |
126 | 126 | $indexes = array_keys($result[0]); |
127 | 127 | |
128 | - foreach($indexes as $idx) |
|
128 | + foreach ($indexes as $idx) |
|
129 | 129 | { |
130 | 130 | $keyword = $result[1][$idx]; |
131 | 131 | $declaration = $result[3][$idx]; |
132 | 132 | $type = $result[2][$idx]; |
133 | - if(empty($keyword)) { |
|
133 | + if (empty($keyword)) { |
|
134 | 134 | $type = $result[4][$idx]; |
135 | 135 | $declaration = $result[5][$idx]; |
136 | 136 | } |
@@ -24,7 +24,7 @@ |
||
24 | 24 | interface PathInfoInterface |
25 | 25 | { |
26 | 26 | public function getName() : string; |
27 | - public function getExtension(bool $lowercase=true) : string; |
|
27 | + public function getExtension(bool $lowercase = true) : string; |
|
28 | 28 | public function getPath() : string; |
29 | 29 | public function getFolderPath() : string; |
30 | 30 | public function exists() : bool; |
@@ -32,13 +32,13 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public static function factory($path) : SerializedFile |
34 | 34 | { |
35 | - if($path instanceof self) { |
|
35 | + if ($path instanceof self) { |
|
36 | 36 | return $path; |
37 | 37 | } |
38 | 38 | |
39 | 39 | $instance = self::createInstance($path); |
40 | 40 | |
41 | - if($instance instanceof self) { |
|
41 | + if ($instance instanceof self) { |
|
42 | 42 | return $instance; |
43 | 43 | } |
44 | 44 | |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | ) |
74 | 74 | ); |
75 | 75 | |
76 | - if($result !== false) { |
|
76 | + if ($result !== false) { |
|
77 | 77 | return $result; |
78 | 78 | } |
79 | 79 |
@@ -32,13 +32,13 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public static function factory($path) : PHPFile |
34 | 34 | { |
35 | - if($path instanceof self) { |
|
35 | + if ($path instanceof self) { |
|
36 | 36 | return $path; |
37 | 37 | } |
38 | 38 | |
39 | 39 | $instance = self::createInstance($path); |
40 | 40 | |
41 | - if($instance instanceof self) { |
|
41 | + if ($instance instanceof self) { |
|
42 | 42 | return $instance; |
43 | 43 | } |
44 | 44 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function checkSyntax() |
61 | 61 | { |
62 | - if(!FileHelper::canMakePHPCalls()) |
|
62 | + if (!FileHelper::canMakePHPCalls()) |
|
63 | 63 | { |
64 | 64 | return true; |
65 | 65 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | // when the validation is successful, the first entry |
72 | 72 | // in the array contains the success message. When it |
73 | 73 | // is invalid, the first entry is always empty. |
74 | - if(!empty($output[0])) { |
|
74 | + if (!empty($output[0])) { |
|
75 | 75 | return true; |
76 | 76 | } |
77 | 77 |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | { |
31 | 31 | $pathString = AbstractPathInfo::type2string($path); |
32 | 32 | |
33 | - if(!isset(self::$infoCache[$pathString])) |
|
33 | + if (!isset(self::$infoCache[$pathString])) |
|
34 | 34 | { |
35 | 35 | self::$infoCache[$pathString] = new FolderInfo($pathString); |
36 | 36 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | { |
60 | 60 | parent::__construct($path); |
61 | 61 | |
62 | - if(!self::is_dir($this->path)) |
|
62 | + if (!self::is_dir($this->path)) |
|
63 | 63 | { |
64 | 64 | throw new FileHelper_Exception( |
65 | 65 | 'Not a folder', |
@@ -81,12 +81,12 @@ discard block |
||
81 | 81 | { |
82 | 82 | $path = trim($path); |
83 | 83 | |
84 | - if($path === '' || $path === '.' || $path === '..') |
|
84 | + if ($path === '' || $path === '.' || $path === '..') |
|
85 | 85 | { |
86 | 86 | return false; |
87 | 87 | } |
88 | 88 | |
89 | - if(is_dir($path)) |
|
89 | + if (is_dir($path)) |
|
90 | 90 | { |
91 | 91 | return true; |
92 | 92 | } |
@@ -104,12 +104,12 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function delete() : FolderInfo |
106 | 106 | { |
107 | - if(!$this->exists()) |
|
107 | + if (!$this->exists()) |
|
108 | 108 | { |
109 | 109 | return $this; |
110 | 110 | } |
111 | 111 | |
112 | - if(rmdir($this->path)) |
|
112 | + if (rmdir($this->path)) |
|
113 | 113 | { |
114 | 114 | return $this; |
115 | 115 | } |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | */ |
136 | 136 | public function create() : FolderInfo |
137 | 137 | { |
138 | - if(is_dir($this->path) || mkdir($this->path, 0777, true) || is_dir($this->path)) |
|
138 | + if (is_dir($this->path) || mkdir($this->path, 0777, true) || is_dir($this->path)) |
|
139 | 139 | { |
140 | 140 | return $this; |
141 | 141 | } |
@@ -185,12 +185,12 @@ discard block |
||
185 | 185 | return FileHelper::createFolder($this->getPath().'/'.$name); |
186 | 186 | } |
187 | 187 | |
188 | - public function saveFile(string $fileName, string $content='') : FileInfo |
|
188 | + public function saveFile(string $fileName, string $content = '') : FileInfo |
|
189 | 189 | { |
190 | 190 | return FileHelper::saveFile($this.'/'.$fileName, $content); |
191 | 191 | } |
192 | 192 | |
193 | - public function saveJSONFile(array $data, string $fileName, bool $pretty=false) : JSONFile |
|
193 | + public function saveJSONFile(array $data, string $fileName, bool $pretty = false) : JSONFile |
|
194 | 194 | { |
195 | 195 | return FileHelper::saveAsJSON($data, $this.'/'.$fileName, $pretty); |
196 | 196 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public static function factory($path) : FileInfo |
52 | 52 | { |
53 | - if($path instanceof self) { |
|
53 | + if ($path instanceof self) { |
|
54 | 54 | return $path; |
55 | 55 | } |
56 | 56 | |
@@ -67,12 +67,12 @@ discard block |
||
67 | 67 | $pathString = AbstractPathInfo::type2string($path); |
68 | 68 | $key = $pathString.';'.static::class; |
69 | 69 | |
70 | - if(!isset(self::$infoCache[$key])) |
|
70 | + if (!isset(self::$infoCache[$key])) |
|
71 | 71 | { |
72 | 72 | $class = static::class; |
73 | 73 | $instance = new $class($pathString); |
74 | 74 | |
75 | - if(!$instance instanceof self) { |
|
75 | + if (!$instance instanceof self) { |
|
76 | 76 | throw new FileHelper_Exception( |
77 | 77 | 'Invalid class' |
78 | 78 | ); |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | { |
107 | 107 | parent::__construct($path); |
108 | 108 | |
109 | - if(!self::is_file($this->path)) |
|
109 | + if (!self::is_file($this->path)) |
|
110 | 110 | { |
111 | 111 | throw new FileHelper_Exception( |
112 | 112 | 'Not a file path', |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | { |
121 | 121 | $path = trim($path); |
122 | 122 | |
123 | - if(empty($path)) |
|
123 | + if (empty($path)) |
|
124 | 124 | { |
125 | 125 | return false; |
126 | 126 | } |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | return is_file($path) || pathinfo($path, PATHINFO_EXTENSION) !== ''; |
129 | 129 | } |
130 | 130 | |
131 | - public function removeExtension(bool $keepPath=false) : string |
|
131 | + public function removeExtension(bool $keepPath = false) : string |
|
132 | 132 | { |
133 | - if(!$keepPath) |
|
133 | + if (!$keepPath) |
|
134 | 134 | { |
135 | 135 | return (string)pathinfo($this->getName(), PATHINFO_FILENAME); |
136 | 136 | } |
@@ -144,11 +144,11 @@ discard block |
||
144 | 144 | return implode('/', $parts); |
145 | 145 | } |
146 | 146 | |
147 | - public function getExtension(bool $lowercase=true) : string |
|
147 | + public function getExtension(bool $lowercase = true) : string |
|
148 | 148 | { |
149 | 149 | $ext = (string)pathinfo($this->path, PATHINFO_EXTENSION); |
150 | 150 | |
151 | - if($lowercase) |
|
151 | + if ($lowercase) |
|
152 | 152 | { |
153 | 153 | $ext = mb_strtolower($ext); |
154 | 154 | } |
@@ -169,12 +169,12 @@ discard block |
||
169 | 169 | */ |
170 | 170 | public function delete() : FileInfo |
171 | 171 | { |
172 | - if(!$this->exists()) |
|
172 | + if (!$this->exists()) |
|
173 | 173 | { |
174 | 174 | return $this; |
175 | 175 | } |
176 | 176 | |
177 | - if(unlink($this->path)) |
|
177 | + if (unlink($this->path)) |
|
178 | 178 | { |
179 | 179 | return $this; |
180 | 180 | } |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | { |
202 | 202 | $target = $this->checkCopyPrerequisites($targetPath); |
203 | 203 | |
204 | - if(copy($this->path, (string)$target)) |
|
204 | + if (copy($this->path, (string)$target)) |
|
205 | 205 | { |
206 | 206 | return $target; |
207 | 207 | } |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | */ |
254 | 254 | public function getLineReader() : LineReader |
255 | 255 | { |
256 | - if($this->lineReader === null) |
|
256 | + if ($this->lineReader === null) |
|
257 | 257 | { |
258 | 258 | $this->lineReader = new LineReader($this); |
259 | 259 | } |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | |
273 | 273 | $result = file_get_contents($this->getPath()); |
274 | 274 | |
275 | - if($result !== false) { |
|
275 | + if ($result !== false) { |
|
276 | 276 | return $result; |
277 | 277 | } |
278 | 278 | |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | */ |
295 | 295 | public function putContents(string $content) : FileInfo |
296 | 296 | { |
297 | - if($this->exists()) |
|
297 | + if ($this->exists()) |
|
298 | 298 | { |
299 | 299 | $this->requireWritable(); |
300 | 300 | } |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | ->requireWritable(); |
306 | 306 | } |
307 | 307 | |
308 | - if(file_put_contents($this->path, $content) !== false) |
|
308 | + if (file_put_contents($this->path, $content) !== false) |
|
309 | 309 | { |
310 | 310 | return $this; |
311 | 311 | } |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | */ |
336 | 336 | private function createFolder() : FileInfo |
337 | 337 | { |
338 | - if(!$this->exists()) |
|
338 | + if (!$this->exists()) |
|
339 | 339 | { |
340 | 340 | FolderInfo::factory($this->getFolderPath()) |
341 | 341 | ->create() |