Skip to content

Commit

Permalink
Faсtory methods now returns self instead of static (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
gomzyakov authored Oct 22, 2020
1 parent bc8197e commit 97e55cb
Show file tree
Hide file tree
Showing 25 changed files with 39 additions and 64 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ The format is based on [Keep a Changelog][keepachangelog] and this project adher
- Method `ClientInterface::userReports` now takes optional object `UserReportsParams` as parameter
- Method `ClientInterface::userReport` now takes object `UserReportParams` as parameter
- Method `ClientInterface::userReportRefresh` now takes object `UserReportRefreshParams` as parameter
- Faсtory methods now returns `self` instead of `static` in classes:
- `Avtocod\B2BApi\Exceptions\*`
- `Avtocod\B2BApi\Responses\Entities\*`
- `Avtocod\B2BApi\Responses\*Response`

### Fixed

Expand Down
7 changes: 0 additions & 7 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,3 @@ parameters:
level: 'max'
paths:
- src
ignoreErrors:
- # Replacing with `return new self` or classes finalization requires major version upping. Make it on next major release
message: '#Unsafe usage of new static\(\)#'
paths:
- src/Responses/*Response.php
- src/Responses/Entities/*.php
- src/Exceptions/*Exception.php
2 changes: 1 addition & 1 deletion src/Exceptions/BadResponseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function wrongJson(ResponseInterface $http_response,
?string $message = null,
?Throwable $prev = null): self
{
return new static($http_response, $message ?? 'Server sent wrong json', 0, $prev);
return new self($http_response, $message ?? 'Server sent wrong json', 0, $prev);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/TokenParserException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class TokenParserException extends RuntimeException implements B2BApiExceptionIn
*/
public static function cannotParseToken(?string $message = null, int $code = 0, ?Throwable $prev = null): self
{
return new static($message ?? 'Cannot parse token', $code, $prev);
return new self($message ?? 'Cannot parse token', $code, $prev);
}
}
2 changes: 1 addition & 1 deletion src/Responses/DevPingResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static function fromHttpResponse(HttpResponseInterface $response): self
throw BadResponseException::wrongJson($response, $e->getMessage(), $e);
}

return new static(
return new self(
$raw_response,
$as_array['value'],
$as_array['in'],
Expand Down
2 changes: 1 addition & 1 deletion src/Responses/DevTokenResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public static function fromHttpResponse(HttpResponseInterface $response): self
throw BadResponseException::wrongJson($response, $e->getMessage(), $e);
}

return new static(
return new self(
$raw_response,
$as_array['user'],
$as_array['pass'],
Expand Down
6 changes: 2 additions & 4 deletions src/Responses/Entities/Balance.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,11 @@ public function __construct(string $report_type_uid,
}

/**
* @param array<string, mixed> $data
*
* @return self
* @inheritDoc
*/
public static function fromArray(array $data): self
{
return new static(
return new self(
$data['report_type_uid'],
$data['balance_type'],
$data['quote_init'],
Expand Down
4 changes: 2 additions & 2 deletions src/Responses/Entities/CanCreateSelfFromArrayInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ interface CanCreateSelfFromArrayInterface
/**
* Create self using array of data.
*
* @param array<mixed> $data
* @param array<string, mixed> $data
*
* @return self|$this
* @return self
*/
public static function fromArray(array $data);
}
6 changes: 2 additions & 4 deletions src/Responses/Entities/CleanOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ public function __construct(?int $process_response, ?int $process_request, ?int
}

/**
* @param array<string, int|null> $data
*
* @return self
* @inheritDoc
*/
public static function fromArray(array $data): self
{
return new static(
return new self(
$data['Process_Response'] ?? null,
$data['Process_Request'] ?? null,
$data['ReportLog'] ?? null
Expand Down
6 changes: 2 additions & 4 deletions src/Responses/Entities/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,11 @@ public function __construct(string $uid,
}

/**
* @param array<string, mixed> $data
*
* @return self
* @inheritDoc
*/
public static function fromArray(array $data): self
{
return new static(
return new self(
$data['uid'],
$data['comment'],
$data['name'],
Expand Down
6 changes: 2 additions & 4 deletions src/Responses/Entities/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,11 @@ public function __construct(string $uid,
}

/**
* @param array<string, mixed> $data
*
* @return self
* @inheritDoc
*/
public static function fromArray(array $data): self
{
return new static(
return new self(
$data['uid'],
$data['comment'],
$data['name'],
Expand Down
6 changes: 2 additions & 4 deletions src/Responses/Entities/ReportMade.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ public function __construct(string $report_uid, bool $is_new, ?string $process_r
}

/**
* @param array<string, string|bool|null> $data
*
* @return self
* @inheritDoc
*/
public static function fromArray(array $data): self
{
return new static(
return new self(
$data['uid'],
$data['isnew'],
$data['process_request_uid'] ?? null,
Expand Down
6 changes: 2 additions & 4 deletions src/Responses/Entities/ReportQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ public function __construct(?string $type, ?string $body, ?array $data)
}

/**
* @param array<string, string|array<mixed>|null> $data
*
* @return self
* @inheritDoc
*/
public static function fromArray(array $data): self
{
return new static(
return new self(
$data['type'] ?? null,
$data['body'] ?? null,
$data['data'] ?? null
Expand Down
6 changes: 2 additions & 4 deletions src/Responses/Entities/ReportSourceState.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ public function __construct(string $name, string $state, ?array $data)
}

/**
* @param array<string, string|array<mixed>|null> $data
*
* @return self
* @inheritDoc
*/
public static function fromArray(array $data): self
{
return new static(
return new self(
$data['_id'] ?? $data['id'] ?? $data['name'],
$data['state'],
$data['data'] ?? null
Expand Down
6 changes: 2 additions & 4 deletions src/Responses/Entities/ReportState.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ public function __construct(array $source_states)
}

/**
* @param array<string, array<string, mixed>> $data
*
* @return self
* @inheritDoc
*/
public static function fromArray(array $data): self
{
return new static(
return new self(
\array_map(static function (array $report_data): ReportSourceState {
return ReportSourceState::fromArray($report_data);
}, $data['sources'])
Expand Down
6 changes: 2 additions & 4 deletions src/Responses/Entities/ReportType.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,11 @@ public function __construct(string $uid,
}

/**
* @param array<string, mixed> $data
*
* @return self
* @inheritDoc
*/
public static function fromArray(array $data): self
{
return new static(
return new self(
$data['uid'],
$data['comment'],
$data['name'],
Expand Down
6 changes: 2 additions & 4 deletions src/Responses/Entities/ReportTypeContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ public function __construct(array $sources, array $fields)
}

/**
* @param array<string, array<string>> $data
*
* @return self
* @inheritDoc
*/
public static function fromArray(array $data): self
{
return new static(
return new self(
$data['sources'],
$data['fields']
);
Expand Down
6 changes: 2 additions & 4 deletions src/Responses/Entities/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,11 @@ public function __construct(string $uid,
}

/**
* @param array<string, mixed> $data
*
* @return self
* @inheritDoc
*/
public static function fromArray(array $data): self
{
return new static(
return new self(
$data['uid'],
$data['comment'],
$data['contacts'],
Expand Down
2 changes: 1 addition & 1 deletion src/Responses/UserBalanceResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static function fromHttpResponse(HttpResponseInterface $response): self
return Balance::fromArray($balance_data);
}, $as_array['data']);

return new static(
return new self(
$raw_response,
$as_array['state'],
$as_array['size'],
Expand Down
2 changes: 1 addition & 1 deletion src/Responses/UserReportMakeResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static function fromHttpResponse(HttpResponseInterface $response): self
return ReportMade::fromArray($data);
}, $as_array['data']);

return new static(
return new self(
$raw_response,
$as_array['state'],
$as_array['size'],
Expand Down
2 changes: 1 addition & 1 deletion src/Responses/UserReportRefreshResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static function fromHttpResponse(HttpResponseInterface $response): self
return ReportMade::fromArray($data);
}, $as_array['data']);

return new static(
return new self(
$raw_response,
$as_array['state'],
$as_array['size'],
Expand Down
2 changes: 1 addition & 1 deletion src/Responses/UserReportResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static function fromHttpResponse(HttpResponseInterface $response): self
return Report::fromArray($data);
}, $as_array['data']);

return new static(
return new self(
$raw_response,
$as_array['state'],
$as_array['size'],
Expand Down
2 changes: 1 addition & 1 deletion src/Responses/UserReportTypesResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static function fromHttpResponse(HttpResponseInterface $response): self
return ReportType::fromArray($report_type_data);
}, $as_array['data']);

return new static(
return new self(
$raw_response,
$as_array['state'],
$as_array['size'],
Expand Down
2 changes: 1 addition & 1 deletion src/Responses/UserReportsResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static function fromHttpResponse(HttpResponseInterface $response): self
return Report::fromArray($report_data);
}, $as_array['data']);

return new static(
return new self(
$raw_response,
$as_array['state'],
$as_array['size'],
Expand Down
2 changes: 1 addition & 1 deletion src/Responses/UserResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static function fromHttpResponse(HttpResponseInterface $response): self
return User::fromArray($user_data);
}, $as_array['data']);

return new static(
return new self(
$raw_response,
$as_array['state'],
$as_array['size'],
Expand Down

0 comments on commit 97e55cb

Please sign in to comment.