Skip to content

Commit

Permalink
refactor: use property promotion in other classes
Browse files Browse the repository at this point in the history
  • Loading branch information
JaZo committed Mar 13, 2024
1 parent 0d9c9a0 commit f4df2c3
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 44 deletions.
5 changes: 1 addition & 4 deletions src/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions src/Exceptions/RequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 1 addition & 4 deletions src/Parsers/DetourParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/Parsers/RestrictionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 5 additions & 20 deletions src/Parsers/SituationParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f4df2c3

Please sign in to comment.