@@ -29,8 +29,8 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | public function __construct(array $players) |
| 31 | 31 | { |
| 32 | - $this->players = $players; |
|
| 33 | - parent::__construct("Some players do already exist!", 409); |
|
| 32 | + $this->players = $players; |
|
| 33 | + parent::__construct("Some players do already exist!", 409); |
|
| 34 | 34 | } |
| 35 | 35 | //</editor-fold desc="Constructor"> |
| 36 | 36 | |
@@ -41,16 +41,16 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function getJsonMessage() |
| 43 | 43 | { |
| 44 | - return [ |
|
| 45 | - 'message' => "Some players do already exist", |
|
| 46 | - 'players' => array_map(function (Player $player) { |
|
| 47 | - return [ |
|
| 48 | - "firstName" => $player->getFirstName(), |
|
| 49 | - "lastName" => $player->getLastName(), |
|
| 50 | - "id" => $player->getPlayerId(), |
|
| 51 | - "birthday" => $player->getBirthday()->format("Y-m-d")]; |
|
| 52 | - }, $this->players) |
|
| 53 | - ]; |
|
| 44 | + return [ |
|
| 45 | + 'message' => "Some players do already exist", |
|
| 46 | + 'players' => array_map(function (Player $player) { |
|
| 47 | + return [ |
|
| 48 | + "firstName" => $player->getFirstName(), |
|
| 49 | + "lastName" => $player->getLastName(), |
|
| 50 | + "id" => $player->getPlayerId(), |
|
| 51 | + "birthday" => $player->getBirthday()->format("Y-m-d")]; |
|
| 52 | + }, $this->players) |
|
| 53 | + ]; |
|
| 54 | 54 | } |
| 55 | 55 | //</editor-fold desc="Public Methods"> |
| 56 | 56 | } |
| 57 | 57 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * Created by PhpStorm. |
| 5 | 5 | * User: benedikt |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | * PlayerAlreadyExists constructor. |
| 28 | 28 | * @param Player[] $players list of already existing players |
| 29 | 29 | */ |
| 30 | - public function __construct(array $players) |
|
| 30 | + public function __construct( array $players ) |
|
| 31 | 31 | { |
| 32 | 32 | $this->players = $players; |
| 33 | 33 | parent::__construct("Some players do already exist!", 409); |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | { |
| 44 | 44 | return [ |
| 45 | 45 | 'message' => "Some players do already exist", |
| 46 | - 'players' => array_map(function (Player $player) { |
|
| 46 | + 'players' => array_map(function( Player $player ) { |
|
| 47 | 47 | return [ |
| 48 | 48 | "firstName" => $player->getFirstName(), |
| 49 | 49 | "lastName" => $player->getLastName(), |
@@ -16,8 +16,7 @@ discard block |
||
| 16 | 16 | * Class PlayerAlreadyExists |
| 17 | 17 | * @package Tfboe\FmLib\Exceptions |
| 18 | 18 | */ |
| 19 | -class PlayerAlreadyExists extends AbstractException |
|
| 20 | -{ |
|
| 19 | +class PlayerAlreadyExists extends AbstractException { |
|
| 21 | 20 | //<editor-fold desc="Fields"> |
| 22 | 21 | /** @var Player[] */ |
| 23 | 22 | private $players; |
@@ -27,8 +26,7 @@ discard block |
||
| 27 | 26 | * PlayerAlreadyExists constructor. |
| 28 | 27 | * @param Player[] $players list of already existing players |
| 29 | 28 | */ |
| 30 | - public function __construct(array $players) |
|
| 31 | - { |
|
| 29 | + public function __construct(array $players) { |
|
| 32 | 30 | $this->players = $players; |
| 33 | 31 | parent::__construct("Some players do already exist!", 409); |
| 34 | 32 | } |
@@ -39,8 +37,7 @@ discard block |
||
| 39 | 37 | * Gets a json representation of the exception |
| 40 | 38 | * @return array |
| 41 | 39 | */ |
| 42 | - public function getJsonMessage() |
|
| 43 | - { |
|
| 40 | + public function getJsonMessage() { |
|
| 44 | 41 | return [ |
| 45 | 42 | 'message' => "Some players do already exist", |
| 46 | 43 | 'players' => array_map(function (Player $player) { |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * @var array |
| 21 | 21 | */ |
| 22 | 22 | protected $dontReport = [ |
| 23 | - ValidationException::class, |
|
| 23 | + ValidationException::class, |
|
| 24 | 24 | ]; |
| 25 | 25 | //</editor-fold desc="Fields"> |
| 26 | 26 | |
@@ -36,13 +36,13 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public function render($request, Exception $exception) |
| 38 | 38 | { |
| 39 | - //don't throw html exceptions always render using json |
|
| 40 | - $statusCode = $this->getExceptionHTTPStatusCode($exception); |
|
| 39 | + //don't throw html exceptions always render using json |
|
| 40 | + $statusCode = $this->getExceptionHTTPStatusCode($exception); |
|
| 41 | 41 | |
| 42 | - return response()->json( |
|
| 43 | - $this->getJsonMessage($exception, $statusCode), |
|
| 44 | - $statusCode |
|
| 45 | - ); |
|
| 42 | + return response()->json( |
|
| 43 | + $this->getJsonMessage($exception, $statusCode), |
|
| 44 | + $statusCode |
|
| 45 | + ); |
|
| 46 | 46 | } |
| 47 | 47 | //</editor-fold desc="Public Methods"> |
| 48 | 48 | |
@@ -54,13 +54,13 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | protected function getExceptionHTTPStatusCode(Exception $exception) |
| 56 | 56 | { |
| 57 | - // Not all Exceptions have a http status code |
|
| 58 | - // We will give Error 500 if none found |
|
| 59 | - if ($exception instanceof ValidationException) { |
|
| 60 | - return $exception->getResponse()->getStatusCode(); |
|
| 61 | - } |
|
| 62 | - return method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : |
|
| 63 | - ($exception->getCode() != 0 ? $exception->getCode() : 500); |
|
| 57 | + // Not all Exceptions have a http status code |
|
| 58 | + // We will give Error 500 if none found |
|
| 59 | + if ($exception instanceof ValidationException) { |
|
| 60 | + return $exception->getResponse()->getStatusCode(); |
|
| 61 | + } |
|
| 62 | + return method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : |
|
| 63 | + ($exception->getCode() != 0 ? $exception->getCode() : 500); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -70,25 +70,25 @@ discard block |
||
| 70 | 70 | */ |
| 71 | 71 | protected function getExceptionName(Exception $exception): string |
| 72 | 72 | { |
| 73 | - if ($exception instanceof AuthenticationException) { |
|
| 74 | - return ExceptionNames::AUTHENTICATION_EXCEPTION; |
|
| 75 | - } |
|
| 76 | - if ($exception instanceof DuplicateException) { |
|
| 77 | - return ExceptionNames::DUPLICATE_EXCEPTION; |
|
| 78 | - } |
|
| 79 | - if ($exception instanceof UnorderedPhaseNumberException) { |
|
| 80 | - return ExceptionNames::UNORDERED_PHASE_NUMBER_EXCEPTION; |
|
| 81 | - } |
|
| 82 | - if ($exception instanceof ReferenceException) { |
|
| 83 | - return ExceptionNames::REFERENCE_EXCEPTION; |
|
| 84 | - } |
|
| 85 | - if ($exception instanceof PlayerAlreadyExists) { |
|
| 86 | - return ExceptionNames::PLAYER_ALREADY_EXISTS_EXCEPTION; |
|
| 87 | - } |
|
| 88 | - if ($exception instanceof ValidationException) { |
|
| 89 | - return ExceptionNames::VALIDATION_EXCEPTION; |
|
| 90 | - } |
|
| 91 | - return ExceptionNames::INTERNAL_EXCEPTION; |
|
| 73 | + if ($exception instanceof AuthenticationException) { |
|
| 74 | + return ExceptionNames::AUTHENTICATION_EXCEPTION; |
|
| 75 | + } |
|
| 76 | + if ($exception instanceof DuplicateException) { |
|
| 77 | + return ExceptionNames::DUPLICATE_EXCEPTION; |
|
| 78 | + } |
|
| 79 | + if ($exception instanceof UnorderedPhaseNumberException) { |
|
| 80 | + return ExceptionNames::UNORDERED_PHASE_NUMBER_EXCEPTION; |
|
| 81 | + } |
|
| 82 | + if ($exception instanceof ReferenceException) { |
|
| 83 | + return ExceptionNames::REFERENCE_EXCEPTION; |
|
| 84 | + } |
|
| 85 | + if ($exception instanceof PlayerAlreadyExists) { |
|
| 86 | + return ExceptionNames::PLAYER_ALREADY_EXISTS_EXCEPTION; |
|
| 87 | + } |
|
| 88 | + if ($exception instanceof ValidationException) { |
|
| 89 | + return ExceptionNames::VALIDATION_EXCEPTION; |
|
| 90 | + } |
|
| 91 | + return ExceptionNames::INTERNAL_EXCEPTION; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -100,22 +100,22 @@ discard block |
||
| 100 | 100 | protected function getJsonMessage(Exception $exception, $statusCode = null) |
| 101 | 101 | { |
| 102 | 102 | |
| 103 | - $result = method_exists($exception, 'getJsonMessage') ? $exception->getJsonMessage() : |
|
| 104 | - ['message' => $exception->getMessage()]; |
|
| 103 | + $result = method_exists($exception, 'getJsonMessage') ? $exception->getJsonMessage() : |
|
| 104 | + ['message' => $exception->getMessage()]; |
|
| 105 | 105 | |
| 106 | - if ($exception instanceof ValidationException) { |
|
| 107 | - $result["errors"] = $exception->errors(); |
|
| 108 | - } |
|
| 106 | + if ($exception instanceof ValidationException) { |
|
| 107 | + $result["errors"] = $exception->errors(); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - if (!array_key_exists('status', $result)) { |
|
| 111 | - $result['status'] = $statusCode !== null ? $statusCode : "false"; |
|
| 112 | - } |
|
| 110 | + if (!array_key_exists('status', $result)) { |
|
| 111 | + $result['status'] = $statusCode !== null ? $statusCode : "false"; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - if (!array_key_exists('name', $result)) { |
|
| 115 | - $result['name'] = $this->getExceptionName($exception); |
|
| 116 | - } |
|
| 114 | + if (!array_key_exists('name', $result)) { |
|
| 115 | + $result['name'] = $this->getExceptionName($exception); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - return $result; |
|
| 118 | + return $result; |
|
| 119 | 119 | } |
| 120 | 120 | //</editor-fold desc="Protected Methods"> |
| 121 | 121 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | |
| 4 | 4 | namespace Tfboe\FmLib\Exceptions; |
| 5 | 5 | |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @return \Illuminate\Http\Response |
| 35 | 35 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
| 36 | 36 | */ |
| 37 | - public function render($request, Exception $exception) |
|
| 37 | + public function render( $request, Exception $exception ) |
|
| 38 | 38 | { |
| 39 | 39 | //don't throw html exceptions always render using json |
| 40 | 40 | $statusCode = $this->getExceptionHTTPStatusCode($exception); |
@@ -52,15 +52,14 @@ discard block |
||
| 52 | 52 | * @param Exception $exception the exception to extract from |
| 53 | 53 | * @return int|mixed the status code or 500 if no status code found |
| 54 | 54 | */ |
| 55 | - protected function getExceptionHTTPStatusCode(Exception $exception) |
|
| 55 | + protected function getExceptionHTTPStatusCode( Exception $exception ) |
|
| 56 | 56 | { |
| 57 | 57 | // Not all Exceptions have a http status code |
| 58 | 58 | // We will give Error 500 if none found |
| 59 | - if ($exception instanceof ValidationException) { |
|
| 59 | + if ( $exception instanceof ValidationException ) { |
|
| 60 | 60 | return $exception->getResponse()->getStatusCode(); |
| 61 | 61 | } |
| 62 | - return method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : |
|
| 63 | - ($exception->getCode() != 0 ? $exception->getCode() : 500); |
|
| 62 | + return method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : ($exception->getCode() != 0 ? $exception->getCode() : 500); |
|
| 64 | 63 | } |
| 65 | 64 | |
| 66 | 65 | /** |
@@ -68,24 +67,24 @@ discard block |
||
| 68 | 67 | * @param Exception $exception the exception whose name we want |
| 69 | 68 | * @return string the exception name |
| 70 | 69 | */ |
| 71 | - protected function getExceptionName(Exception $exception): string |
|
| 70 | + protected function getExceptionName( Exception $exception ): string |
|
| 72 | 71 | { |
| 73 | - if ($exception instanceof AuthenticationException) { |
|
| 72 | + if ( $exception instanceof AuthenticationException ) { |
|
| 74 | 73 | return ExceptionNames::AUTHENTICATION_EXCEPTION; |
| 75 | 74 | } |
| 76 | - if ($exception instanceof DuplicateException) { |
|
| 75 | + if ( $exception instanceof DuplicateException ) { |
|
| 77 | 76 | return ExceptionNames::DUPLICATE_EXCEPTION; |
| 78 | 77 | } |
| 79 | - if ($exception instanceof UnorderedPhaseNumberException) { |
|
| 78 | + if ( $exception instanceof UnorderedPhaseNumberException ) { |
|
| 80 | 79 | return ExceptionNames::UNORDERED_PHASE_NUMBER_EXCEPTION; |
| 81 | 80 | } |
| 82 | - if ($exception instanceof ReferenceException) { |
|
| 81 | + if ( $exception instanceof ReferenceException ) { |
|
| 83 | 82 | return ExceptionNames::REFERENCE_EXCEPTION; |
| 84 | 83 | } |
| 85 | - if ($exception instanceof PlayerAlreadyExists) { |
|
| 84 | + if ( $exception instanceof PlayerAlreadyExists ) { |
|
| 86 | 85 | return ExceptionNames::PLAYER_ALREADY_EXISTS_EXCEPTION; |
| 87 | 86 | } |
| 88 | - if ($exception instanceof ValidationException) { |
|
| 87 | + if ( $exception instanceof ValidationException ) { |
|
| 89 | 88 | return ExceptionNames::VALIDATION_EXCEPTION; |
| 90 | 89 | } |
| 91 | 90 | return ExceptionNames::INTERNAL_EXCEPTION; |
@@ -97,21 +96,20 @@ discard block |
||
| 97 | 96 | * @param string|null $statusCode the status code or null if unknown |
| 98 | 97 | * @return array containing the infos status and message |
| 99 | 98 | */ |
| 100 | - protected function getJsonMessage(Exception $exception, $statusCode = null) |
|
| 99 | + protected function getJsonMessage( Exception $exception, $statusCode = null ) |
|
| 101 | 100 | { |
| 102 | 101 | |
| 103 | - $result = method_exists($exception, 'getJsonMessage') ? $exception->getJsonMessage() : |
|
| 104 | - ['message' => $exception->getMessage()]; |
|
| 102 | + $result = method_exists($exception, 'getJsonMessage') ? $exception->getJsonMessage() : ['message' => $exception->getMessage()]; |
|
| 105 | 103 | |
| 106 | - if ($exception instanceof ValidationException) { |
|
| 104 | + if ( $exception instanceof ValidationException ) { |
|
| 107 | 105 | $result["errors"] = $exception->errors(); |
| 108 | 106 | } |
| 109 | 107 | |
| 110 | - if (!array_key_exists('status', $result)) { |
|
| 108 | + if ( !array_key_exists('status', $result) ) { |
|
| 111 | 109 | $result['status'] = $statusCode !== null ? $statusCode : "false"; |
| 112 | 110 | } |
| 113 | 111 | |
| 114 | - if (!array_key_exists('name', $result)) { |
|
| 112 | + if ( !array_key_exists('name', $result) ) { |
|
| 115 | 113 | $result['name'] = $this->getExceptionName($exception); |
| 116 | 114 | } |
| 117 | 115 | |
@@ -11,8 +11,7 @@ discard block |
||
| 11 | 11 | * Class Handler |
| 12 | 12 | * @package Tfboe\FmLib\Exceptions |
| 13 | 13 | */ |
| 14 | -class Handler extends ExceptionHandler |
|
| 15 | -{ |
|
| 14 | +class Handler extends ExceptionHandler { |
|
| 16 | 15 | //<editor-fold desc="Fields"> |
| 17 | 16 | /** |
| 18 | 17 | * A list of the exception types that should not be reported. |
@@ -34,8 +33,7 @@ discard block |
||
| 34 | 33 | * @return \Illuminate\Http\Response |
| 35 | 34 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
| 36 | 35 | */ |
| 37 | - public function render($request, Exception $exception) |
|
| 38 | - { |
|
| 36 | + public function render($request, Exception $exception) { |
|
| 39 | 37 | //don't throw html exceptions always render using json |
| 40 | 38 | $statusCode = $this->getExceptionHTTPStatusCode($exception); |
| 41 | 39 | |
@@ -52,8 +50,7 @@ discard block |
||
| 52 | 50 | * @param Exception $exception the exception to extract from |
| 53 | 51 | * @return int|mixed the status code or 500 if no status code found |
| 54 | 52 | */ |
| 55 | - protected function getExceptionHTTPStatusCode(Exception $exception) |
|
| 56 | - { |
|
| 53 | + protected function getExceptionHTTPStatusCode(Exception $exception) { |
|
| 57 | 54 | // Not all Exceptions have a http status code |
| 58 | 55 | // We will give Error 500 if none found |
| 59 | 56 | if ($exception instanceof ValidationException) { |
@@ -97,8 +94,7 @@ discard block |
||
| 97 | 94 | * @param string|null $statusCode the status code or null if unknown |
| 98 | 95 | * @return array containing the infos status and message |
| 99 | 96 | */ |
| 100 | - protected function getJsonMessage(Exception $exception, $statusCode = null) |
|
| 101 | - { |
|
| 97 | + protected function getJsonMessage(Exception $exception, $statusCode = null) { |
|
| 102 | 98 | |
| 103 | 99 | $result = method_exists($exception, 'getJsonMessage') ? $exception->getJsonMessage() : |
| 104 | 100 | ['message' => $exception->getMessage()]; |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * Created by PhpStorm. |
| 5 | 5 | * User: benedikt |
@@ -16,8 +16,7 @@ |
||
| 16 | 16 | * Class ExceptionNames |
| 17 | 17 | * @package Tfboe\FmLib\Exceptions |
| 18 | 18 | */ |
| 19 | -abstract class ExceptionNames extends BasicEnum |
|
| 20 | -{ |
|
| 19 | +abstract class ExceptionNames extends BasicEnum { |
|
| 21 | 20 | //<editor-fold desc="Fields"> |
| 22 | 21 | const AUTHENTICATION_EXCEPTION = "AuthenticationException"; |
| 23 | 22 | const DUPLICATE_EXCEPTION = "DuplicateException"; |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * Created by PhpStorm. |
| 5 | 5 | * User: benedikt |
@@ -14,6 +14,5 @@ |
||
| 14 | 14 | * Class PreconditionFailedException |
| 15 | 15 | * @package Tfboe\FmLib\Exceptions |
| 16 | 16 | */ |
| 17 | -class PreconditionFailedException extends AbstractException |
|
| 18 | -{ |
|
| 17 | +class PreconditionFailedException extends AbstractException { |
|
| 19 | 18 | } |
| 20 | 19 | \ No newline at end of file |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | public function __construct($message = "", Throwable $previous = null) |
| 28 | 28 | { |
| 29 | - parent::__construct($message, 401, $previous); |
|
| 29 | + parent::__construct($message, 401, $previous); |
|
| 30 | 30 | } |
| 31 | 31 | //</editor-fold desc="Constructor"> |
| 32 | 32 | } |
| 33 | 33 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * Created by PhpStorm. |
| 5 | 5 | * User: benedikt |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * @param string $message |
| 25 | 25 | * @param Throwable|null $previous |
| 26 | 26 | */ |
| 27 | - public function __construct($message = "", Throwable $previous = null) |
|
| 27 | + public function __construct( $message = "", Throwable $previous = null ) |
|
| 28 | 28 | { |
| 29 | 29 | parent::__construct($message, 401, $previous); |
| 30 | 30 | } |
@@ -16,16 +16,14 @@ |
||
| 16 | 16 | * Class AuthenticationException |
| 17 | 17 | * @package Tfboe\FmLib\Exceptions |
| 18 | 18 | */ |
| 19 | -class AuthenticationException extends AbstractException |
|
| 20 | -{ |
|
| 19 | +class AuthenticationException extends AbstractException { |
|
| 21 | 20 | //<editor-fold desc="Constructor"> |
| 22 | 21 | /** |
| 23 | 22 | * AuthenticationException constructor. |
| 24 | 23 | * @param string $message |
| 25 | 24 | * @param Throwable|null $previous |
| 26 | 25 | */ |
| 27 | - public function __construct($message = "", Throwable $previous = null) |
|
| 28 | - { |
|
| 26 | + public function __construct($message = "", Throwable $previous = null) { |
|
| 29 | 27 | parent::__construct($message, 401, $previous); |
| 30 | 28 | } |
| 31 | 29 | //</editor-fold desc="Constructor"> |
@@ -23,15 +23,15 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | public function __construct($value, ?string $enumName = null, string $valueFunction = "getValues") |
| 25 | 25 | { |
| 26 | - $message = "The following value is not valid: " . json_encode($value); |
|
| 27 | - if ($enumName != null && method_exists($enumName, $valueFunction)) { |
|
| 28 | - /** @var mixed[] $values */ |
|
| 29 | - $values = call_user_func([$enumName, $valueFunction]); |
|
| 30 | - assert(!in_array($value, $values, true)); |
|
| 31 | - $message .= " in " . $enumName . ". Possible values: " . |
|
| 32 | - implode(', ', array_map("json_encode", $values)) . "."; |
|
| 33 | - } |
|
| 34 | - parent::__construct($message); |
|
| 26 | + $message = "The following value is not valid: " . json_encode($value); |
|
| 27 | + if ($enumName != null && method_exists($enumName, $valueFunction)) { |
|
| 28 | + /** @var mixed[] $values */ |
|
| 29 | + $values = call_user_func([$enumName, $valueFunction]); |
|
| 30 | + assert(!in_array($value, $values, true)); |
|
| 31 | + $message .= " in " . $enumName . ". Possible values: " . |
|
| 32 | + implode(', ', array_map("json_encode", $values)) . "."; |
|
| 33 | + } |
|
| 34 | + parent::__construct($message); |
|
| 35 | 35 | } |
| 36 | 36 | //</editor-fold desc="Constructor"> |
| 37 | 37 | } |
| 38 | 38 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * Created by PhpStorm. |
| 5 | 5 | * User: benedikt |
@@ -21,15 +21,15 @@ discard block |
||
| 21 | 21 | * @param string|null $enumName the corresponding enum class name or null |
| 22 | 22 | * @param string $valueFunction the function to call on the enum class to get the list of possible values |
| 23 | 23 | */ |
| 24 | - public function __construct($value, ?string $enumName = null, string $valueFunction = "getValues") |
|
| 24 | + public function __construct( $value, ?string $enumName = null, string $valueFunction = "getValues" ) |
|
| 25 | 25 | { |
| 26 | - $message = "The following value is not valid: " . json_encode($value); |
|
| 27 | - if ($enumName != null && method_exists($enumName, $valueFunction)) { |
|
| 26 | + $message = "The following value is not valid: ".json_encode($value); |
|
| 27 | + if ( $enumName != null && method_exists($enumName, $valueFunction) ) { |
|
| 28 | 28 | /** @var mixed[] $values */ |
| 29 | 29 | $values = call_user_func([$enumName, $valueFunction]); |
| 30 | 30 | assert(!in_array($value, $values, true)); |
| 31 | - $message .= " in " . $enumName . ". Possible values: " . |
|
| 32 | - implode(', ', array_map("json_encode", $values)) . "."; |
|
| 31 | + $message .= " in ".$enumName.". Possible values: ". |
|
| 32 | + implode(', ', array_map("json_encode", $values))."."; |
|
| 33 | 33 | } |
| 34 | 34 | parent::__construct($message); |
| 35 | 35 | } |
@@ -13,16 +13,14 @@ |
||
| 13 | 13 | * Class AuthenticationException |
| 14 | 14 | * @package Tfboe\FmLib\Exceptions |
| 15 | 15 | */ |
| 16 | -class ValueNotValid extends AbstractException |
|
| 17 | -{ |
|
| 16 | +class ValueNotValid extends AbstractException { |
|
| 18 | 17 | //<editor-fold desc="Constructor"> |
| 19 | 18 | /** |
| 20 | 19 | * @param mixed $value |
| 21 | 20 | * @param string|null $enumName the corresponding enum class name or null |
| 22 | 21 | * @param string $valueFunction the function to call on the enum class to get the list of possible values |
| 23 | 22 | */ |
| 24 | - public function __construct($value, ?string $enumName = null, string $valueFunction = "getValues") |
|
| 25 | - { |
|
| 23 | + public function __construct($value, ?string $enumName = null, string $valueFunction = "getValues") { |
|
| 26 | 24 | $message = "The following value is not valid: " . json_encode($value); |
| 27 | 25 | if ($enumName != null && method_exists($enumName, $valueFunction)) { |
| 28 | 26 | /** @var mixed[] $values */ |
@@ -36,10 +36,10 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public function __construct(string $className, string $propertyName, string $accessorMethod) |
| 38 | 38 | { |
| 39 | - $this->className = $className; |
|
| 40 | - $this->propertyName = $propertyName; |
|
| 41 | - $this->accessorMethod = $accessorMethod; |
|
| 42 | - parent::__construct("An object of the class $className had no property $propertyName via $accessorMethod"); |
|
| 39 | + $this->className = $className; |
|
| 40 | + $this->propertyName = $propertyName; |
|
| 41 | + $this->accessorMethod = $accessorMethod; |
|
| 42 | + parent::__construct("An object of the class $className had no property $propertyName via $accessorMethod"); |
|
| 43 | 43 | } |
| 44 | 44 | //</editor-fold desc="Constructor"> |
| 45 | 45 | |
@@ -50,12 +50,12 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | public function getJsonMessage() |
| 52 | 52 | { |
| 53 | - return [ |
|
| 54 | - 'message' => "Missing property in object", |
|
| 55 | - 'className' => $this->className, |
|
| 56 | - 'propertyName' => $this->propertyName, |
|
| 57 | - 'accessorMethod' => $this->accessorMethod |
|
| 58 | - ]; |
|
| 53 | + return [ |
|
| 54 | + 'message' => "Missing property in object", |
|
| 55 | + 'className' => $this->className, |
|
| 56 | + 'propertyName' => $this->propertyName, |
|
| 57 | + 'accessorMethod' => $this->accessorMethod |
|
| 58 | + ]; |
|
| 59 | 59 | } |
| 60 | 60 | //</editor-fold desc="Public Methods"> |
| 61 | 61 | } |
| 62 | 62 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * Created by PhpStorm. |
| 5 | 5 | * User: benedikt |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @param string $propertyName |
| 35 | 35 | * @param string $accessorMethod |
| 36 | 36 | */ |
| 37 | - public function __construct(string $className, string $propertyName, string $accessorMethod) |
|
| 37 | + public function __construct( string $className, string $propertyName, string $accessorMethod ) |
|
| 38 | 38 | { |
| 39 | 39 | $this->className = $className; |
| 40 | 40 | $this->propertyName = $propertyName; |
@@ -13,8 +13,7 @@ discard block |
||
| 13 | 13 | * Class MethodNotExistingException |
| 14 | 14 | * @package Tfboe\FmLib\Exceptions |
| 15 | 15 | */ |
| 16 | -class PropertyNotExistingException extends AbstractException |
|
| 17 | -{ |
|
| 16 | +class PropertyNotExistingException extends AbstractException { |
|
| 18 | 17 | //<editor-fold desc="Fields"> |
| 19 | 18 | /** @var string */ |
| 20 | 19 | private $propertyName; |
@@ -34,8 +33,7 @@ discard block |
||
| 34 | 33 | * @param string $propertyName |
| 35 | 34 | * @param string $accessorMethod |
| 36 | 35 | */ |
| 37 | - public function __construct(string $className, string $propertyName, string $accessorMethod) |
|
| 38 | - { |
|
| 36 | + public function __construct(string $className, string $propertyName, string $accessorMethod) { |
|
| 39 | 37 | $this->className = $className; |
| 40 | 38 | $this->propertyName = $propertyName; |
| 41 | 39 | $this->accessorMethod = $accessorMethod; |
@@ -48,8 +46,7 @@ discard block |
||
| 48 | 46 | * Gets a json representation of the exception |
| 49 | 47 | * @return array |
| 50 | 48 | */ |
| 51 | - public function getJsonMessage() |
|
| 52 | - { |
|
| 49 | + public function getJsonMessage() { |
|
| 53 | 50 | return [ |
| 54 | 51 | 'message' => "Missing property in object", |
| 55 | 52 | 'className' => $this->className, |
@@ -30,11 +30,11 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | public function __construct($referenceValue, string $referenceName) |
| 32 | 32 | { |
| 33 | - $this->referenceName = $referenceName; |
|
| 34 | - $this->referenceValue = $referenceValue; |
|
| 33 | + $this->referenceName = $referenceName; |
|
| 34 | + $this->referenceValue = $referenceValue; |
|
| 35 | 35 | |
| 36 | - $message = "The reference $referenceValue of $referenceName is not existing!"; |
|
| 37 | - parent::__construct($message, 409); |
|
| 36 | + $message = "The reference $referenceValue of $referenceName is not existing!"; |
|
| 37 | + parent::__construct($message, 409); |
|
| 38 | 38 | } |
| 39 | 39 | //</editor-fold desc="Constructor"> |
| 40 | 40 | |
@@ -45,11 +45,11 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function getJsonMessage() |
| 47 | 47 | { |
| 48 | - return [ |
|
| 49 | - 'message' => "Reference Exception", |
|
| 50 | - 'referenceValue' => $this->referenceValue, |
|
| 51 | - 'referenceName' => $this->referenceName |
|
| 52 | - ]; |
|
| 48 | + return [ |
|
| 49 | + 'message' => "Reference Exception", |
|
| 50 | + 'referenceValue' => $this->referenceValue, |
|
| 51 | + 'referenceName' => $this->referenceName |
|
| 52 | + ]; |
|
| 53 | 53 | } |
| 54 | 54 | //</editor-fold desc="Public Methods"> |
| 55 | 55 | } |
| 56 | 56 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * Created by PhpStorm. |
| 5 | 5 | * User: benedikt |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @param $referenceValue |
| 29 | 29 | * @param string $referenceName |
| 30 | 30 | */ |
| 31 | - public function __construct($referenceValue, string $referenceName) |
|
| 31 | + public function __construct( $referenceValue, string $referenceName ) |
|
| 32 | 32 | { |
| 33 | 33 | $this->referenceName = $referenceName; |
| 34 | 34 | $this->referenceValue = $referenceValue; |
@@ -13,8 +13,7 @@ discard block |
||
| 13 | 13 | * Class DuplicateException |
| 14 | 14 | * @package Tfboe\FmLib\Exceptions |
| 15 | 15 | */ |
| 16 | -class ReferenceException extends AbstractException |
|
| 17 | -{ |
|
| 16 | +class ReferenceException extends AbstractException { |
|
| 18 | 17 | //<editor-fold desc="Fields"> |
| 19 | 18 | /** @var mixed */ |
| 20 | 19 | private $referenceValue; |
@@ -28,8 +27,7 @@ discard block |
||
| 28 | 27 | * @param $referenceValue |
| 29 | 28 | * @param string $referenceName |
| 30 | 29 | */ |
| 31 | - public function __construct($referenceValue, string $referenceName) |
|
| 32 | - { |
|
| 30 | + public function __construct($referenceValue, string $referenceName) { |
|
| 33 | 31 | $this->referenceName = $referenceName; |
| 34 | 32 | $this->referenceValue = $referenceValue; |
| 35 | 33 | |
@@ -43,8 +41,7 @@ discard block |
||
| 43 | 41 | * Gets a json representation of the exception |
| 44 | 42 | * @return array |
| 45 | 43 | */ |
| 46 | - public function getJsonMessage() |
|
| 47 | - { |
|
| 44 | + public function getJsonMessage() { |
|
| 48 | 45 | return [ |
| 49 | 46 | 'message' => "Reference Exception", |
| 50 | 47 | 'referenceValue' => $this->referenceValue, |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * Created by PhpStorm. |
| 5 | 5 | * User: benedikt |
@@ -14,7 +14,6 @@ |
||
| 14 | 14 | * Class AbstractException |
| 15 | 15 | * @package Tfboe\FmLib\Exceptions |
| 16 | 16 | */ |
| 17 | -class AbstractException extends \Exception |
|
| 18 | -{ |
|
| 17 | +class AbstractException extends \Exception { |
|
| 19 | 18 | |
| 20 | 19 | } |
| 21 | 20 | \ No newline at end of file |