Skip to content

Commit 588ab7b

Browse files
authored
Merge pull request #358 from EasyPost/stricter_phpstan
stricter phpstan
2 parents 64bd714 + 5cdcb59 commit 588ab7b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+208
-190
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"coverage": "XDEBUG_MODE=coverage ./bin/phpunit --coverage-html clover.html --coverage-clover build/logs/clover.xml && ./bin/coverage-check build/logs/clover.xml 85 --only-percentage",
3737
"fix": "./bin/phpcbf --standard=examples/style_guides/php/phpcs.xml lib test",
3838
"lint": "./bin/phpcs --standard=examples/style_guides/php/phpcs.xml lib test",
39-
"phpstan": "./bin/phpstan analyse --memory-limit 1G",
39+
"phpstan": "./bin/phpstan analyse --memory-limit 4G",
4040
"scan": "composer update --dry-run roave/security-advisories",
4141
"test": "./bin/phpunit"
4242
},

lib/EasyPost/EasyPostClient.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class EasyPostClient extends BaseService
7575
private float $timeout;
7676
private string $apiBase;
7777
private ?object $mockingUtility;
78-
public object $requestEvent;
79-
public object $responseEvent;
78+
public RequestHook $requestEvent;
79+
public ResponseHook $responseEvent;
8080
public Client $httpClient;
8181

8282
/**
@@ -198,9 +198,9 @@ public function mock(): bool
198198
/**
199199
* Get the mock requests of an EasyPostClient.
200200
*
201-
* @return object
201+
* @return object|null
202202
*/
203-
public function getMockingUtility(): object
203+
public function getMockingUtility(): ?object
204204
{
205205
return $this->mockingUtility;
206206
}

lib/EasyPost/EasyPostObject.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,11 @@ public function __get(string $k): mixed
126126
*/
127127
public static function constructFrom(?EasyPostClient $client, array $values, string $class): mixed
128128
{
129-
$object = new $class($client);
130-
$object->convertEach($client, $values);
129+
/** @var EasyPostObject $easypostObject */
130+
$easypostObject = new $class($client);
131+
$easypostObject->convertEach($client, $values);
131132

132-
return $object;
133+
return $easypostObject;
133134
}
134135

135136
/**
@@ -265,7 +266,7 @@ public function __toJSON(): string|bool
265266
*/
266267
public function __toString(): string
267268
{
268-
return $this->__toJSON();
269+
return (string)$this->__toJSON();
269270
}
270271

271272
/**

lib/EasyPost/Exception/Api/ApiException.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* @package EasyPost
1111
* @property string|null $code
12-
* @property array<FieldError|array<string>>|null $errors
12+
* @property array<FieldError|array<string>> $errors
1313
* @property string $message
1414
* @property string|null $httpBody
1515
* @property int|null $httpStatus
@@ -36,7 +36,7 @@ public function __construct(string $message = '', ?int $httpStatus = null, ?stri
3636
parent::__construct($message);
3737
$this->httpStatus = $httpStatus;
3838
$this->httpBody = $httpBody;
39-
$this->errors = null;
39+
$this->errors = [];
4040
$this->code = null;
4141

4242
try {
@@ -59,19 +59,19 @@ public function __construct(string $message = '', ?int $httpStatus = null, ?stri
5959
/**
6060
* Get the HTTP status code.
6161
*
62-
* @return int
62+
* @return int|null
6363
*/
64-
public function getHttpStatus(): int
64+
public function getHttpStatus(): ?int
6565
{
6666
return $this->httpStatus;
6767
}
6868

6969
/**
7070
* Get the HTTP body.
7171
*
72-
* @return string
72+
* @return string|null
7373
*/
74-
public function getHttpBody(): string
74+
public function getHttpBody(): ?string
7575
{
7676
return $this->httpBody;
7777
}

lib/EasyPost/Hook/EventHook.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class EventHook
1515
/**
1616
* Fires when the class is invoked.
1717
*
18-
* @param array<callable> ...$args
18+
* @param array<mixed> ...$args
1919
* @return void
2020
*/
2121
public function __invoke(array ...$args): void
@@ -47,7 +47,7 @@ public function removeHandler(callable $handler)
4747
{
4848
$index = array_search($handler, $this->eventHandlers, true);
4949
if ($index !== false) {
50-
array_splice($this->eventHandlers, $index, 1);
50+
array_splice($this->eventHandlers, (int)$index, 1);
5151
}
5252
return $this;
5353
}

lib/EasyPost/Http/Requestor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private static function requestRaw(
171171
if ($client->mock()) {
172172
// If there are mock requests set, this client will ONLY make mock requests
173173
$mockingUtility = $client->getMockingUtility();
174-
$matchingRequest = $mockingUtility->findMatchingMockRequest($method, $absoluteUrl);
174+
$matchingRequest = $mockingUtility->findMatchingMockRequest($method, $absoluteUrl); // @phpstan-ignore-line
175175
if ($matchingRequest === null) {
176176
throw new HttpException(sprintf(Constants::NO_MATCHING_MOCK_REQUEST, $method, $absoluteUrl));
177177
}
@@ -342,7 +342,7 @@ private static function traverseJsonElement(mixed $errorMessage, array &$message
342342
}
343343
break;
344344
case 'object':
345-
foreach ($errorMessage as $value) {
345+
foreach ($errorMessage as $value) { // @phpstan-ignore-line
346346
self::traverseJsonElement($value, $messagesList);
347347
}
348348
break;

lib/EasyPost/Order.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Order extends EasyPostObject
3434
*/
3535
public function lowestRate(?array $carriers = [], ?array $services = []): Rate
3636
{
37+
/** @var Rate $lowestRate */
3738
$lowestRate = InternalUtil::getLowestObjectRate($this, $carriers, $services);
3839

3940
return $lowestRate;

lib/EasyPost/Pickup.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Pickup extends EasyPostObject
3737
*/
3838
public function lowestRate(?array $carriers = [], ?array $services = []): PickupRate
3939
{
40+
/** @var PickupRate $lowestRate */
4041
$lowestRate = InternalUtil::getLowestObjectRate($this, $carriers, $services, 'pickup_rates');
4142

4243
return $lowestRate;

lib/EasyPost/Service/BaseService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,15 @@ protected function deleteResource(string $class, string $id, mixed $params = nul
224224
* @param string $class
225225
* @param string $id
226226
* @param mixed $params
227-
* @param string|null $method
227+
* @param string $method
228228
* @param bool $beta
229229
* @return mixed
230230
*/
231231
protected function updateResource(
232232
string $class,
233233
string $id,
234234
mixed $params = null,
235-
?string $method = 'patch',
235+
string $method = 'patch',
236236
bool $beta = false
237237
): mixed {
238238
self::validate();

lib/EasyPost/Shipment.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class Shipment extends EasyPostObject
5050
*/
5151
public function lowestRate(?array $carriers = [], ?array $services = []): Rate
5252
{
53+
/** @var Rate $lowestRate */
5354
$lowestRate = InternalUtil::getLowestObjectRate($this, $carriers, $services);
5455

5556
return $lowestRate;

0 commit comments

Comments
 (0)