Skip to content

Commit

Permalink
Merge pull request #29 from 365Werk/feature/add-exceptions-to-services
Browse files Browse the repository at this point in the history
Feature/add exceptions to services
  • Loading branch information
HergenD authored Apr 30, 2021
2 parents bfefdc5 + f0014b7 commit 012f7d5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "werk365/identitydocuments",
"description": "Package to parse identity documents like passports",
"license": "GPL-3.0-or-later",
"version": "2.0.1",
"version": "2.0.2",
"authors": [
{
"name": "Hergen Dillema",
Expand Down
6 changes: 6 additions & 0 deletions src/Commands/MakeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ public function handle()
case 'facedetection':
case 'fd':
$this->stubName = 'FaceDetectionServiceStub.php';
break;
case 'both':
$this->stubName = 'OcrFdServiceStub.php';
break;
default:
$this->error('Service Type not recognized, try using "OCR", "FaceDetection" or "Both"');

return false;
}
// First we need to ensure that the given name is not a reserved word within the PHP
// language and that the class name will actually be valid. If it is not valid we
Expand Down
13 changes: 13 additions & 0 deletions src/Exceptions/CouldNotSetService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Werk365\IdentityDocuments\Exceptions;

use Exception;

class CouldNotSetService extends Exception
{
public static function couldNotDetectInterface($interface, $service)
{
return new static("Could not detect interface {$interface} on service {$service}.");
}
}
5 changes: 3 additions & 2 deletions src/IdentityImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Exception;
use Intervention\Image\Image;
use ReflectionClass;
use Werk365\IdentityDocuments\Exceptions\CouldNotSetService;
use Werk365\IdentityDocuments\Filters\MergeFilter;
use Werk365\IdentityDocuments\Interfaces\FaceDetection;
use Werk365\IdentityDocuments\Interfaces\OCR;
Expand All @@ -29,7 +30,7 @@ public function setOcrService(string $service)
{
$class = new ReflectionClass($service);
if (! $class->implementsInterface(OCR::class)) {
dd('not ocr');
throw CouldNotSetService::couldNotDetectInterface(OCR::class, $service);
}
$this->ocrService = $service;
}
Expand All @@ -38,7 +39,7 @@ public function setFaceDetectionService(string $service)
{
$class = new ReflectionClass($service);
if (! $class->implementsInterface(FaceDetection::class)) {
dd('not fd');
throw CouldNotSetService::couldNotDetectInterface(FaceDetection::class, $service);
}
$this->faceDetectionService = $service;
}
Expand Down

0 comments on commit 012f7d5

Please sign in to comment.