SafeSearch::detect()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 14
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AhmadMayahi\Vision\Detectors;
6
7
use AhmadMayahi\Vision\Contracts\Detectable;
8
use AhmadMayahi\Vision\Data\SafeSearch as SafeSearchData;
9
use AhmadMayahi\Vision\Enums\Likelihood;
10
use AhmadMayahi\Vision\Support\AbstractDetector;
11
use Google\Cloud\Vision\V1\SafeSearchAnnotation;
12
13
class SafeSearch extends AbstractDetector implements Detectable
14
{
15
    public function getOriginalResponse(): ?SafeSearchAnnotation
16
    {
17
        $response = $this
18
            ->imageAnnotatorClient
19
            ->safeSearchDetection($this->file->toVisionFile());
20
21
        return $response->getSafeSearchAnnotation();
22
    }
23
24
    public function detect(): ?SafeSearchData
25
    {
26
        $response = $this->getOriginalResponse();
27
28
        if (! $response) {
29
            return null;
30
        }
31
32
        return (new SafeSearchData(
33
            adult: Likelihood::fromKey($response->getAdult()),
0 ignored issues
show
Bug introduced by
It seems like AhmadMayahi\Vision\Enums...($response->getAdult()) can also be of type null; however, parameter $adult of AhmadMayahi\Vision\Data\SafeSearch::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

33
            /** @scrutinizer ignore-type */ adult: Likelihood::fromKey($response->getAdult()),
Loading history...
34
            medical: Likelihood::fromKey($response->getMedical()),
0 ignored issues
show
Bug introduced by
It seems like AhmadMayahi\Vision\Enums...response->getMedical()) can also be of type null; however, parameter $medical of AhmadMayahi\Vision\Data\SafeSearch::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

34
            /** @scrutinizer ignore-type */ medical: Likelihood::fromKey($response->getMedical()),
Loading history...
35
            spoof: Likelihood::fromKey($response->getSpoof()),
0 ignored issues
show
Bug introduced by
It seems like AhmadMayahi\Vision\Enums...($response->getSpoof()) can also be of type null; however, parameter $spoof of AhmadMayahi\Vision\Data\SafeSearch::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

35
            /** @scrutinizer ignore-type */ spoof: Likelihood::fromKey($response->getSpoof()),
Loading history...
36
            violence: Likelihood::fromKey($response->getViolence()),
0 ignored issues
show
Bug introduced by
It seems like AhmadMayahi\Vision\Enums...esponse->getViolence()) can also be of type null; however, parameter $violence of AhmadMayahi\Vision\Data\SafeSearch::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

36
            /** @scrutinizer ignore-type */ violence: Likelihood::fromKey($response->getViolence()),
Loading history...
37
            racy: Likelihood::fromKey($response->getRacy()),
0 ignored issues
show
Bug introduced by
It seems like AhmadMayahi\Vision\Enums...y($response->getRacy()) can also be of type null; however, parameter $racy of AhmadMayahi\Vision\Data\SafeSearch::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

37
            /** @scrutinizer ignore-type */ racy: Likelihood::fromKey($response->getRacy()),
Loading history...
38
        ));
39
    }
40
}
41