Logo   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
c 0
b 0
f 0
dl 0
loc 25
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A detect() 0 11 3
A getOriginalResponse() 0 7 1
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\Logo as LogoData;
9
use AhmadMayahi\Vision\Support\AbstractDetector;
10
use AhmadMayahi\Vision\Traits\Arrayable;
11
use AhmadMayahi\Vision\Traits\Jsonable;
12
use Generator;
13
use Google\Cloud\Vision\V1\EntityAnnotation;
14
use Google\Protobuf\Internal\RepeatedField;
15
16
/**
17
 * @see https://cloud.google.com/vision/docs/detecting-logos
18
 */
19
class Logo extends AbstractDetector implements Detectable
20
{
21
    use Arrayable;
22
    use Jsonable;
23
24
    public function getOriginalResponse(): RepeatedField
25
    {
26
        $response = $this
27
            ->imageAnnotatorClient
28
            ->logoDetection($this->file->toVisionFile());
29
30
        return $response->getLogoAnnotations();
31
    }
32
33
    public function detect(): ?Generator
34
    {
35
        $response = $this->getOriginalResponse();
36
37
        if (0 === $response->count()) {
38
            return null;
39
        }
40
41
        /** @var EntityAnnotation $item */
42
        foreach ($response as $item) {
43
            yield new LogoData($item->getDescription());
44
        }
45
    }
46
}
47