PutRemoteFile::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 11
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 17
ccs 0
cts 13
cp 0
crap 6
rs 9.9
1
<?php
2
3
namespace Freyo\Flysystem\QcloudCOSv5\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 string|false
27
     */
28
    public function handle($path, $remoteUrl, array $options = [])
29
    {
30
        //Get file from remote url
31
        $contents = $this->filesystem
32
            ->getAdapter()
33
            ->getHttpClient()
34
            ->get($remoteUrl)
35
            ->getBody()
36
            ->getContents();
37
38
        $filename = md5($contents);
39
        $extension = ExtensionGuesser::getInstance()->guess(MimeType::detectByContent($contents));
40
        $name = $filename.'.'.$extension;
41
42
        $path = trim($path.'/'.$name, '/');
43
44
        return $this->filesystem->put($path, $contents, $options) ? $path : false;
45
    }
46
}
47