Passed
Push — master ( 4d0ab7...cefb78 )
by Chris
11:24
created

InteractsWithStorage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 10
c 3
b 0
f 0
dl 0
loc 63
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A path() 0 3 1
A ensureSourceIsNotNull() 0 4 2
A disk() 0 5 1
A source() 0 5 1
1
<?php
2
3
namespace Meema\MediaRecognition\Traits;
4
5
trait InteractsWithStorage
6
{
7
    /**
8
     * The disk of where the file to analyze is stored.
9
     *
10
     * @var string
11
     */
12
    protected string $disk;
13
14
    /**
15
     * The path to the source of the file to analyze.
16
     *
17
     * @var string|null
18
     */
19
    protected ?string $source = null;
20
21
    /**
22
     * Set which S3 disk to use.
23
     *
24
     * @param string $disk
25
     * @return $this
26
     */
27
    public function disk(string $disk)
28
    {
29
        $this->disk = $disk;
30
31
        return $this;
32
    }
33
34
    /**
35
     * The equivalent of the S3 Key / the path of the file inside the bucket.
36
     *
37
     * @param string $source
38
     * @return $this
39
     */
40
    public function source(string $source)
41
    {
42
        $this->source = $source;
43
44
        return $this;
45
    }
46
47
    /**
48
     * Alias of source().
49
     *
50
     * @param string $source
51
     * @return $this
52
     */
53
    public function path(string $source)
54
    {
55
        return $this->source($source);
56
    }
57
58
    /**
59
     * Ensures the source/path not to be null if it is null it will thrown an exception.
60
     *
61
     * @return void
62
     * @throws \Exception
63
     */
64
    public function ensureSourceIsNotNull()
65
    {
66
        if (is_null($this->source)) {
67
            throw new \Exception('Please set a $source to run the analysis on');
68
        }
69
    }
70
}
71