Skip to content

Commit 5f7b4c8

Browse files
committed
fix: solve static analysis issues
1 parent cce8dc8 commit 5f7b4c8

27 files changed

+282
-153
lines changed

composer.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"phpunit/phpunit": "^11.3.1",
2222
"phpstan/phpstan": "^1.12",
2323
"squizlabs/php_codesniffer": "^3.10",
24-
"slevomat/coding-standard": "^8.15"
24+
"slevomat/coding-standard": "^8.15",
25+
"phpstan/phpstan-phpunit": "^1.4",
26+
"phpstan/extension-installer": "^1.4"
2527
},
2628
"autoload": {
2729
"psr-4": {
@@ -36,13 +38,15 @@
3638
},
3739
"config": {
3840
"allow-plugins": {
39-
"dealerdirect/phpcodesniffer-composer-installer": true
41+
"dealerdirect/phpcodesniffer-composer-installer": true,
42+
"phpstan/extension-installer": true
4043
}
4144
},
4245
"scripts": {
43-
"lint": "phpcs",
46+
"lint": "phpcs -s",
4447
"lint-fix": "phpcbf",
4548
"phpstan": "phpstan analyse -c phpstan.neon",
49+
"test": "phpunit",
4650
"check-quality": [
4751
"@lint",
4852
"@phpstan"

composer.lock

Lines changed: 104 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
parameters:
22
level: 8
3-
phpVersion: 70400
3+
phpVersion: 80100
44

55
tmpDir: %currentWorkingDirectory%/var/tmp/phpstan
66

src/Exception/BadRequestException.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ final class BadRequestException extends FoxentryException
1717
/**
1818
* The HTTP status code associated with this exception.
1919
*
20+
* @var int
2021
*/
21-
protected int $code = 400;
22+
// Native typehint missing, because definition needs to match the native Exception class.
23+
// phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
24+
protected $code = 400;
2225
}

src/Exception/ForbiddenException.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ final class ForbiddenException extends FoxentryException
1717
/**
1818
* The HTTP status code associated with this exception.
1919
*
20+
* @var int
2021
*/
21-
protected int $code = 403;
22+
// Native typehint missing, because definition needs to match the native Exception class.
23+
// phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
24+
protected $code = 403;
2225
}

src/Exception/FoxentryException.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static function fromRequestException(RequestException $e): self
2424
{
2525
// Check if the exception has a response
2626
if ($e->hasResponse()) {
27-
$statusCode = $e->getResponse()->getStatusCode();
27+
$statusCode = $e->getResponse()?->getStatusCode() ?? -1;
2828
// Switch based on the status code of the response
2929
switch ($statusCode) {
3030
case 400:
@@ -55,17 +55,18 @@ public static function fromRequestException(RequestException $e): self
5555
break;
5656
default:
5757
// Handle the rest with generic FoxentryException class
58-
$foxentryException = new self("Request exception: " . $e->getResponse()->getBody()->getContents(), $statusCode);
58+
$foxentryException = new self("Request exception: " . $e->getMessage(), $statusCode);
5959
break;
6060
}
61+
6162
return $foxentryException->setResponse($e->getResponse());
6263
}
6364

6465
// Return a generic exception with the original exception message
6566
return new self("Exception: " . $e->getMessage());
6667
}
6768

68-
public function setResponse(ResponseInterface $response): self
69+
public function setResponse(?ResponseInterface $response): self
6970
{
7071
$this->response = $response;
7172
return $this;

src/Exception/NotFoundException.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ final class NotFoundException extends FoxentryException
1717
/**
1818
* The HTTP status code associated with this exception.
1919
*
20+
* @var int
2021
*/
21-
protected int $code = 404;
22+
// Native typehint missing, because definition needs to match the native Exception class.
23+
// phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
24+
protected $code = 404;
2225
}

src/Exception/PaymentRequiredException.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ final class PaymentRequiredException extends FoxentryException
1717
/**
1818
* The HTTP status code associated with this exception.
1919
*
20+
* @var int
2021
*/
21-
protected int $code = 402;
22+
// Native typehint missing, because definition needs to match the native Exception class.
23+
// phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
24+
protected $code = 402;
2225
}

src/Exception/ServerErrorException.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ final class ServerErrorException extends FoxentryException
1717
/**
1818
* The HTTP status code associated with this exception.
1919
*
20+
* @var int
2021
*/
21-
protected int $code = 500;
22+
// Native typehint missing, because definition needs to match the native Exception class.
23+
// phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
24+
protected $code = 500;
2225
}

src/Exception/ServiceUnavailableException.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ final class ServiceUnavailableException extends FoxentryException
1717
/**
1818
* The HTTP status code associated with this exception.
1919
*
20+
* @var int
2021
*/
21-
protected int $code = 503;
22+
// Native typehint missing, because definition needs to match the native Exception class.
23+
// phpcs:ignore SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
24+
protected $code = 503;
2225
}

0 commit comments

Comments
 (0)