fix: 🐛 reorder function parameters to avoid PHP 8.0+ optional parameter warning
This commit is contained in:
parent
36494a7944
commit
da8074c5a4
5 changed files with 13 additions and 14 deletions
|
|
@ -180,13 +180,13 @@ class Handler extends ExceptionHandler
|
|||
): JsonResponse {
|
||||
if (Helper::isRequestForApiV2($request)) {
|
||||
return (new V2ApiResponse(
|
||||
ApiStatus::KO,
|
||||
(object)array_merge($data, ['message' => $message, 'code' => $apiCode]),
|
||||
ApiStatus::KO
|
||||
))->toResponse($request)->setStatusCode($httpCode);
|
||||
}
|
||||
return (new V4ApiResponse(
|
||||
ApiStatus::KO,
|
||||
(object)array_merge($data, ['message' => $message, 'code' => $apiCode]),
|
||||
ApiStatus::KO
|
||||
))->toResponse($request)->setStatusCode($httpCode);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,9 +57,8 @@ class ApiResponse
|
|||
$status = intval($response->getStatusCode() / 100) == 2 ? ApiStatus::OK : ApiStatus::KO;
|
||||
|
||||
if (Helper::isRequestForApiV2($request)) {
|
||||
return $response->setData(new V2ApiResponse((object)$data, $status));
|
||||
return $response->setData(new V2ApiResponse($status, (object)$data));
|
||||
}
|
||||
|
||||
return $response->setData(new V4ApiResponse((object)$data, $status));
|
||||
return $response->setData(new V4ApiResponse($status, (object)$data));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,10 +16,10 @@ class ApiResponse extends JsonResource
|
|||
protected $status;
|
||||
|
||||
/**
|
||||
* @param \stdClass|null $data
|
||||
* @param \App\Enums\ApiStatus $status
|
||||
* @param \stdClass|null $data
|
||||
*/
|
||||
public function __construct(stdClass|null $data = null, ApiStatus $status)
|
||||
public function __construct(ApiStatus $status, stdClass|null $data = null)
|
||||
{
|
||||
$this->status = $status;
|
||||
$this->data = $data;
|
||||
|
|
|
|||
|
|
@ -16,10 +16,10 @@ class ApiResponse extends JsonResource
|
|||
protected $status;
|
||||
|
||||
/**
|
||||
* @param \stdClass|null $data
|
||||
* @param \App\Enums\ApiStatus $status
|
||||
* @param \stdClass|null $data
|
||||
*/
|
||||
public function __construct(stdClass|null $data = null, ApiStatus $status)
|
||||
public function __construct(ApiStatus $status, stdClass|null $data = null)
|
||||
{
|
||||
$this->status = $status;
|
||||
$this->data = $data;
|
||||
|
|
@ -36,8 +36,8 @@ class ApiResponse extends JsonResource
|
|||
{
|
||||
//phpcs:enable
|
||||
return [
|
||||
'status' => $this->status->value(),
|
||||
'data' => (array)($this->data ?? []),
|
||||
'status' => $this->status->value(),
|
||||
'data' => (array)($this->data ?? []),
|
||||
'version' => config('api.version')
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class SingleOptinTest extends ApiBase
|
|||
|
||||
/**
|
||||
* Test set single optin on with answer associated.
|
||||
* route: apiV2.optin
|
||||
* route: apiV4.optin
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
|
@ -57,7 +57,7 @@ class SingleOptinTest extends ApiBase
|
|||
// * Make sure a customer answer is set.
|
||||
$firstAnswer = $questions->first()->answers->first();
|
||||
|
||||
$response = $this->callApiWithToken($service, 'post', route('apiV2.optin'), [
|
||||
$response = $this->callApiWithToken($service, 'post', route('apiV4.optin'), [
|
||||
'email' => 'singleoptin@hotmail.fr',
|
||||
'opt_in' => 1,
|
||||
'answer_id' => [$firstAnswer->getkey()],
|
||||
|
|
@ -134,7 +134,7 @@ class SingleOptinTest extends ApiBase
|
|||
public function testSingleOptinShouldFailIfAnswerIdDoesntExist(): void
|
||||
{
|
||||
$service = Service::query()->firstOrFail();
|
||||
$response = $this->callApiWithToken($service, 'post', route('apiV2.optin'), [
|
||||
$response = $this->callApiWithToken($service, 'post', route('apiV4.optin'), [
|
||||
'email' => 'singleoptin@hotmail.fr',
|
||||
'opt_in' => 1,
|
||||
'answer_id' => [0],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue