Passed
Push — master ( dec909...4437a6 )
by Chris
10:44
created

IncomingWebhookController::fireEventFor()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 26
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 26
rs 8.4444
cc 8
nc 8
nop 2
1
<?php
2
3
namespace Meema\MediaRecognition\Http\Controllers;
4
5
use Aws\Sns\Message;
6
use Illuminate\Routing\Controller;
7
use Illuminate\Support\Facades\Log;
8
use Illuminate\Support\Str;
9
use Meema\MediaRecognition\Events\VideoFacesAreAnalyzed;
10
use Meema\MediaRecognition\Events\VideoLabelsAreAnalyzed;
11
use Meema\MediaRecognition\Events\VideoModerationComplete;
12
use Meema\MediaRecognition\Facades\Recognize;
13
14
class IncomingWebhookController extends Controller
15
{
16
    public function __construct()
17
    {
18
        $this->middleware('verify-signature');
19
    }
20
21
    /**
22
     * @throws \Exception
23
     */
24
    public function __invoke()
25
    {
26
        $message = json_decode(Message::fromRawPostData()['Message'], true);
27
28
        if ($message['Status'] !== 'SUCCEEDED') {
29
            return;
30
        }
31
32
        $arr = explode('_', $message['JobTag']);
33
        $type = $arr[0];
34
        $mediaId = (int) $arr[1];
35
36
        if ($type === 'labels') {
37
            Recognize::getLabelsByJobId($message['JobId'], $mediaId);
0 ignored issues
show
Bug introduced by
The method getLabelsByJobId() does not exist on Meema\MediaRecognition\Facades\Recognize. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

37
            Recognize::/** @scrutinizer ignore-call */ 
38
                       getLabelsByJobId($message['JobId'], $mediaId);
Loading history...
38
39
            event(new VideoLabelsAreAnalyzed($message));
40
41
            return;
42
        }
43
44
        if ($type === 'faces') {
45
            Recognize::getFacesByJobId($message['JobId'], $mediaId);
0 ignored issues
show
Bug introduced by
The method getFacesByJobId() does not exist on Meema\MediaRecognition\Facades\Recognize. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

45
            Recognize::/** @scrutinizer ignore-call */ 
46
                       getFacesByJobId($message['JobId'], $mediaId);
Loading history...
46
47
            event(new VideoFacesAreAnalyzed($message));
48
49
            return;
50
        }
51
52
        if ($type === 'moderation') {
53
            Recognize::getModerationByJobId($message['JobId'], $mediaId);
0 ignored issues
show
Bug introduced by
The method getModerationByJobId() does not exist on Meema\MediaRecognition\Facades\Recognize. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

53
            Recognize::/** @scrutinizer ignore-call */ 
54
                       getModerationByJobId($message['JobId'], $mediaId);
Loading history...
54
55
            event(new VideoModerationComplete($message));
56
        }
57
    }
58
}
59