PutRemoteFile   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 36
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethod() 0 4 1
A handle() 0 16 2
1
<?php
2
3
namespace Freyo\Flysystem\QcloudCOSv3\Plugins;
4
5
use League\Flysystem\Plugin\AbstractPlugin;
6
use League\Flysystem\Util\MimeType;
7
use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser;
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;
43
    }
44
}
45