Skip to content

Commit

Permalink
Enum replaced with array.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandar Naydenov committed Apr 27, 2023
1 parent abe7ce7 commit 45594a9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 43 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"require-dev": {
"laravel/pint": "^1.0",
"nunomaduro/collision": "^7.9",
"nunomaduro/larastan": "^2.0.1",
"nunomaduro/larastan": "^2.0",
"orchestra/testbench": "^8.0",
"pestphp/pest": "^2.0",
"pestphp/pest-plugin-arch": "^2.0",
Expand Down
24 changes: 0 additions & 24 deletions src/Enums/ErrorCodes.php

This file was deleted.

34 changes: 16 additions & 18 deletions src/Objects/ErrorResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

namespace Aon2003\LaravelSendInBlue\Objects;

use Aon2003\LaravelSendInBlue\Enums\ErrorCodes;
use ReflectionEnum;
use ReflectionException;

/**
* Class for formulating errors returned by the package.
*/
Expand All @@ -18,6 +14,21 @@ class ErrorResponse
public string $message;
public string $reason;

protected array $errorCodes = [
'invalid_parameter' => 'The value of the parameter you have provided is not valid. Please check the format and the type',
'missing_parameter' => 'One of the required parameter is missing to perform the request',
'out_of_range' => 'The value of the parameter you have provided is not included in the authorized range',
'unauthorized' => 'You are not authorized to do this call',
'reseller_permission_denied' => 'You need a reseller plan to perform this API call',
'document_not_found' => 'The parameter value in brackets {} is not found',
'method_not_allowed' => 'The method you are requesting for this path is not allowed. (ex : you are doing put but only get method is allowed for the path',
'not_enough_credits' => 'You don\'t have enough credit to perform the request. Example : you are trying to send a campaign but your plan has expired',
'duplicate_parameter' => 'You have duplicated one of the parameter in the request',
'duplicate_request' => 'The request rate of the very same request is too high',
'account_under_validation' => 'Your account is under validation',
'permission_denied' => 'You don\'t have the permission to perform this request',
];

/**
* @param int $code
* @param string $json_response
Expand All @@ -31,19 +42,6 @@ public function __construct(int $code, string $json_response)
$this->messageCode = $array_response->code;
$this->reason = $array_response->message;

$this->message = $this->getMessageText($this->messageCode);
}

/**
* @param string $message_code
* @return string
*/
protected function getMessageText(string $message_code): string
{
try {
return (new ReflectionEnum(ErrorCodes::class))->getCase($message_code)->getValue()->value;
} catch (ReflectionException) {
return '';
}
$this->message = $this->errorCodes[$this->messageCode] ?? '';
}
}

0 comments on commit 45594a9

Please sign in to comment.