AzureAPIFaceDetector::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace XSolve\FaceValidatorBundle\Detector;
4
5
use XSolve\FaceValidatorBundle\Client\AzureFaceAPIClient;
6
use XSolve\FaceValidatorBundle\Exception\NoFaceDetectedException;
7
use XSolve\FaceValidatorBundle\Factory\FaceDetectionResultFactory;
8
use XSolve\FaceValidatorBundle\Result\FaceDetectionResult;
9
10
class AzureAPIFaceDetector implements FaceDetector
11
{
12
    /**
13
     * @var AzureFaceAPIClient
14
     */
15
    private $client;
16
17
    /**
18
     * @var FaceDetectionResultFactory
19
     */
20
    private $resultFactory;
21
22
    public function __construct(AzureFaceAPIClient $client, FaceDetectionResultFactory $resultFactory)
23
    {
24
        $this->client = $client;
25
        $this->resultFactory = $resultFactory;
26
    }
27
28
    public function detect(string $filePath): FaceDetectionResult
29
    {
30
        $data = $this->client->detect($filePath);
31
32
        if (empty($data)) {
33
            throw new NoFaceDetectedException();
34
        }
35
36
        return $this->resultFactory->create($filePath, $data);
37
    }
38
}
39