GetProcessUrl::handle()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
c 1
b 0
f 0
nc 3
nop 3
dl 0
loc 13
rs 10
1
<?php
2
/**
3
 * Created by summer.
4
 * User: summer
5
 * Date: 18/7/22
6
 * Time: 下午7:03
7
 */
8
9
namespace Jacobcyl\AliOSS\Plugins;
10
11
use League\Flysystem\Plugin\AbstractPlugin;
0 ignored issues
show
Bug introduced by
The type League\Flysystem\Plugin\AbstractPlugin 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...
12
use Illuminate\Contracts\Filesystem\FileNotFoundException;
0 ignored issues
show
Bug introduced by
The type Illuminate\Contracts\Fil...m\FileNotFoundException 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...
13
14
class GetProcessUrl extends AbstractPlugin
15
{
16
17
    /**
18
     * Get the method name.
19
     *
20
     * @return string
21
     */
22
    public function getMethod()
23
    {
24
        return 'getProcessUrl';
25
    }
26
27
    /**
28
     * 对oss图片进行操作
29
     * 阿里云 oss 帮助文档:https://help.aliyun.com/document_detail/44688.html?spm=a2c4g.11186623.6.1199.40572e934MoHWu
30
     * @param $path 文件路径
0 ignored issues
show
Documentation Bug introduced by
The doc comment 文件路径 at position 0 could not be parsed: Unknown type name '文件路径' at position 0 in 文件路径.
Loading history...
31
     * @param string $action 操作名称
32
     * @param array $option 操作参数
33
     * @return string 返回 url 链接地址
34
     * @throws \Exception
35
     */
36
    public function handle($path, $action = 'resize', $option = ['m' => 'fixed','h' => '100','w' => '100']){
37
        if(empty($action) || empty($option)){
38
            throw new \Exception('操作名称和操作参数不能为空!');
39
        }
40
41
        $url = $this->filesystem->getAdapter()->getUrl($path);
42
43
        $param = '';
44
        foreach ($option as $key => $value){
45
            $param .= ','.$key.'_'.$value;
46
        }
47
48
        return $url.'?x-oss-process=image/'.$action.$param;
49
    }
50
}
51