Passed
Push — master ( cbec87...7e0337 )
by alpha
02:15
created

PutRemoteFile::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 2
1
<?php
2
3
4
namespace AlphaSnow\AliyunOss\Plugins;
5
6
use League\Flysystem\Config;
7
use League\Flysystem\Plugin\AbstractPlugin;
8
9
class PutRemoteFile extends AbstractPlugin
10
{
11 1
    public function getMethod()
12
    {
13 1
        return 'putRemoteFile';
14
    }
15
16
    /**
17
     * @param string $path
18
     * @param string $remoteUrl
19
     * @param array $config
20
     * @return bool
21
     */
22 1
    public function handle($path, $remoteUrl, array $config = [])
23
    {
24 1
        $config = new Config($config);
25 1
        if (method_exists($this->filesystem, 'getConfig')) {
26 1
            $config->setFallback($this->filesystem->getConfig());
27
        }
28
29 1
        $resource = fopen($remoteUrl, 'r');
30 1
        $status = (bool)$this->filesystem->getAdapter()->writeStream($path, $resource, $config);
31 1
        fclose($resource);
32 1
        return $status;
33
    }
34
35
}