From f4df2c37615b7d876538f216c52c4d678fcb107d Mon Sep 17 00:00:00 2001 From: Jasper Zonneveld Date: Wed, 13 Mar 2024 11:16:17 +0100 Subject: [PATCH] refactor: use property promotion in other classes --- src/Api/AbstractApi.php | 5 +---- src/Client.php | 5 +---- src/Exceptions/RequestException.php | 10 ++-------- src/Parsers/DetourParser.php | 5 +---- src/Parsers/RestrictionParser.php | 5 +---- src/Parsers/SituationParser.php | 25 +++++-------------------- 6 files changed, 11 insertions(+), 44 deletions(-) diff --git a/src/Api/AbstractApi.php b/src/Api/AbstractApi.php index 00b5964..3e91f3d 100644 --- a/src/Api/AbstractApi.php +++ b/src/Api/AbstractApi.php @@ -9,11 +9,8 @@ abstract class AbstractApi { - protected Client $client; - - public function __construct(Client $client) + public function __construct(protected Client $client) { - $this->client = $client; } protected function getClient(): Client diff --git a/src/Client.php b/src/Client.php index 999570b..b8c7ed1 100644 --- a/src/Client.php +++ b/src/Client.php @@ -9,11 +9,8 @@ class Client { - protected HttpClient $httpClient; - - public function __construct(HttpClient $httpClient) + public function __construct(protected HttpClient $httpClient) { - $this->httpClient = $httpClient; } public static function create(string $username, string $password, string $clientId = 'melvin-frontend-test'): self diff --git a/src/Exceptions/RequestException.php b/src/Exceptions/RequestException.php index ace94df..04a1434 100644 --- a/src/Exceptions/RequestException.php +++ b/src/Exceptions/RequestException.php @@ -9,20 +9,14 @@ class RequestException extends \RuntimeException implements Exception { - private RequestInterface $request; - - private ?ResponseInterface $response; - public function __construct( string $message, - RequestInterface $request, - ?ResponseInterface $response = null, + private RequestInterface $request, + private ?ResponseInterface $response = null, ?\Throwable $previous = null ) { $code = $response ? $response->getStatusCode() : 0; parent::__construct($message, $code, $previous); - $this->request = $request; - $this->response = $response; } public static function create( diff --git a/src/Parsers/DetourParser.php b/src/Parsers/DetourParser.php index ef8d3b8..26c0e7c 100644 --- a/src/Parsers/DetourParser.php +++ b/src/Parsers/DetourParser.php @@ -12,11 +12,8 @@ class DetourParser { - protected GeometryParser $geometryParser; - - public function __construct(GeometryParser $geometryParser) + public function __construct(protected GeometryParser $geometryParser) { - $this->geometryParser = $geometryParser; } public function parse(\stdClass $object, int $index): Detour diff --git a/src/Parsers/RestrictionParser.php b/src/Parsers/RestrictionParser.php index a68a6e4..86cedca 100644 --- a/src/Parsers/RestrictionParser.php +++ b/src/Parsers/RestrictionParser.php @@ -16,11 +16,8 @@ class RestrictionParser { - protected GeometryParser $geometryParser; - - public function __construct(GeometryParser $geometryParser) + public function __construct(protected GeometryParser $geometryParser) { - $this->geometryParser = $geometryParser; } public function parse(\stdClass $object, int $index): Restriction diff --git a/src/Parsers/SituationParser.php b/src/Parsers/SituationParser.php index 58b6c56..5a9d9e8 100644 --- a/src/Parsers/SituationParser.php +++ b/src/Parsers/SituationParser.php @@ -22,28 +22,13 @@ class SituationParser { - protected GeometryParser $geometryParser; - - protected PeriodParser $periodParser; - - protected AttachmentParser $attachmentParser; - - protected RestrictionParser $restrictionParser; - - protected DetourParser $detourParser; - public function __construct( - GeometryParser $geometryParser, - PeriodParser $periodParser, - AttachmentParser $attachmentParser, - RestrictionParser $restrictionParser, - DetourParser $detourParser + protected GeometryParser $geometryParser, + protected PeriodParser $periodParser, + protected AttachmentParser $attachmentParser, + protected RestrictionParser $restrictionParser, + protected DetourParser $detourParser ) { - $this->geometryParser = $geometryParser; - $this->periodParser = $periodParser; - $this->attachmentParser = $attachmentParser; - $this->restrictionParser = $restrictionParser; - $this->detourParser = $detourParser; } public function parse(\stdClass $object, array $restrictions, array $detours = []): Situation