Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
php-version: '8.4'
coverage: none

- name: Install composer dependencies
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"friendsofphp/php-cs-fixer": "^3.5",
"illuminate/collections": "^9.39 || ^10.0",
"league/flysystem": "^3.0",
"pestphp/pest": "^2.10",
"phpstan/phpstan": "^1.11.4",
"pestphp/pest": "^3.8.2",
"phpstan/phpstan": "^2.1.13",
"saloonphp/xml-wrangler": "^1.1",
"spatie/ray": "^1.33",
"symfony/dom-crawler": "^6.0 || ^7.0",
Expand Down Expand Up @@ -73,7 +73,7 @@
"./vendor/bin/pest -p"
],
"pstan": [
"./vendor/bin/phpstan analyse"
"./vendor/bin/phpstan analyse --memory-limit=1G"
]
}
}
67 changes: 67 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
parameters:
ignoreErrors:
-
message: '#^Call to an undefined method GuzzleHttp\\Promise\\PromiseInterface\|Saloon\\Http\\Response\:\:then\(\)\.$#'
identifier: method.notFound
count: 1
path: src/Http/Connector.php

-
message: '#^Method Saloon\\Http\\Connector\:\:defaultSender\(\) should return Saloon\\Contracts\\Sender but returns object\.$#'
identifier: return.type
count: 1
path: src/Http/Connector.php

-
message: '#^Parameter \#1 \$response of method Saloon\\Http\\PendingRequest\:\:executeResponsePipeline\(\) expects Saloon\\Http\\Response, GuzzleHttp\\Promise\\PromiseInterface\|Saloon\\Http\\Response given\.$#'
identifier: argument.type
count: 1
path: src/Http/Connector.php

-
message: '#^Parameter \#1 \$contents of static method Saloon\\Data\\RecordedResponse\:\:fromFile\(\) expects string, bool\|string given\.$#'
identifier: argument.type
count: 1
path: src/Http/Faking/Fixture.php

-
message: '#^Method Saloon\\Http\\Faking\\MockClient\:\:getLastResponse\(\) should return Saloon\\Http\\Response\|null but returns \(callable\)\|Saloon\\Http\\Faking\\Fixture\|Saloon\\Http\\Faking\\MockResponse\.$#'
identifier: return.type
count: 1
path: src/Http/Faking/MockClient.php

-
message: '#^Method Saloon\\Http\\Faking\\MockClient\:\:getRecordedResponses\(\) should return array\<Saloon\\Http\\Response\> but returns array\<\(callable\)\|Saloon\\Http\\Faking\\Fixture\|Saloon\\Http\\Faking\\MockResponse\>\.$#'
identifier: return.type
count: 1
path: src/Http/Faking/MockClient.php

-
message: '#^Property Saloon\\Http\\Faking\\MockClient\:\:\$recordedResponses \(array\<\(callable\(\)\: mixed\)\|Saloon\\Http\\Faking\\Fixture\|Saloon\\Http\\Faking\\MockResponse\>\) does not accept non\-empty\-array\<\(callable\(\)\: mixed\)\|Saloon\\Http\\Faking\\Fixture\|Saloon\\Http\\Faking\\MockResponse\|Saloon\\Http\\Response\>\.$#'
identifier: assign.propertyType
count: 1
path: src/Http/Faking/MockClient.php

-
message: '#^Parameter \#1 \$callback of function call_user_func_array expects callable\(\)\: mixed, \(callable\(\)\: mixed\)\|object given\.$#'
identifier: argument.type
count: 2
path: src/Http/PendingRequest.php

-
message: '#^Parameter \#1 \$object of method ReflectionMethod\:\:invoke\(\) expects object\|null, class\-string\|object given\.$#'
identifier: argument.type
count: 1
path: src/Http/PendingRequest.php

-
message: '#^Parameter \#1 \$callback of function call_user_func_array expects callable\(\)\: mixed, \(callable\(\)\: mixed\)\|object given\.$#'
identifier: argument.type
count: 2
path: src/Http/Response.php

-
message: '#^Parameter \#1 \$object of method ReflectionMethod\:\:invoke\(\) expects object\|null, class\-string\|object given\.$#'
identifier: argument.type
count: 1
path: src/Http/Response.php
51 changes: 0 additions & 51 deletions phpstan.baseline.neon

This file was deleted.

6 changes: 5 additions & 1 deletion phpstan.dist.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#############################################################################################

includes:
- phpstan.baseline.neon
- phpstan-baseline.neon

parameters:
# Add one of the editorUrl's in your phpstan.neon file for direct editor/IDE links in the terminal.
Expand All @@ -18,3 +18,7 @@ parameters:

ignoreErrors:
- "#^Unsafe usage of new static\\(\\)\\.$#"

# Rules

treatPhpDocTypesAsCertain: false
14 changes: 5 additions & 9 deletions src/Helpers/ArrayHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class ArrayHelpers
/**
* Determine whether the given value is array accessible.
*
* @phpstan-assert-if-true array|ArrayAccess $value
* @phpstan-assert-if-true array<array-key, mixed>|ArrayAccess<array-key, mixed> $value
*/
private static function accessible(mixed $value): bool
{
Expand Down Expand Up @@ -49,10 +49,6 @@ private static function exists(array|ArrayAccess $array, string|int|float $key):
*/
public static function get(array $array, string|int|null $key, mixed $default = null): mixed
{
if (! static::accessible($array)) {
return Helpers::value($default);
}

if (is_null($key)) {
return $array;
}
Expand Down Expand Up @@ -81,17 +77,17 @@ public static function get(array $array, string|int|null $key, mixed $default =
*
* If no key is given to the method, the entire array will be replaced.
*
* @param array $array
* @param string|int|null $key
* @return array
* @param array<array-key, mixed> $array
* @param string|int|null $key
* @return array<array-key, mixed>
*/
public static function set(&$array, $key, $value)
{
if (is_null($key)) {
return $array = $value;
}

$keys = explode('.', $key);
$keys = explode('.', (string)$key);

foreach ($keys as $i => $key) {
if (count($keys) === 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Faking/FakeResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Saloon\Contracts\FakeResponse as FakeResponseContract;

/**
* @method static static make(mixed $body = [], int $status = 200, array $headers = [])
* @method static static make(mixed $body = [], int $status = 200, array<string, string|int|float|bool> $headers = [])
*/
class FakeResponse implements FakeResponseContract
{
Expand Down
6 changes: 5 additions & 1 deletion src/Http/Faking/Fixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class Fixture

/**
* Data to merge in the mocked response.
*
* @var array<array-key, mixed>|null
*/
protected ?array $merge = null;

Expand All @@ -51,6 +53,8 @@ public function __construct(string $name = '', ?Storage $storage = null)

/**
* Specify data to merge with the mock response data.
*
* @param array<array-key, mixed> $merge
*/
public function merge(array $merge = []): static
{
Expand Down Expand Up @@ -97,7 +101,7 @@ public function getMockResponse(): ?MockResponse
ArrayHelpers::set($body, $key, $value);
}
}

// If specified, we pass the body through a function that
// may modify the mock response data.
if (! is_null($this->through)) {
Expand Down
20 changes: 6 additions & 14 deletions src/Http/Faking/MockClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Saloon\Http\PendingRequest;
use PHPUnit\Framework\Assert as PHPUnit;
use Saloon\Exceptions\NoMockResponseFoundException;
use Saloon\Exceptions\InvalidMockResponseCaptureMethodException;

class MockClient
{
Expand Down Expand Up @@ -96,10 +95,6 @@ public function addResponse(MockResponse|Fixture|callable $response, ?string $ca
return;
}

if (! is_string($captureMethod)) {
throw new InvalidMockResponseCaptureMethodException;
}

// Let's detect if the capture method is either a connector or
// a request. If so we'll put them in their designated arrays.

Expand Down Expand Up @@ -271,16 +266,15 @@ public function assertSentInOrder(array $callbacks): void
foreach ($callbacks as $index => $callback) {
$result = $this->checkRequestWasSent($callback, $index);

PHPUnit::assertTrue($result, 'An expected request (#'.($index + 1).') was not sent.');
PHPUnit::assertTrue($result, 'An expected request (#' . ($index + 1) . ') was not sent.');
}
}

/**
* Assert JSON response data was received
*
* @deprecated This method will be removed in v4
*
* @param array<string, mixed> $data
* @deprecated This method will be removed in v4
*/
public function assertSentJson(string $request, array $data): void
{
Expand Down Expand Up @@ -324,12 +318,10 @@ protected function checkRequestWasSent(string|callable $request, ?int $index = n
return $this->checkClosureAgainstResponses($request, $index);
}

if (is_string($request)) {
if (class_exists($request) && Helpers::isSubclassOf($request, Request::class)) {
$passed = $this->findResponseByRequest($request, $index) instanceof Response;
} else {
$passed = $this->findResponseByRequestUrl($request, $index) instanceof Response;
}
if (class_exists($request) && Helpers::isSubclassOf($request, Request::class)) {
$passed = $this->findResponseByRequest($request, $index) instanceof Response;
} else {
$passed = $this->findResponseByRequestUrl($request, $index) instanceof Response;
}

return $passed;
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Faking/MockResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Saloon\Http\Faking;

/**
* @method static static make(mixed $body = [], int $status = 200, array $headers = [])
* @method static static make(mixed $body = [], int $status = 200, array<string, string|int|float|bool> $headers = [])
*/
class MockResponse extends FakeResponse
{
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Middleware/DetermineMockResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __invoke(PendingRequest $pendingRequest): PendingRequest
// an instance of a fixture instead, we will register a
// middleware on the response to record the response.

if (is_null($mockResponse) && $mockObject instanceof Fixture) {
if ($mockObject instanceof Fixture) {
$pendingRequest->middleware()->onResponse(new RecordFixture($mockObject, $mockClient), 'recordFixture', PipeOrder::FIRST);
}

Expand Down
12 changes: 6 additions & 6 deletions src/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,33 +491,33 @@ public function header(string $header): string|array|null

/**
* Determine if the response is in JSON format.
*
* @return bool
*/
public function isJson(): bool
{
$contentType = $this->header('Content-Type');

if(is_null($contentType)) {
if (is_null($contentType)) {
return false;
}

$contentType = is_array($contentType) ? $contentType[0] : $contentType;

return str_contains($contentType, 'json');
}

/**
* Determine if the response is in XML format.
*
* @return bool
*/
public function isXml(): bool
{
$contentType = $this->header('Content-Type');

if(is_null($contentType)) {
if (is_null($contentType)) {
return false;
}

$contentType = is_array($contentType) ? $contentType[0] : $contentType;

return str_contains($contentType, 'xml');
}

Expand Down
6 changes: 2 additions & 4 deletions src/Repositories/ArrayStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ public function remove(string $key): static
/**
* Determine if the store is empty
*
*
* @phpstan-assert-if-false non-empty-array $this->data
* @phpstan-assert-if-false non-empty-array<array-key, mixed> $this->data
*/
public function isEmpty(): bool
{
Expand All @@ -111,8 +110,7 @@ public function isEmpty(): bool
/**
* Determine if the store is not empty
*
*
* @phpstan-assert-if-true non-empty-array $this->data
* @phpstan-assert-if-true non-empty-array<array-key, mixed> $this->data
*/
public function isNotEmpty(): bool
{
Expand Down
5 changes: 2 additions & 3 deletions src/Repositories/Body/ArrayBodyRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ public function remove(string|int $key): static
/**
* Determine if the repository is empty
*
*
* @phpstan-assert-if-false non-empty-array $this->data
* @phpstan-assert-if-false non-empty-array<array-key, mixed> $this->data
*/
public function isEmpty(): bool
{
Expand All @@ -133,7 +132,7 @@ public function isEmpty(): bool
* Determine if the repository is not empty
*
*
* @phpstan-assert-if-true non-empty-array $this->data
* @phpstan-assert-if-true non-empty-array<array-key, mixed> $this->data
*/
public function isNotEmpty(): bool
{
Expand Down
Loading