Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump phpstan level #16

Merged
merged 6 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ includes:
- ./tools/phpstan/vendor/phpstan/phpstan-symfony/extension.neon

parameters:
level: 5
level: max
paths:
- src
- tests
6 changes: 3 additions & 3 deletions src/HelloassoClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Helloasso\Service\DirectoryService;
use Helloasso\Service\PaymentService;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\SerializerInterface;

class HelloassoClient
{
Expand All @@ -23,7 +22,7 @@ class HelloassoClient
public DirectoryService $directory;

public function __construct(
private readonly SerializerInterface|DenormalizerInterface $serializer,
private readonly DenormalizerInterface $serializer,
ApiCaller $apiCaller,
string $organizationSlug,
) {
Expand All @@ -40,6 +39,7 @@ public function __construct(
public function decodeEvent(string $eventData): Event
{
try {
/** @var array{eventType?: string, data?: array<string, mixed>, metadata?: array<string, mixed>} */
$event = json_decode($eventData, true, 512, \JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new InvalidValueException('Unable to json_decode given event.');
Expand All @@ -59,7 +59,7 @@ public function decodeEvent(string $eventData): Event
Event::EVENT_TYPE_FORM => FormPublicModel::class,
Event::EVENT_TYPE_ORDER => OrderDetail::class,
Event::EVENT_TYPE_PAYMENT => PaymentDetail::class,
default => throw new InvalidValueException('eventType "'.$eventType.'" not supported')
default => throw new InvalidValueException('eventType "'.$eventType.'" not supported'),
};

return (new Event())
Expand Down
20 changes: 17 additions & 3 deletions src/Http/ApiCaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,20 @@ public function __construct(
/**
* @template T of HelloassoObject
*
* @param class-string<T> $responseClassType
* @param array<string, mixed> $options HttpClient request options
* @param array<mixed>|HelloassoObject|null $body The body of the request to make
* @param class-string<T> $responseClassType
* @param array<string, mixed> $options HttpClient request options
*
* @return T
*/
public function post(string $url, array|HelloassoObject|null $body, string $responseClassType, ?array $options = []): HelloassoObject
{
if (null === $options) {
@trigger_error(__METHOD__.'(): Passing null for $options is deprecated and will be removed in v2.0.0', \E_USER_DEPRECATED);

$options = [];
}

$response = $this->httpClient->request(Request::METHOD_POST, $url, array_merge([
'auth_bearer' => $this->tokenManager->getAccessToken(),
'body' => $this->serializer->serialize($body, 'json'),
Expand All @@ -40,12 +47,19 @@ public function post(string $url, array|HelloassoObject|null $body, string $resp
/**
* @template T of HelloassoObject
*
* @param class-string<T> $responseClassType
* @param class-string<T> $responseClassType
* @param array<string, mixed> $options
*
* @return T
*/
public function get(string $url, string $responseClassType, ?array $options = []): HelloassoObject
{
if (null === $options) {
@trigger_error(__METHOD__.'(): Passing null for $options is deprecated and will be removed in v2.0.0', \E_USER_DEPRECATED);

$options = [];
}

$response = $this->httpClient->request(Request::METHOD_GET, $url, array_merge([
'auth_bearer' => $this->tokenManager->getAccessToken(),
], $options));
Expand Down
5 changes: 4 additions & 1 deletion src/Http/ResponseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public function deserializeResponse(ResponseInterface $response, string $respons
*/
public function deserializeResponseContent(string $content, string $responseClassType): HelloassoObject
{
return $this->serializer->deserialize($content, $responseClassType, 'json');
/** @var T $object */
$object = $this->serializer->deserialize($content, $responseClassType, 'json');

return $object;
}
}
6 changes: 3 additions & 3 deletions src/Http/TokenManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ public function __construct(
public function getAccessToken(): string
{
if (null === $this->accessToken) {
$this->retrieveAccessToken();
$this->accessToken = $this->retrieveAccessToken();
}

return $this->accessToken;
}

private function retrieveAccessToken(): void
private function retrieveAccessToken(): string
{
$response = $this->httpClient->request(Request::METHOD_POST, '/oauth2/token', [
'body' => [
Expand All @@ -44,6 +44,6 @@ private function retrieveAccessToken(): void

$credentials = $this->responseHandler->deserializeResponse($response, ClientCredentials::class);

$this->accessToken = $credentials->getAccessToken();
return $credentials->getAccessToken();
}
}
6 changes: 6 additions & 0 deletions src/Models/Accounts/ApiClients/ApiClientModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,17 @@ public function setPartnerName(string $partnerName): self
return $this;
}

/**
* @return string[]
*/
public function getPrivileges(): array
{
return $this->privileges;
}

/**
* @param string[] $privileges
*/
public function setPrivileges(array $privileges): self
{
$this->privileges = $privileges;
Expand Down
9 changes: 9 additions & 0 deletions src/Models/Carts/CheckoutIntentResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class CheckoutIntentResponse implements HelloassoObject
*/
private string $redirectUrl;

/**
* @var array<string, mixed>
*/
private array $metadata;

private ?OrderDetail $order = null;
Expand Down Expand Up @@ -47,11 +50,17 @@ public function setRedirectUrl(string $redirectUrl): self
return $this;
}

/**
* @return array<string, mixed>
*/
public function getMetadata(): array
{
return $this->metadata;
}

/**
* @param array<string, mixed> $metadata
*/
public function setMetadata(array $metadata): self
{
$this->metadata = $metadata;
Expand Down
22 changes: 14 additions & 8 deletions src/Models/Carts/InitCheckoutBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@ class InitCheckoutBody implements HelloassoObject
/**
* @var array<CheckoutTerm> Tableau contenant les échéances éventuelles
*/
private ?array $terms;
private array $terms = [];

/**
* Informations concernant le payeur.
*/
private ?CheckoutPayer $payer;

/**
* @var array<array> Informations partenaire.
* Ces infos ne seront pas transmises à l’association ou au contributeur.
* Elles vous seront renvoyées avec la commande ou le paiement lors de la notification,
* ou quand vous voudrez récupérer le détail du paiement ou de la commande.
* @var array<string, mixed> Informations partenaire.
* Ces infos ne seront pas transmises à l’association ou au contributeur.
* Elles vous seront renvoyées avec la commande ou le paiement lors de la notification,
* ou quand vous voudrez récupérer le détail du paiement ou de la commande.
*/
private array $metadata;

Expand All @@ -84,7 +84,7 @@ class InitCheckoutBody implements HelloassoObject
*
* @example 101
*/
private ?string $trackingParameter;
private ?string $trackingParameter = null;

public function getTotalAmount(): int
{
Expand Down Expand Up @@ -192,9 +192,9 @@ public function setContainsDonation(bool $containsDonation): self
}

/**
* @return array<CheckoutTerm>|null
* @return array<CheckoutTerm>
*/
public function getTerms(): ?array
public function getTerms(): array
{
return $this->terms;
}
Expand All @@ -218,11 +218,17 @@ public function setPayer(?CheckoutPayer $payer): self
return $this;
}

/**
* @return array<string, mixed>
*/
public function getMetadata(): array
{
return $this->metadata;
}

/**
* @param array<string, mixed> $metadata
*/
public function setMetadata(array $metadata): self
{
$this->metadata = $metadata;
Expand Down
5 changes: 5 additions & 0 deletions src/Models/Common/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public function getData(): array

/**
* @param T[] $data
*
* @return self<T>
*/
public function setData(array $data): self
{
Expand All @@ -46,6 +48,9 @@ public function getPagination(): PaginationModel
return $this->pagination;
}

/**
* @return self<T>
*/
public function setPagination(PaginationModel $pagination): self
{
$this->pagination = $pagination;
Expand Down
Loading
Loading