diff --git a/src/Abstracts/Requests/Request.php b/src/Abstracts/Requests/Request.php index 0351216eb..4a25aab32 100644 --- a/src/Abstracts/Requests/Request.php +++ b/src/Abstracts/Requests/Request.php @@ -3,7 +3,7 @@ namespace Apiato\Core\Abstracts\Requests; use Apiato\Core\Abstracts\Models\UserModel as User; -use Apiato\Core\Exceptions\IncorrectIdException; +use Apiato\Core\Exceptions\IncorrectId; use Apiato\Core\Traits\HashIdTrait; use Apiato\Core\Traits\SanitizerTrait; use Illuminate\Foundation\Http\FormRequest as LaravelRequest; @@ -171,7 +171,7 @@ protected function hasAnyRoleAccess($user): array * Note that the old value (data.attributes.name) is removed the original request - this method manipulates the request! * Be sure you know what you do! * - * @throws IncorrectIdException + * @throws IncorrectId * @throws \Throwable */ public function mapInput(array $fields): void @@ -199,7 +199,7 @@ public function mapInput(array $fields): void * * @param null $keys * - * @throws IncorrectIdException + * @throws IncorrectId * @throws \Throwable */ public function all($keys = null): array @@ -233,7 +233,7 @@ protected function mergeUrlParametersWithRequestData(array $requestData): array /** * This method mimics the $request->input() method but works on the "decoded" values. * - * @throws IncorrectIdException + * @throws IncorrectId * @throws \Throwable */ public function getInputByKey($key = null, $default = null): mixed diff --git a/src/Abstracts/Transformers/Transformer.php b/src/Abstracts/Transformers/Transformer.php index a294f8d41..f92acf9de 100644 --- a/src/Abstracts/Transformers/Transformer.php +++ b/src/Abstracts/Transformers/Transformer.php @@ -2,8 +2,8 @@ namespace Apiato\Core\Abstracts\Transformers; -use Apiato\Core\Exceptions\CoreInternalErrorException; -use Apiato\Core\Exceptions\UnsupportedFractalIncludeException; +use Apiato\Core\Exceptions\InternalError; +use Apiato\Core\Exceptions\UnsupportedInclude; use League\Fractal\Resource\Collection; use League\Fractal\Resource\Item; use League\Fractal\Resource\Primitive; @@ -47,10 +47,10 @@ protected function callIncludeMethod(Scope $scope, $includeName, $data) return parent::callIncludeMethod($scope, $includeName, $data); } catch (\ErrorException $exception) { if (config('apiato.requests.force-valid-includes', true)) { - throw new UnsupportedFractalIncludeException($exception->getMessage()); + throw new UnsupportedInclude($exception->getMessage()); } } catch (\Exception $exception) { - throw new CoreInternalErrorException($exception->getMessage()); + throw new InternalError($exception->getMessage()); } } diff --git a/src/Exceptions/AuthenticationException.php b/src/Exceptions/AuthenticationException.php deleted file mode 100644 index cfa6c3b22..000000000 --- a/src/Exceptions/AuthenticationException.php +++ /dev/null @@ -1,12 +0,0 @@ -endpoint) is missed in your test.'; diff --git a/src/Exceptions/UndefinedMethodException.php b/src/Exceptions/UndefinedMethod.php similarity index 82% rename from src/Exceptions/UndefinedMethodException.php rename to src/Exceptions/UndefinedMethod.php index 3f0097d64..25f69ebd4 100644 --- a/src/Exceptions/UndefinedMethodException.php +++ b/src/Exceptions/UndefinedMethod.php @@ -5,7 +5,7 @@ use Apiato\Core\Abstracts\Exceptions\Exception; use Symfony\Component\HttpFoundation\Response; -class UndefinedMethodException extends Exception +class UndefinedMethod extends Exception { protected $code = Response::HTTP_FORBIDDEN; protected $message = 'Undefined HTTP Verb!'; diff --git a/src/Exceptions/UnsupportedFractalIncludeException.php b/src/Exceptions/UnsupportedInclude.php similarity index 81% rename from src/Exceptions/UnsupportedFractalIncludeException.php rename to src/Exceptions/UnsupportedInclude.php index 947a48bfa..9369e653b 100644 --- a/src/Exceptions/UnsupportedFractalIncludeException.php +++ b/src/Exceptions/UnsupportedInclude.php @@ -5,7 +5,7 @@ use Apiato\Core\Abstracts\Exceptions\Exception; use Symfony\Component\HttpFoundation\Response; -class UnsupportedFractalIncludeException extends Exception +class UnsupportedInclude extends Exception { protected $code = Response::HTTP_BAD_REQUEST; protected $message = 'Requested a invalid Include Parameter.'; diff --git a/src/Exceptions/WrongEndpointFormatException.php b/src/Exceptions/WrongEndpointFormat.php similarity index 84% rename from src/Exceptions/WrongEndpointFormatException.php rename to src/Exceptions/WrongEndpointFormat.php index d035b711f..6fb131044 100644 --- a/src/Exceptions/WrongEndpointFormatException.php +++ b/src/Exceptions/WrongEndpointFormat.php @@ -5,7 +5,7 @@ use Apiato\Core\Abstracts\Exceptions\Exception; use Symfony\Component\HttpFoundation\Response; -class WrongEndpointFormatException extends Exception +class WrongEndpointFormat extends Exception { protected $code = Response::HTTP_INTERNAL_SERVER_ERROR; protected $message = 'tests ($this->endpoint) property must be formatted as "verb@url".'; diff --git a/src/Generator/Generator.php b/src/Generator/Generator.php index a35ffa038..6fb390188 100644 --- a/src/Generator/Generator.php +++ b/src/Generator/Generator.php @@ -2,7 +2,7 @@ namespace Apiato\Core\Generator; -use Apiato\Core\Exceptions\GeneratorErrorException; +use Apiato\Core\Exceptions\GeneratorError; use Apiato\Core\Generator\Interfaces\ComponentsGenerator; use Apiato\Core\Generator\Traits\FileSystemTrait; use Apiato\Core\Generator\Traits\FormatterTrait; @@ -90,7 +90,7 @@ public function __construct(IlluminateFilesystem $fileSystem) /** * @void * - * @throws GeneratorErrorException|FileNotFoundException + * @throws GeneratorError|FileNotFoundException */ public function handle() { @@ -138,12 +138,12 @@ public function handle() } /** - * @throws GeneratorErrorException + * @throws GeneratorError */ private function validateGenerator($generator): void { if (!$generator instanceof ComponentsGenerator) { - throw new GeneratorErrorException('Your component maker command should implement ComponentsGenerator interface.'); + throw new GeneratorError('Your component maker command should implement ComponentsGenerator interface.'); } } diff --git a/src/Middlewares/Http/ValidateJsonContent.php b/src/Middlewares/Http/ValidateJsonContent.php index 46e3ca119..4db74c757 100644 --- a/src/Middlewares/Http/ValidateJsonContent.php +++ b/src/Middlewares/Http/ValidateJsonContent.php @@ -3,18 +3,18 @@ namespace Apiato\Core\Middlewares\Http; use Apiato\Core\Abstracts\Middlewares\Middleware; -use Apiato\Core\Exceptions\MissingJSONHeaderException; +use Apiato\Core\Exceptions\MissingJSONHeader; use Illuminate\Http\Request; class ValidateJsonContent extends Middleware { /** - * @throws MissingJSONHeaderException + * @throws MissingJSONHeader */ public function handle(Request $request, \Closure $next) { if (!$request->expectsJson() && config('apiato.requests.force-accept-header')) { - throw new MissingJSONHeaderException(); + throw new MissingJSONHeader(); } return $next($request); diff --git a/src/Traits/CanOwnTrait.php b/src/Traits/CanOwnTrait.php index e24367076..d0107736c 100644 --- a/src/Traits/CanOwnTrait.php +++ b/src/Traits/CanOwnTrait.php @@ -2,7 +2,7 @@ namespace Apiato\Core\Traits; -use Apiato\Core\Exceptions\CoreInternalErrorException; +use Apiato\Core\Exceptions\InternalError; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Str; @@ -18,7 +18,7 @@ trait CanOwnTrait * * If the relation name is different, you can pass it as the second parameter. * - * @throws CoreInternalErrorException + * @throws InternalError */ public function isOwnedBy(Model $owner, string|null $relation = null): bool { @@ -35,7 +35,7 @@ public function isOwnedBy(Model $owner, string|null $relation = null): bool * * If the relation name is different, you can pass it as the second parameter. * - * @throws CoreInternalErrorException + * @throws InternalError */ public function owns(Model $ownable, string|null $relation = null): bool { @@ -53,7 +53,7 @@ public function owns(Model $ownable, string|null $relation = null): bool return null !== $this->$relation()->find($ownable); } - throw new CoreInternalErrorException('No relationship found. Please pass the relationship name as the second parameter.'); + throw new InternalError('No relationship found. Please pass the relationship name as the second parameter.'); } protected function guessSingularRelationshipName(Model $ownable): string diff --git a/src/Traits/HashIdTrait.php b/src/Traits/HashIdTrait.php index 6405f9dc7..3c229ddfb 100644 --- a/src/Traits/HashIdTrait.php +++ b/src/Traits/HashIdTrait.php @@ -2,8 +2,8 @@ namespace Apiato\Core\Traits; -use Apiato\Core\Exceptions\CoreInternalErrorException; -use Apiato\Core\Exceptions\IncorrectIdException; +use Apiato\Core\Exceptions\InternalError; +use Apiato\Core\Exceptions\IncorrectId; use Vinkla\Hashids\Facades\Hashids; trait HashIdTrait @@ -26,7 +26,7 @@ trait HashIdTrait public function getHashedKey(string|null $field = null): string|null { // if no key is set, use the default key name (i.e., id) - if (null === $field) { + if (is_null($field)) { $field = $this->getKeyName(); } @@ -35,7 +35,7 @@ public function getHashedKey(string|null $field = null): string|null // we need to get the VALUE for this KEY (model field) $value = $this->getAttribute($field); - if (null === $value) { + if (is_null($value)) { return null; } @@ -77,7 +77,7 @@ public function decodeArray(array $ids): array public function decode(string|null $id): int|null { // check if passed as null, (could be an optional decodable variable) - if (null === $id || 'null' === strtolower($id)) { + if (is_null($id) || 'null' === strtolower($id)) { return $id; } @@ -99,7 +99,7 @@ private function decoder($id): array * without decoding the encoded ID's you won't be able to use * validation features like `exists:table,id`. * - * @throws IncorrectIdException + * @throws IncorrectId * @throws \Throwable */ protected function decodeHashedIdsBeforeValidation(array $requestData): array @@ -118,7 +118,7 @@ protected function decodeHashedIdsBeforeValidation(array $requestData): array /** * Search the IDs to be decoded in the request data. * - * @throws IncorrectIdException + * @throws IncorrectId * @throws \Throwable */ private function locateAndDecodeIds($requestData, $key): mixed @@ -133,7 +133,7 @@ private function locateAndDecodeIds($requestData, $key): mixed /** * Recursive function to process (decode) the request data with a given key. * - * @throws IncorrectIdException + * @throws IncorrectId * @throws \Throwable */ private function processField($data, $keysTodo, $currentFieldName): mixed @@ -152,13 +152,13 @@ private function processField($data, $keysTodo, $currentFieldName): mixed throw_if( !is_string($data), - new CoreInternalErrorException('String expected, got ' . gettype($data), 422), + new InternalError('String expected, got ' . gettype($data), 422), ); $decodedField = $this->decode($data); if (is_null($decodedField)) { - throw new IncorrectIdException('ID (' . $currentFieldName . ') is incorrect, consider using the hashed ID.'); + throw new IncorrectId('ID (' . $currentFieldName . ') is incorrect, consider using the hashed ID.'); } return $decodedField; diff --git a/src/Traits/HashedRouteBindingTrait.php b/src/Traits/HashedRouteBindingTrait.php index 9c53ae5ab..234ef092e 100644 --- a/src/Traits/HashedRouteBindingTrait.php +++ b/src/Traits/HashedRouteBindingTrait.php @@ -2,7 +2,7 @@ namespace Apiato\Core\Traits; -use Apiato\Core\Exceptions\IncorrectIdException; +use Apiato\Core\Exceptions\IncorrectId; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Support\Str; @@ -15,14 +15,14 @@ trait HashedRouteBindingTrait * @param Model|Relation $query * @param string|null $field * - * @throws IncorrectIdException + * @throws IncorrectId */ public function resolveRouteBindingQuery($query, $value, $field = null) { if (config('apiato.hash-id')) { $decodingResult = $this->decode($value); if (is_null($decodingResult)) { - throw new IncorrectIdException(); + throw new IncorrectId(); } $value = $decodingResult; } diff --git a/src/Traits/ResponseTrait.php b/src/Traits/ResponseTrait.php index d8131bb0d..ef4f2eeed 100644 --- a/src/Traits/ResponseTrait.php +++ b/src/Traits/ResponseTrait.php @@ -4,7 +4,7 @@ use Apiato\Core\Abstracts\Models\Model; use Apiato\Core\Abstracts\Transformers\Transformer; -use Apiato\Core\Exceptions\InvalidTransformerException; +use Apiato\Core\Exceptions\InvalidTransformer; use Illuminate\Http\JsonResponse; use Illuminate\Pagination\AbstractPaginator; use Illuminate\Support\Collection; @@ -16,7 +16,7 @@ trait ResponseTrait protected array $metaData = []; /** - * @throws InvalidTransformerException + * @throws InvalidTransformer */ public function transform( $data, @@ -36,7 +36,7 @@ public function transform( // now, finally check, if the class is really a TRANSFORMER if (!($transformer instanceof Transformer)) { - throw new InvalidTransformerException(); + throw new InvalidTransformer(); } // add specific meta information to the response message diff --git a/src/Traits/SanitizerTrait.php b/src/Traits/SanitizerTrait.php index cf849b089..9eab037ad 100644 --- a/src/Traits/SanitizerTrait.php +++ b/src/Traits/SanitizerTrait.php @@ -2,7 +2,7 @@ namespace Apiato\Core\Traits; -use Apiato\Core\Exceptions\IncorrectIdException; +use Apiato\Core\Exceptions\IncorrectId; use Illuminate\Support\Arr; trait SanitizerTrait @@ -15,7 +15,8 @@ trait SanitizerTrait * * @return array an array containing the values if the field was present in the request and the intersection array * - * @throws IncorrectIdException + * @throws IncorrectId + * @throws \Throwable */ public function sanitizeInput(array $fields): array { diff --git a/src/Traits/TestTraits/TestRequestHelperTrait.php b/src/Traits/TestTraits/TestRequestHelperTrait.php index 3e27f5cca..06ae654b1 100644 --- a/src/Traits/TestTraits/TestRequestHelperTrait.php +++ b/src/Traits/TestTraits/TestRequestHelperTrait.php @@ -2,9 +2,9 @@ namespace Apiato\Core\Traits\TestTraits; -use Apiato\Core\Exceptions\MissingTestEndpointException; -use Apiato\Core\Exceptions\UndefinedMethodException; -use Apiato\Core\Exceptions\WrongEndpointFormatException; +use Apiato\Core\Exceptions\MissingTestEndpoint; +use Apiato\Core\Exceptions\UndefinedMethod; +use Apiato\Core\Exceptions\WrongEndpointFormat; use Illuminate\Support\Arr; use Illuminate\Support\Str; use Illuminate\Testing\TestResponse; @@ -43,9 +43,9 @@ trait TestRequestHelperTrait private string|null $url; /** - * @throws WrongEndpointFormatException - * @throws MissingTestEndpointException - * @throws UndefinedMethodException + * @throws WrongEndpointFormat + * @throws MissingTestEndpoint + * @throws UndefinedMethod */ public function makeCall(array $data = [], array $headers = []): TestResponse { @@ -69,7 +69,7 @@ public function makeCall(array $data = [], array $headers = []): TestResponse case 'delete': break; default: - throw new UndefinedMethodException('Unsupported HTTP Verb (' . $verb . ')!'); + throw new UndefinedMethod('Unsupported HTTP Verb (' . $verb . ')!'); } $httpResponse = $this->json($verb, $url, $data, $this->injectAccessToken($headers)); @@ -82,8 +82,8 @@ public function makeCall(array $data = [], array $headers = []): TestResponse * * @return array * - * @throws WrongEndpointFormatException - * @throws MissingTestEndpointException + * @throws WrongEndpointFormat + * @throws MissingTestEndpoint */ private function parseEndpoint(): array { @@ -108,18 +108,18 @@ private function parseEndpoint(): array } /** - * @throws MissingTestEndpointException + * @throws MissingTestEndpoint */ private function validateEndpointExist(): void { if (!$this->getEndpoint()) { - throw new MissingTestEndpointException(); + throw new MissingTestEndpoint(); } } public function getEndpoint(): string { - if (null !== $this->overrideEndpoint) { + if (!is_null($this->overrideEndpoint)) { return $this->overrideEndpoint; } @@ -127,12 +127,12 @@ public function getEndpoint(): string } /** - * @throws WrongEndpointFormatException + * @throws WrongEndpointFormat */ private function validateEndpointFormat(string $separator): void { if (!strpos($this->getEndpoint(), $separator)) { - throw new WrongEndpointFormatException(); + throw new WrongEndpointFormat(); } } @@ -184,7 +184,7 @@ private function injectAccessToken(array $headers = []): array public function getAuth(): bool { - if (null === $this->overrideAuth) { + if (is_null($this->overrideAuth)) { return $this->auth; } @@ -248,7 +248,7 @@ public function injectId($id, bool $skipEncoding = false, string $replace = '{id $id = $this->hashIdIfEnabled($id); } - if (null === $this->overrideEndpoint) { + if (is_null($this->overrideEndpoint)) { $this->endpoint = str_replace($replace, $id, $this->endpoint); } else { $this->overrideEndpoint = str_replace($replace, $id, $this->overrideEndpoint); diff --git a/tests/Unit/Traits/HashIdTraitTest.php b/tests/Unit/Traits/HashIdTraitTest.php index 461d48b4e..2303d9bff 100644 --- a/tests/Unit/Traits/HashIdTraitTest.php +++ b/tests/Unit/Traits/HashIdTraitTest.php @@ -2,7 +2,7 @@ namespace Apiato\Core\Tests\Unit\Traits; -use Apiato\Core\Exceptions\IncorrectIdException; +use Apiato\Core\Exceptions\IncorrectId; use Apiato\Core\Tests\UnitTestCase; use Apiato\Core\Traits\HashIdTrait; use Mockery\LegacyMockInterface; @@ -260,7 +260,7 @@ public function testDecodeReturnsNullForNonHashString(): void #[DataProvider('invalidHashedIdsProvider')] public function testThrowsIncorrectIdException(array $requestData, array $decode): void { - $this->expectException(IncorrectIdException::class); + $this->expectException(IncorrectId::class); $this->trait->decode = $decode;