Total Complexity | 45 |
Total Lines | 270 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Complex classes like ForwardsIlluminateFilesystem often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ForwardsIlluminateFilesystem, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
14 | trait ForwardsIlluminateFilesystem |
||
15 | { |
||
16 | /** @inheritDoc */ |
||
17 | public static function exists(string $path): bool |
||
18 | { |
||
19 | return self::filesystem()->exists(self::absolutePath($path)); |
||
|
|||
20 | } |
||
21 | |||
22 | /** @inheritDoc */ |
||
23 | public static function missing(string $path): bool |
||
24 | { |
||
25 | return self::filesystem()->missing(self::absolutePath($path)); |
||
26 | } |
||
27 | |||
28 | /** @inheritDoc */ |
||
29 | public static function get(string $path, bool $lock = false): string |
||
30 | { |
||
31 | return self::filesystem()->get(self::absolutePath($path), $lock); |
||
32 | } |
||
33 | |||
34 | /** @inheritDoc */ |
||
35 | public static function sharedGet(string $path): string |
||
36 | { |
||
37 | return self::filesystem()->sharedGet(self::absolutePath($path)); |
||
38 | } |
||
39 | |||
40 | /** @inheritDoc */ |
||
41 | public static function getRequire(string $path, array $data = []): mixed |
||
42 | { |
||
43 | return self::filesystem()->getRequire(self::absolutePath($path), $data); |
||
44 | } |
||
45 | |||
46 | /** @inheritDoc */ |
||
47 | public static function requireOnce(string $path, array $data = []): mixed |
||
48 | { |
||
49 | return self::filesystem()->requireOnce(self::absolutePath($path), $data); |
||
50 | } |
||
51 | |||
52 | /** @inheritDoc */ |
||
53 | public static function lines(string $path): \Illuminate\Support\LazyCollection |
||
54 | { |
||
55 | return self::filesystem()->lines(self::absolutePath($path)); |
||
56 | } |
||
57 | |||
58 | /** @inheritDoc */ |
||
59 | public static function hash(string $path, string $algorithm = 'md5'): string |
||
60 | { |
||
61 | return self::filesystem()->hash(self::absolutePath($path), $algorithm); |
||
62 | } |
||
63 | |||
64 | /** @inheritDoc */ |
||
65 | public static function put(string $path, string $contents, bool $lock = false): bool|int |
||
66 | { |
||
67 | return self::filesystem()->put(self::absolutePath($path), $contents, $lock); |
||
68 | } |
||
69 | |||
70 | /** @inheritDoc */ |
||
71 | public static function replace(string $path, string $content): void |
||
72 | { |
||
73 | self::filesystem()->replace(self::absolutePath($path), $content); |
||
74 | } |
||
75 | |||
76 | /** @inheritDoc */ |
||
77 | public static function replaceInFile(array|string $search, array|string $replace, string $path): void |
||
78 | { |
||
79 | self::filesystem()->replaceInFile($search, $replace, self::absolutePath($path)); |
||
80 | } |
||
81 | |||
82 | /** @inheritDoc */ |
||
83 | public static function prepend(string $path, string $data): int |
||
84 | { |
||
85 | return self::filesystem()->prepend(self::absolutePath($path), $data); |
||
86 | } |
||
87 | |||
88 | /** @inheritDoc */ |
||
89 | public static function append(string $path, string $data): int |
||
90 | { |
||
91 | return self::filesystem()->append(self::absolutePath($path), $data); |
||
92 | } |
||
93 | |||
94 | /** @inheritDoc */ |
||
95 | public static function chmod(string $path, int $mode = null): mixed |
||
96 | { |
||
97 | return self::filesystem()->chmod(self::absolutePath($path), $mode); |
||
98 | } |
||
99 | |||
100 | /** @inheritDoc */ |
||
101 | public static function delete(array|string $paths): bool |
||
102 | { |
||
103 | return self::filesystem()->delete(self::qualifyPossiblePathArray($paths)); |
||
104 | } |
||
105 | |||
106 | /** @inheritDoc */ |
||
107 | public static function move(string $path, string $target): bool |
||
108 | { |
||
109 | return self::filesystem()->move(self::absolutePath($path), self::absolutePath($target)); |
||
110 | } |
||
111 | |||
112 | /** @inheritDoc */ |
||
113 | public static function copy(string $path, string $target): bool |
||
114 | { |
||
115 | return self::filesystem()->copy(self::absolutePath($path), self::absolutePath($target)); |
||
116 | } |
||
117 | |||
118 | /** @inheritDoc */ |
||
119 | public static function link(string $target, string $link): void |
||
120 | { |
||
121 | self::filesystem()->link(self::absolutePath($target), self::absolutePath($link)); |
||
122 | } |
||
123 | |||
124 | /** @inheritDoc */ |
||
125 | public static function relativeLink(string $target, string $link): void |
||
126 | { |
||
127 | self::filesystem()->relativeLink(self::absolutePath($target), self::absolutePath($link)); |
||
128 | } |
||
129 | |||
130 | /** @inheritDoc */ |
||
131 | public static function name(string $path): string |
||
132 | { |
||
133 | return self::filesystem()->name(self::absolutePath($path)); |
||
134 | } |
||
135 | |||
136 | /** @inheritDoc */ |
||
137 | public static function basename(string $path): string |
||
138 | { |
||
139 | return self::filesystem()->basename(self::absolutePath($path)); |
||
140 | } |
||
141 | |||
142 | /** @inheritDoc */ |
||
143 | public static function dirname(string $path): string |
||
144 | { |
||
145 | return self::filesystem()->dirname(self::absolutePath($path)); |
||
146 | } |
||
147 | |||
148 | /** @inheritDoc */ |
||
149 | public static function extension(string $path): string |
||
150 | { |
||
151 | return self::filesystem()->extension(self::absolutePath($path)); |
||
152 | } |
||
153 | |||
154 | /** @inheritDoc */ |
||
155 | public static function guessExtension(string $path): ?string |
||
156 | { |
||
157 | return self::filesystem()->guessExtension(self::absolutePath($path)); |
||
158 | } |
||
159 | |||
160 | /** @inheritDoc */ |
||
161 | public static function type(string $path): string |
||
162 | { |
||
163 | return self::filesystem()->type(self::absolutePath($path)); |
||
164 | } |
||
165 | |||
166 | /** @inheritDoc */ |
||
167 | public static function mimeType(string $path): bool|string |
||
168 | { |
||
169 | return self::filesystem()->mimeType(self::absolutePath($path)); |
||
170 | } |
||
171 | |||
172 | /** @inheritDoc */ |
||
173 | public static function size(string $path): int |
||
174 | { |
||
175 | return self::filesystem()->size(self::absolutePath($path)); |
||
176 | } |
||
177 | |||
178 | /** @inheritDoc */ |
||
179 | public static function lastModified(string $path): int |
||
180 | { |
||
181 | return self::filesystem()->lastModified(self::absolutePath($path)); |
||
182 | } |
||
183 | |||
184 | /** @inheritDoc */ |
||
185 | public static function isDirectory(string $directory): bool |
||
186 | { |
||
187 | return self::filesystem()->isDirectory(self::absolutePath($directory)); |
||
188 | } |
||
189 | |||
190 | /** @inheritDoc */ |
||
191 | public static function isEmptyDirectory(string $directory, bool $ignoreDotFiles = false): bool |
||
192 | { |
||
193 | return self::filesystem()->isEmptyDirectory(self::absolutePath($directory), $ignoreDotFiles); |
||
194 | } |
||
195 | |||
196 | /** @inheritDoc */ |
||
197 | public static function isReadable(string $path): bool |
||
198 | { |
||
199 | return self::filesystem()->isReadable(self::absolutePath($path)); |
||
200 | } |
||
201 | |||
202 | /** @inheritDoc */ |
||
203 | public static function isWritable(string $path): bool |
||
204 | { |
||
205 | return self::filesystem()->isWritable(self::absolutePath($path)); |
||
206 | } |
||
207 | |||
208 | /** @inheritDoc */ |
||
209 | public static function hasSameHash(string $firstFile, string $secondFile): bool |
||
210 | { |
||
211 | return self::filesystem()->hasSameHash(self::absolutePath($firstFile), self::absolutePath($secondFile)); |
||
212 | } |
||
213 | |||
214 | /** @inheritDoc */ |
||
215 | public static function isFile(string $file): bool |
||
218 | } |
||
219 | |||
220 | /** @inheritDoc */ |
||
221 | public static function glob(string $pattern, int $flags = 0): array |
||
222 | { |
||
223 | return self::filesystem()->glob(self::absolutePath($pattern), $flags); |
||
224 | } |
||
225 | |||
226 | /** @inheritDoc */ |
||
227 | public static function files(string $directory, bool $hidden = false): array |
||
228 | { |
||
229 | return self::filesystem()->files(self::absolutePath($directory), $hidden); |
||
230 | } |
||
231 | |||
232 | /** @inheritDoc */ |
||
233 | public static function allFiles(string $directory, bool $hidden = false): array |
||
234 | { |
||
235 | return self::filesystem()->allFiles(self::absolutePath($directory), $hidden); |
||
236 | } |
||
237 | |||
238 | /** @inheritDoc*/ |
||
239 | public static function directories(string $directory): array |
||
240 | { |
||
241 | return self::filesystem()->directories(self::absolutePath($directory)); |
||
242 | } |
||
243 | |||
244 | /** @inheritDoc */ |
||
245 | public static function ensureDirectoryExists(string $path, int $mode = 0755, bool $recursive = true): void |
||
248 | } |
||
249 | |||
250 | /** @inheritDoc */ |
||
251 | public static function makeDirectory(string $path, int $mode = 0755, bool $recursive = false, bool $force = false): bool |
||
252 | { |
||
253 | return self::filesystem()->makeDirectory(self::absolutePath($path), $mode, $recursive, $force); |
||
254 | } |
||
255 | |||
256 | /** @inheritDoc */ |
||
257 | public static function moveDirectory(string $from, string $to, bool $overwrite = false): bool |
||
258 | { |
||
259 | return self::filesystem()->moveDirectory(self::absolutePath($from), self::absolutePath($to), $overwrite); |
||
260 | } |
||
261 | |||
262 | /** @inheritDoc */ |
||
263 | public static function copyDirectory(string $directory, string $destination, ?int $options = null): bool |
||
266 | } |
||
267 | |||
268 | /** @inheritDoc */ |
||
269 | public static function deleteDirectory(string $directory, bool $preserve = false): bool |
||
272 | } |
||
273 | |||
274 | /** @inheritDoc */ |
||
275 | public static function deleteDirectories(string $directory): bool |
||
276 | { |
||
277 | return self::filesystem()->deleteDirectories(self::absolutePath($directory)); |
||
278 | } |
||
279 | |||
280 | /** @inheritDoc */ |
||
281 | public static function cleanDirectory(string $directory): bool |
||
282 | { |
||
283 | return self::filesystem()->cleanDirectory(self::absolutePath($directory)); |
||
284 | } |
||
285 | } |
||
286 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.