Passed
Push — master ( cefb78...c2816e )
by Chris
10:44
created

CanRecognizeImages::detectModeration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Meema\MediaRecognition\Traits;
4
5
use Exception;
6
use Meema\MediaRecognition\Models\MediaRecognition;
7
8
trait CanRecognizeImages
9
{
10
    /**
11
     * The input image as base64-encoded bytes.
12
     *
13
     * @var string|null
14
     */
15
    protected ?string $blob = null;
16
17
    /**
18
     * Set the base64 encoded image.
19
     *
20
     * @param string $blob
21
     *
22
     * @return $this
23
     */
24
    public function blob(string $blob)
25
    {
26
        $this->blob = $blob;
27
28
        return $this;
29
    }
30
31
    /**
32
     * Sets the image to be analyzed.
33
     *
34
     * @return void
35
     * @throws \Exception
36
     */
37
    protected function setImageSettings(): void
38
    {
39
        $this->ensureSourceIsNotNull();
0 ignored issues
show
Bug introduced by
It seems like ensureSourceIsNotNull() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
        $this->/** @scrutinizer ignore-call */ 
40
               ensureSourceIsNotNull();
Loading history...
40
41
        if (is_string($this->blob)) {
42
            $this->settings['Image'] = [
0 ignored issues
show
Bug Best Practice introduced by
The property settings does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
43
                'Bytes' => $this->blob,
44
            ];
45
46
            return;
47
        }
48
49
        $disk = $this->disk ?? config('media-recognition.disk');
50
        $bucketName = config("filesystems.disks.$disk.bucket");
51
52
        if (! $bucketName) {
53
            throw new Exception('Please make sure to set a S3 bucket name.');
54
        }
55
56
        $this->settings['Image'] = [
57
            'S3Object' => [
58
                'Bucket' => $bucketName,
59
                'Name' => $this->source,
60
            ],
61
        ];
62
    }
63
}
64