Issues (26)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Filesystem.php (15 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace League\Flysystem;
4
5
use InvalidArgumentException;
6
use League\Flysystem\Adapter\CanOverwriteFiles;
7
use League\Flysystem\Plugin\PluggableTrait;
8
use League\Flysystem\Util\ContentListingFormatter;
9
10
/**
11
 * @method array getWithMetadata(string $path, array $metadata)
12
 * @method bool  forceCopy(string $path, string $newpath)
13
 * @method bool  forceRename(string $path, string $newpath)
14
 * @method array listFiles(string $path = '', boolean $recursive = false)
15
 * @method array listPaths(string $path = '', boolean $recursive = false)
16
 * @method array listWith(array $keys = [], $directory = '', $recursive = false)
17
 */
18
class Filesystem implements FilesystemInterface
19
{
20
    use PluggableTrait;
21
    use ConfigAwareTrait;
22
23
    /**
24
     * @var AdapterInterface
25
     */
26
    protected $adapter;
27
28
    /**
29
     * Constructor.
30
     *
31
     * @param AdapterInterface $adapter
32
     * @param Config|array     $config
33
     */
34 249
    public function __construct(AdapterInterface $adapter, $config = null)
35
    {
36 249
        $this->adapter = $adapter;
37 249
        $this->setConfig($config);
38 249
    }
39
40
    /**
41
     * Get the Adapter.
42
     *
43
     * @return AdapterInterface adapter
44
     */
45 213
    public function getAdapter()
46
    {
47 213
        return $this->adapter;
48
    }
49
50
    /**
51
     * @inheritdoc
52
     */
53 180
    public function has($path)
54
    {
55 180
        $path = Util::normalizePath($path);
56
57 180
        return strlen($path) === 0 ? false : (bool) $this->getAdapter()->has($path);
58
    }
59
60
    /**
61
     * @inheritdoc
62
     */
63 18 View Code Duplication
    public function write($path, $contents, array $config = [])
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65 18
        $path = Util::normalizePath($path);
66 18
        $this->assertAbsent($path);
67 15
        $config = $this->prepareConfig($config);
68
69 15
        return (bool) $this->getAdapter()->write($path, $contents, $config);
70
    }
71
72
    /**
73
     * @inheritdoc
74
     */
75 15 View Code Duplication
    public function writeStream($path, $resource, array $config = [])
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
    {
77 15
        if ( ! is_resource($resource)) {
78 6
            throw new InvalidArgumentException(__METHOD__ . ' expects argument #2 to be a valid resource.');
79
        }
80
81 9
        $path = Util::normalizePath($path);
82 9
        $this->assertAbsent($path);
83 9
        $config = $this->prepareConfig($config);
84
85 9
        Util::rewindStream($resource);
86
87 9
        return (bool) $this->getAdapter()->writeStream($path, $resource, $config);
88
    }
89
90
    /**
91
     * @inheritdoc
92
     */
93 12
    public function put($path, $contents, array $config = [])
94
    {
95 12
        $path = Util::normalizePath($path);
96 12
        $config = $this->prepareConfig($config);
97
98 12
        if ( ! $this->getAdapter() instanceof CanOverwriteFiles && $this->has($path)) {
99 6
            return (bool) $this->getAdapter()->update($path, $contents, $config);
100
        }
101
102 9
        return (bool) $this->getAdapter()->write($path, $contents, $config);
103
    }
104
105
    /**
106
     * @inheritdoc
107
     */
108 15
    public function putStream($path, $resource, array $config = [])
109
    {
110 15
        if ( ! is_resource($resource)) {
111 3
            throw new InvalidArgumentException(__METHOD__ . ' expects argument #2 to be a valid resource.');
112
        }
113
114 12
        $path = Util::normalizePath($path);
115 12
        $config = $this->prepareConfig($config);
116 12
        Util::rewindStream($resource);
117
118 12
        if ( ! $this->getAdapter() instanceof CanOverwriteFiles && $this->has($path)) {
119 6
            return (bool) $this->getAdapter()->updateStream($path, $resource, $config);
120
        }
121
122 9
        return (bool) $this->getAdapter()->writeStream($path, $resource, $config);
123
    }
124
125
    /**
126
     * @inheritdoc
127
     */
128 6
    public function readAndDelete($path)
129
    {
130 6
        $path = Util::normalizePath($path);
131 6
        $this->assertPresent($path);
132 6
        $contents = $this->read($path);
133
134 6
        if ($contents === false) {
135 3
            return false;
136
        }
137
138 3
        $this->delete($path);
139
140 3
        return $contents;
141
    }
142
143
    /**
144
     * @inheritdoc
145
     */
146 6 View Code Duplication
    public function update($path, $contents, array $config = [])
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
147
    {
148 6
        $path = Util::normalizePath($path);
149 6
        $config = $this->prepareConfig($config);
150
151 6
        $this->assertPresent($path);
152
153 6
        return (bool) $this->getAdapter()->update($path, $contents, $config);
154
    }
155
156
    /**
157
     * @inheritdoc
158
     */
159 15 View Code Duplication
    public function updateStream($path, $resource, array $config = [])
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
160
    {
161 15
        if ( ! is_resource($resource)) {
162 6
            throw new InvalidArgumentException(__METHOD__ . ' expects argument #2 to be a valid resource.');
163
        }
164
165 9
        $path = Util::normalizePath($path);
166 9
        $config = $this->prepareConfig($config);
167 9
        $this->assertPresent($path);
168 9
        Util::rewindStream($resource);
169
170 9
        return (bool) $this->getAdapter()->updateStream($path, $resource, $config);
171
    }
172
173
    /**
174
     * @inheritdoc
175
     */
176 36 View Code Duplication
    public function read($path)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
177
    {
178 36
        $path = Util::normalizePath($path);
179 36
        $this->assertPresent($path);
180
181 30
        if ( ! ($object = $this->getAdapter()->read($path))) {
182 3
            return false;
183
        }
184
185 27
        return $object['contents'];
186
    }
187
188
    /**
189
     * @inheritdoc
190
     */
191 12 View Code Duplication
    public function readStream($path)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
192
    {
193 12
        $path = Util::normalizePath($path);
194 12
        $this->assertPresent($path);
195
196 12
        if ( ! $object = $this->getAdapter()->readStream($path)) {
197 6
            return false;
198
        }
199
200 9
        return $object['stream'];
201
    }
202
203
    /**
204
     * @inheritdoc
205
     */
206 9 View Code Duplication
    public function rename($path, $newpath)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
207
    {
208 9
        $path = Util::normalizePath($path);
209 9
        $newpath = Util::normalizePath($newpath);
210 9
        $this->assertPresent($path);
211 9
        $this->assertAbsent($newpath);
212
213 9
        return (bool) $this->getAdapter()->rename($path, $newpath);
214
    }
215
216
    /**
217
     * @inheritdoc
218
     */
219 12 View Code Duplication
    public function copy($path, $newpath)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
220
    {
221 12
        $path = Util::normalizePath($path);
222 12
        $newpath = Util::normalizePath($newpath);
223 12
        $this->assertPresent($path);
224 12
        $this->assertAbsent($newpath);
225
226 12
        return $this->getAdapter()->copy($path, $newpath);
227
    }
228
229
    /**
230
     * @inheritdoc
231
     */
232 60
    public function delete($path)
233
    {
234 60
        $path = Util::normalizePath($path);
235 60
        $this->assertPresent($path);
236
237 57
        return $this->getAdapter()->delete($path);
238
    }
239
240
    /**
241
     * @inheritdoc
242
     */
243 66
    public function deleteDir($dirname)
244
    {
245 66
        $dirname = Util::normalizePath($dirname);
246
247 66
        if ($dirname === '') {
248 3
            throw new RootViolationException('Root directories can not be deleted.');
249
        }
250
251 63
        return (bool) $this->getAdapter()->deleteDir($dirname);
252
    }
253
254
    /**
255
     * @inheritdoc
256
     */
257 3 View Code Duplication
    public function createDir($dirname, array $config = [])
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
258
    {
259 3
        $dirname = Util::normalizePath($dirname);
260 3
        $config = $this->prepareConfig($config);
261
262 3
        return (bool) $this->getAdapter()->createDir($dirname, $config);
263
    }
264
265
    /**
266
     * @inheritdoc
267
     */
268 15
    public function listContents($directory = '', $recursive = false)
269
    {
270 15
        $directory = Util::normalizePath($directory);
271 15
        $contents = $this->getAdapter()->listContents($directory, $recursive);
272
273 15
        return (new ContentListingFormatter($directory, $recursive, $this->config->get('case_sensitive', true)))
274 15
            ->formatListing($contents);
275
    }
276
277
    /**
278
     * @inheritdoc
279
     */
280 9 View Code Duplication
    public function getMimetype($path)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
281
    {
282 9
        $path = Util::normalizePath($path);
283 9
        $this->assertPresent($path);
284
285 9
        if (( ! $object = $this->getAdapter()->getMimetype($path)) || ! array_key_exists('mimetype', $object)) {
286 3
            return false;
287
        }
288
289 6
        return $object['mimetype'];
290
    }
291
292
    /**
293
     * @inheritdoc
294
     */
295 9 View Code Duplication
    public function getTimestamp($path)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
296
    {
297 9
        $path = Util::normalizePath($path);
298 9
        $this->assertPresent($path);
299
300 9
        if (( ! $object = $this->getAdapter()->getTimestamp($path)) || ! array_key_exists('timestamp', $object)) {
301 3
            return false;
302
        }
303
304 6
        return $object['timestamp'];
305
    }
306
307
    /**
308
     * @inheritdoc
309
     */
310 9 View Code Duplication
    public function getVisibility($path)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
311
    {
312 9
        $path = Util::normalizePath($path);
313 9
        $this->assertPresent($path);
314
315 9
        if (( ! $object = $this->getAdapter()->getVisibility($path)) || ! array_key_exists('visibility', $object)) {
316 3
            return false;
317
        }
318
319 6
        return $object['visibility'];
320
    }
321
322
    /**
323
     * @inheritdoc
324
     */
325 12 View Code Duplication
    public function getSize($path)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
326
    {
327 12
        $path = Util::normalizePath($path);
328 12
        $this->assertPresent($path);
329
330 9
        if (( ! $object = $this->getAdapter()->getSize($path)) || ! array_key_exists('size', $object)) {
331 3
            return false;
332
        }
333
334 6
        return (int) $object['size'];
335
    }
336
337
    /**
338
     * @inheritdoc
339
     */
340 9
    public function setVisibility($path, $visibility)
341
    {
342 9
        $path = Util::normalizePath($path);
343 9
        $this->assertPresent($path);
344
345 6
        return (bool) $this->getAdapter()->setVisibility($path, $visibility);
346
    }
347
348
    /**
349
     * @inheritdoc
350
     */
351 51
    public function getMetadata($path)
352
    {
353 51
        $path = Util::normalizePath($path);
354 51
        $this->assertPresent($path);
355
356 51
        return $this->getAdapter()->getMetadata($path);
357
    }
358
359
    /**
360
     * @inheritdoc
361
     */
362 69
    public function get($path, Handler $handler = null)
363
    {
364 69
        $path = Util::normalizePath($path);
365
366 69
        if ( ! $handler) {
367 45
            $metadata = $this->getMetadata($path);
368 45
            $handler = $metadata['type'] === 'file' ? new File($this, $path) : new Directory($this, $path);
0 ignored issues
show
Deprecated Code introduced by Frank de Jonge
The class League\Flysystem\File has been deprecated.

This class, trait or interface has been deprecated.

Loading history...
Deprecated Code introduced by Frank de Jonge
The class League\Flysystem\Directory has been deprecated.

This class, trait or interface has been deprecated.

Loading history...
369 15
        }
370
371 69
        $handler->setPath($path);
372 69
        $handler->setFilesystem($this);
373
374 69
        return $handler;
375
    }
376
377
    /**
378
     * Assert a file is present.
379
     *
380
     * @param string $path path to file
381
     *
382
     * @throws FileNotFoundException
383
     *
384
     * @return void
385
     */
386 147
    public function assertPresent($path)
387
    {
388 147
        if ($this->config->get('disable_asserts', false) === false && ! $this->has($path)) {
389 18
            throw new FileNotFoundException($path);
390
        }
391 135
    }
392
393
    /**
394
     * Assert a file is absent.
395
     *
396
     * @param string $path path to file
397
     *
398
     * @throws FileExistsException
399
     *
400
     * @return void
401
     */
402 48
    public function assertAbsent($path)
403
    {
404 48
        if ($this->config->get('disable_asserts', false) === false && $this->has($path)) {
405 3
            throw new FileExistsException($path);
406
        }
407 45
    }
408
}
409