From f312f49e19af68c8f1f6ba4aae1088d145b6bace Mon Sep 17 00:00:00 2001 From: Lorenzo Ruozzi Date: Mon, 10 Jun 2024 12:46:00 +0200 Subject: [PATCH] Add PHPStan --- .github/workflows/build.yml | 4 ++++ composer.json | 3 ++- phpstan.neon | 4 ++++ src/Api/EcRequest.php | 2 +- src/Notification/Request.php | 10 ++++++++-- src/Signature/DefaultSignatureHashingManager.php | 2 +- src/Signature/Signable.php | 3 +++ 7 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 phpstan.neon diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e98836f..d9228e8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,6 +45,10 @@ jobs: name: Run CS run: vendor/bin/phpcs --standard=PSR2 src/ + - + name: Run PHPStan + run: vendor/bin/phpstan analyse + - name: Run PHPSpec run: vendor/bin/phpspec run diff --git a/composer.json b/composer.json index 277c36e..cb8a63d 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,8 @@ }, "require-dev": { "squizlabs/php_codesniffer": "^3.7", - "phpspec/phpspec": "^7.3" + "phpspec/phpspec": "^7.3", + "phpstan/phpstan": "^1.11" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..d7f8277 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,4 @@ +parameters: + level: 6 + paths: + - src diff --git a/src/Api/EcRequest.php b/src/Api/EcRequest.php index 58db74b..e5a73e2 100644 --- a/src/Api/EcRequest.php +++ b/src/Api/EcRequest.php @@ -165,7 +165,7 @@ private function calculateMac(): string private function convertAmountToString(float $amount): string { - return str_pad((string)round($amount, 2)*100, 9, '0', STR_PAD_LEFT); + return str_pad((string) (round($amount, 2)*100), 9, '0', STR_PAD_LEFT); } private function validate(): void diff --git a/src/Notification/Request.php b/src/Notification/Request.php index c2e2d7e..2da5128 100644 --- a/src/Notification/Request.php +++ b/src/Notification/Request.php @@ -41,6 +41,9 @@ class Request implements Signed private ?string $scadenza_pan; + /** + * @param array $rawParams + */ private function __construct(array $rawParams) { $this->checkForMissingParameters($rawParams); @@ -68,7 +71,7 @@ private function __construct(array $rawParams) $this->session_id = $rawParams['session_id'] ?? null; } - public static function buildFromHttpRequest(ServerRequestInterface $request): static + public static function buildFromHttpRequest(ServerRequestInterface $request): self { if (strtoupper($request->getMethod()) === 'POST') { $rawParams = $request->getParsedBody(); @@ -76,7 +79,7 @@ public static function buildFromHttpRequest(ServerRequestInterface $request): st $rawParams = $request->getQueryParams(); } - return new static($rawParams); + return new self($rawParams); } public function getAlias(): string @@ -215,6 +218,9 @@ private function checkForMissingParameters(array $rawParams): void } } + /** + * @param array $rawParams + */ private function validateParameters(array $rawParams): void { $rawAmount = $rawParams['importo']; diff --git a/src/Signature/DefaultSignatureHashingManager.php b/src/Signature/DefaultSignatureHashingManager.php index 48adcbd..eee518f 100644 --- a/src/Signature/DefaultSignatureHashingManager.php +++ b/src/Signature/DefaultSignatureHashingManager.php @@ -21,7 +21,7 @@ public function hashSignatureString(string $string, string $method): string return $encodedString; } - private function mustEncodeHashResultAsUrlencodedBase64($method): bool + private function mustEncodeHashResultAsUrlencodedBase64(string $method): bool { return $method === SignatureMethod::MD5_METHOD; } diff --git a/src/Signature/Signable.php b/src/Signature/Signable.php index 993fc5a..ac869ed 100644 --- a/src/Signature/Signable.php +++ b/src/Signature/Signable.php @@ -4,6 +4,9 @@ interface Signable { + /** + * @return array + */ public function getSignatureData(): array; public function setSignature(string $signature): static;