Passed
Push — master ( d23155...56cfd7 )
by Chris
11:16
created

Recognizable::recognitionData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
namespace Meema\MediaRecognition\Traits;
4
5
use Meema\MediaRecognition\Facades\Recognize;
6
use Meema\MediaRecognition\Models\MediaRecognition;
7
8
trait Recognizable
9
{
10
    /**
11
     * Get all of the media items' conversions.
12
     */
13
    public function recognition()
14
    {
15
        return $this->morphOne(MediaRecognition::class, 'model');
0 ignored issues
show
Bug introduced by
It seems like morphOne() 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

15
        return $this->/** @scrutinizer ignore-call */ morphOne(MediaRecognition::class, 'model');
Loading history...
16
    }
17
18
    /**
19
     * Start a media "recognition".
20
     *
21
     * @param string $path
22
     * @param string|null $mimeType
23
     * @return \Meema\MediaRecognition\Contracts\MediaRecognition
24
     */
25
    public function recognize(string $path, string $mimeType = null)
26
    {
27
        return Recognize::source($path, $mimeType, $this->id);
28
    }
29
30
    /**
31
     * Return all recognition data.
32
     *
33
     * @return array
34
     */
35
    public function recognitionData()
36
    {
37
        $recognition = $this->recognition()->first();
38
39
        return [
40
            'labels' => $recognition->labels['Labels'] ?? [],
41
            'faces' => $recognition->faces['FaceDetails'] ?? [],
42
            'moderation' => $recognition->moderation['ModerationLabels'] ?? [],
43
            'texts' => $recognition->ocr['TextDetections'] ?? [],
44
        ];
45
    }
46
}
47