UploadRequest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 2
dl 0
loc 67
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 5
A getSourcePath() 0 4 1
A getDestinationPath() 0 4 1
A getTarget() 0 4 1
1
<?php
2
namespace STS\StorageConnect;
3
4
use Illuminate\Database\Eloquent\Model;
5
use Illuminate\Queue\SerializesModels;
6
use Illuminate\Support\Str;
7
use STS\StorageConnect\Contracts\UploadTarget;
8
9
class UploadRequest
10
{
11
    use SerializesModels;
12
13
    /**
14
     * @var string
15
     */
16
    protected $sourcePath;
17
18
    /**
19
     * @var string
20
     */
21
    protected $destinationPath;
22
23
    /**
24
     * @var Model
25
     */
26
    protected $target;
27
28
    /**
29
     * UploadRequest constructor.
30
     *
31
     * @param mixed $source
32
     * @param null $destinationPath
33
     */
34
    public function __construct($source, $destinationPath = null)
35
    {
36
        if($source instanceof Model && $source instanceof UploadTarget) {
37
            $this->sourcePath = $source->upload_source_path;
38
            $this->destinationPath = $destinationPath ?: $source->upload_destination_path;
39
            $this->target = $source;
40
        } else {
41
            $this->sourcePath = $source;
42
            $this->destinationPath = $destinationPath;
43
        }
44
45
        $this->destinationPath = Str::start($this->destinationPath, "/");
46
47
        if (Str::startsWith($this->sourcePath, "s3://")) {
48
            app('aws')->createClient('s3')->registerStreamWrapper();
49
        }
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getSourcePath()
56
    {
57
        return $this->sourcePath;
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function getDestinationPath()
64
    {
65
        return $this->destinationPath;
66
    }
67
68
    /**
69
     * @return Model
70
     */
71
    public function getTarget()
72
    {
73
        return $this->target;
74
    }
75
}