PutRemoteFile   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
eloc 11
dl 0
loc 34
c 0
b 0
f 0
ccs 0
cts 15
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethod() 0 3 1
A handle() 0 15 2
1
<?php
2
3
namespace Freyo\Flysystem\QcloudCOSv4\Plugins;
4
5
use League\Flysystem\Plugin\AbstractPlugin;
6
use League\Flysystem\Util\MimeType;
7
use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFo...meType\ExtensionGuesser was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
class PutRemoteFile extends AbstractPlugin
10
{
11
    /**
12
     * Get the method name.
13
     *
14
     * @return string
15
     */
16
    public function getMethod()
17
    {
18
        return 'putRemoteFile';
19
    }
20
21
    /**
22
     * @param       $path
23
     * @param       $remoteUrl
24
     * @param array $options
25
     *
26
     * @return bool
27
     */
28
    public function handle($path, $remoteUrl, array $options = [])
29
    {
30
        //Get file from remote url
31
        $contents = (new \GuzzleHttp\Client(['verify' => false]))
32
            ->request('get', $remoteUrl)
33
            ->getBody()
34
            ->getContents();
35
36
        $filename = md5($contents);
37
        $extension = ExtensionGuesser::getInstance()->guess(MimeType::detectByContent($contents));
38
        $name = $filename.'.'.$extension;
39
40
        $path = trim($path.'/'.$name, '/');
41
42
        return $this->filesystem->put($path, $contents, $options) ? $path : false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->filesystem...ptions) ? $path : false also could return the type string which is incompatible with the documented return type boolean.
Loading history...
43
    }
44
}
45