GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

FileDisk   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 81
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A putFileAs() 0 18 3
A getUrl() 0 14 3
A getLocalUrl() 0 22 3
1
<?php
2
3
namespace Nip\Filesystem;
4
5
use League\Flysystem\Adapter\Local as LocalAdapter;
6
use League\Flysystem\Filesystem as Flysystem;
7
use Nip\Utility\Str;
8
use RuntimeException;
9
use Symfony\Component\HttpFoundation\File\UploadedFile;
10
11
//use League\Flysystem\AwsS3v3\AwsS3Adapter;
12
13
/**
14
 * Class FlysystemAdapter
15
 * @package Nip\Filesystem
16
 */
17
class FileDisk extends Flysystem
18
{
19
20
    /**
21
     * Store the uploaded file on the disk with a given name.
22
     *
23
     * @param  string $path
24
     * @param  UploadedFile $file
25
     * @param  string $name
26
     * @param  array $options
27
     * @return string|false
28
     */
29
    public function putFileAs($path, $file, $name, $options = [])
30
    {
31
        $stream = fopen($file->getRealPath(), 'r+');
32
33
        // Next, we will format the path of the file and store the file using a stream since
34
        // they provide better performance than alternatives. Once we write the file this
35
        // stream will get closed automatically by us so the developer doesn't have to.
36
        $result = $this->put(
37
            $path = trim($path . '/' . $name, '/'),
38
            $stream,
0 ignored issues
show
Documentation introduced by
$stream is of type resource, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
39
            $options
40
        );
41
42
        if (is_resource($stream)) {
43
            fclose($stream);
44
        }
45
        return $result ? $path : false;
46
    }
47
48
    /**
49
     * Get the URL for the file at the given path.
50
     *
51
     * @param  string $path
52
     * @return string
53
     */
54
    public function getUrl($path)
55
    {
56
        $adapter = $this->getAdapter();
57
58
        if (method_exists($adapter, 'getUrl')) {
59
            return $adapter->getUrl($path);
0 ignored issues
show
Bug introduced by
The method getUrl() does not seem to exist on object<League\Flysystem\AdapterInterface>.

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.

Loading history...
60
//        } elseif ($adapter instanceof AwsS3Adapter) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
61
//            return $this->getAwsUrl($adapter, $path);
62
        } elseif ($adapter instanceof LocalAdapter) {
63
            return $this->getLocalUrl($path);
64
        } else {
65
            throw new RuntimeException('This driver does not support retrieving URLs.');
66
        }
67
    }
68
69
    /**
70
     * Get the URL for the file at the given path.
71
     *
72
     * @param  string $path
73
     * @return string
74
     */
75
    protected function getLocalUrl($path)
76
    {
77
        $config = $this->getConfig();
78
79
        // If an explicit base URL has been set on the disk configuration then we will use
80
        // it as the base URL instead of the default path. This allows the developer to
81
        // have full control over the base path for this filesystem's generated URLs.
82
        if ($config->has('url')) {
83
            return rtrim($config->get('url'), '/') . '/' . ltrim($path, '/');
84
        }
85
86
        $path = '/storage/' . $path;
87
88
        // If the path contains "storage/public", it probably means the developer is using
89
        // the default disk to generate the path instead of the "public" disk like they
90
        // are really supposed to use. We will remove the public from this path here.
91
        if (Str::contains($path, '/storage/public/')) {
92
            return Str::replaceFirst('/public/', '/', $path);
93
        } else {
94
            return $path;
95
        }
96
    }
97
}
98