ahmadmayahi /
php-google-vision
| 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
Loading history...
|
|||||
| 34 | medical: Likelihood::fromKey($response->getMedical()), |
||||
|
0 ignored issues
–
show
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
Loading history...
|
|||||
| 35 | spoof: Likelihood::fromKey($response->getSpoof()), |
||||
|
0 ignored issues
–
show
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
Loading history...
|
|||||
| 36 | violence: Likelihood::fromKey($response->getViolence()), |
||||
|
0 ignored issues
–
show
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
Loading history...
|
|||||
| 37 | racy: Likelihood::fromKey($response->getRacy()), |
||||
|
0 ignored issues
–
show
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
Loading history...
|
|||||
| 38 | )); |
||||
| 39 | } |
||||
| 40 | } |
||||
| 41 |