Skip to content

Commit

Permalink
chore(deps): update phpstan packages to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
renovate[bot] authored and simPod committed Nov 11, 2024
1 parent eddc8c2 commit a271077
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 45 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
"nyholm/psr7": "^1.2",
"php-http/message-factory": "^1.1",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.0.0",
"phpstan/phpstan-phpunit": "^1.0.0",
"phpstan/phpstan-strict-rules": "^1.0.0",
"phpstan/phpstan": "^2.0.0",
"phpstan/phpstan-phpunit": "^2.0.0",
"phpstan/phpstan-strict-rules": "^2.0.0",
"phpunit/phpunit": "^11.0",
"symfony/http-client": "^7.0"
},
Expand Down
5 changes: 3 additions & 2 deletions src/Client/Http/RequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public function prepareRequest(RequestOptions $requestOptions): RequestInterface
}
}

$typeToParam = array_reduce(
/** @var array<string, Type> $paramToType */
$paramToType = array_reduce(
array_keys($matches[1]),
static function (array $acc, string|int $k) use ($matches) {
$acc[$matches[1][$k]] = Type::fromString($matches[2][$k]);
Expand All @@ -94,7 +95,7 @@ static function (array $acc, string|int $k) use ($matches) {

$streamElements = [['name' => 'query', 'contents' => $requestOptions->sql]];
foreach ($requestOptions->params as $name => $value) {
$type = $typeToParam[$name] ?? null;
$type = $paramToType[$name] ?? null;
if ($type === null) {
continue;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Format/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ final class Json implements Format
/** @throws JsonException */
public static function output(string $contents): Output
{
return new \SimPod\ClickHouseClient\Output\Json($contents);
/** @var \SimPod\ClickHouseClient\Output\Json<T> $output */
$output = new \SimPod\ClickHouseClient\Output\Json($contents);

return $output;
}

public static function toSql(): string
Expand Down
5 changes: 4 additions & 1 deletion src/Format/JsonCompact.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ final class JsonCompact implements Format
/** @throws JsonException */
public static function output(string $contents): Output
{
return new \SimPod\ClickHouseClient\Output\JsonCompact($contents);
/** @var \SimPod\ClickHouseClient\Output\JsonCompact<T> $output */
$output = new \SimPod\ClickHouseClient\Output\JsonCompact($contents);

return $output;
}

public static function toSql(): string
Expand Down
5 changes: 4 additions & 1 deletion src/Format/JsonEachRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ final class JsonEachRow implements Format
/** @throws JsonException */
public static function output(string $contents): Output
{
return new \SimPod\ClickHouseClient\Output\JsonEachRow($contents);
/** @var \SimPod\ClickHouseClient\Output\JsonEachRow<T> $output */
$output = new \SimPod\ClickHouseClient\Output\JsonEachRow($contents);

return $output;
}

public static function toSql(): string
Expand Down
5 changes: 4 additions & 1 deletion src/Format/Null_.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ final class Null_ implements Format
{
public static function output(string $contents): Output
{
return new \SimPod\ClickHouseClient\Output\Null_($contents);
/** @var \SimPod\ClickHouseClient\Output\Null_<T> $output */
$output = new \SimPod\ClickHouseClient\Output\Null_($contents);

return $output;
}

public static function toSql(): string
Expand Down
5 changes: 4 additions & 1 deletion src/Format/Pretty.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ final class Pretty implements Format
{
public static function output(string $contents): Output
{
return new Basic($contents);
/** @var Basic<T> $output */
$output = new Basic($contents);

Check warning on line 19 in src/Format/Pretty.php

View check run for this annotation

Codecov / codecov/patch

src/Format/Pretty.php#L19

Added line #L19 was not covered by tests

return $output;

Check warning on line 21 in src/Format/Pretty.php

View check run for this annotation

Codecov / codecov/patch

src/Format/Pretty.php#L21

Added line #L21 was not covered by tests
}

public static function toSql(): string
Expand Down
5 changes: 4 additions & 1 deletion src/Format/PrettySpace.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ final class PrettySpace implements Format
{
public static function output(string $contents): Output
{
return new Basic($contents);
/** @var Basic<T> $output */
$output = new Basic($contents);

Check warning on line 19 in src/Format/PrettySpace.php

View check run for this annotation

Codecov / codecov/patch

src/Format/PrettySpace.php#L19

Added line #L19 was not covered by tests

return $output;

Check warning on line 21 in src/Format/PrettySpace.php

View check run for this annotation

Codecov / codecov/patch

src/Format/PrettySpace.php#L21

Added line #L21 was not covered by tests
}

public static function toSql(): string
Expand Down
5 changes: 4 additions & 1 deletion src/Format/TabSeparated.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ final class TabSeparated implements Format
{
public static function output(string $contents): Output
{
return new Basic($contents);
/** @var Basic<T> $output */
$output = new Basic($contents);

Check warning on line 19 in src/Format/TabSeparated.php

View check run for this annotation

Codecov / codecov/patch

src/Format/TabSeparated.php#L19

Added line #L19 was not covered by tests

return $output;

Check warning on line 21 in src/Format/TabSeparated.php

View check run for this annotation

Codecov / codecov/patch

src/Format/TabSeparated.php#L21

Added line #L21 was not covered by tests
}

public static function toSql(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Output/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class Json implements Output

public int $rows;

public int|null $rowsBeforeLimitAtLeast = null;
public int|null $rowsBeforeLimitAtLeast;

/** @var array{elapsed: float, rows_read: int, bytes_read: int} */
public array $statistics;
Expand Down
2 changes: 1 addition & 1 deletion src/Output/JsonCompact.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class JsonCompact implements Output

public int $rows;

public int|null $rowsBeforeLimitAtLeast = null;
public int|null $rowsBeforeLimitAtLeast;

/** @var array{elapsed: float, rows_read: int, bytes_read: int} */
public array $statistics;
Expand Down
39 changes: 26 additions & 13 deletions src/Param/ParamValueConverterRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,22 @@ final class ParamValueConverterRegistry
public function __construct()
{
$formatPoint = static fn (array $point) => sprintf('(%s)', implode(',', $point));

Check failure on line 53 in src/Param/ParamValueConverterRegistry.php

View workflow job for this annotation

GitHub Actions / Coding Standards (8.2)

Equals sign not aligned correctly; expected 1 space but found 3 spaces
$formatRing = static fn (array $v) => sprintf('[%s]', implode(
',',
array_map($formatPoint, $v),
));
$formatPolygon = static fn (array $v) => sprintf('[%s]', implode(
',',
array_map($formatRing, $v),
));
// phpcs:ignore SlevomatCodingStandard.Functions.RequireArrowFunction.RequiredArrowFunction
$formatRing = static function (array $v) use ($formatPoint) {

Check failure on line 55 in src/Param/ParamValueConverterRegistry.php

View workflow job for this annotation

GitHub Actions / Coding Standards (8.2)

Equals sign not aligned correctly; expected 1 space but found 4 spaces
/** @phpstan-var array<array<string>> $v */
return sprintf('[%s]', implode(
',',
array_map($formatPoint, $v),
));
};
// phpcs:ignore SlevomatCodingStandard.Functions.RequireArrowFunction.RequiredArrowFunction
$formatPolygon = static function (array $v) use ($formatRing) {
/** @phpstan-var array<array<string>> $v */
return sprintf('[%s]', implode(
',',
array_map($formatRing, $v),
));
};

/** @phpstan-var array<string, Converter> $registry */
$registry = [
Expand Down Expand Up @@ -105,6 +113,7 @@ public function __construct()

$types = array_map(static fn ($type) => explode(' ', trim($type))[1], $this->splitTypes($type->params));

/** @phpstan-var array<array<string>> $v */
return sprintf('[%s]', implode(',', array_map(
fn (array $row) => sprintf('(%s)', implode(',', array_map(
fn (int|string $i) => $this->get($types[$i])($row[$i], $types[$i], true),
Expand Down Expand Up @@ -154,10 +163,14 @@ public function __construct()
: $formatPolygon($v),
'MultiPolygon' => static fn (string|array $v) => is_string($v)
? $v
: (static fn (array $vv) => sprintf('[%s]', implode(
',',
array_map($formatPolygon, $vv),
)))($v),
// phpcs:ignore SlevomatCodingStandard.Functions.RequireArrowFunction.RequiredArrowFunction
: (static function (array $vv) use ($formatPolygon) {
/** @phpstan-var array<array<string>> $vv */
return sprintf('[%s]', implode(
',',
array_map($formatPolygon, $vv),
));
})($v),

'Array' => fn (array|string $v, Type $type) => is_string($v)
? $v
Expand Down Expand Up @@ -194,7 +207,7 @@ public function __construct()
/**
* @phpstan-return Converter
*
* @throws UnsupportedParamType;
* @throws UnsupportedParamType
*/
public function get(Type|string $type): Closure
{
Expand Down
19 changes: 12 additions & 7 deletions src/Sql/ValueFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use function array_key_first;
use function array_map;
use function assert;
use function implode;
use function is_array;
use function is_bool;
Expand Down Expand Up @@ -92,13 +93,17 @@ public function format(mixed $value, string|null $paramName = null, string|null

$firstValue = $value[array_key_first($value)];
$mapper = is_array($firstValue)
? fn ($value): string => sprintf(
'(%s)',
implode(
',',
array_map(fn ($val) => $this->format($val), $value),
),
)
? function ($value): string {
assert(is_array($value));

return sprintf(
'(%s)',
implode(
',',
array_map(fn ($val) => $this->format($val), $value),

Check warning on line 103 in src/Sql/ValueFormatter.php

View workflow job for this annotation

GitHub Actions / Infection

Escaped Mutant for Mutator "UnwrapArrayMap": @@ @@ $firstValue = $value[array_key_first($value)]; $mapper = is_array($firstValue) ? function ($value): string { assert(is_array($value)); - return sprintf('(%s)', implode(',', array_map(fn($val) => $this->format($val), $value))); + return sprintf('(%s)', implode(',', $value)); } : fn($value): string => $value === null ? 'NULL' : $this->format($value); return implode(',', array_map($mapper, $value)); }
),
);
}
: fn ($value): string => $value === null ? 'NULL' : $this->format($value);

return implode(
Expand Down
8 changes: 6 additions & 2 deletions tests/Client/SelectAsyncTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@ public function testAsyncSelect(): void
$client->select($sql, $format),
];

/**
* @var array{
* \SimPod\ClickHouseClient\Output\JsonEachRow<array{number: string}>,
* \SimPod\ClickHouseClient\Output\JsonEachRow<array{number: string}>
* } $jsonEachRowOutputs
*/
$jsonEachRowOutputs = Utils::all($promises)->wait();

$expectedData = [
['number' => '0'],
['number' => '1'],
];

self::assertIsArray($jsonEachRowOutputs);
self::assertCount(2, $jsonEachRowOutputs);
self::assertSame($expectedData, $jsonEachRowOutputs[0]->data);
self::assertSame($expectedData, $jsonEachRowOutputs[1]->data);
}
Expand Down
10 changes: 1 addition & 9 deletions tests/Exception/UnsupportedParamValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
use stdClass;

use function opendir;
use function sprintf;

use const PHP_VERSION_ID;

#[CoversClass(UnsupportedParamValue::class)]
final class UnsupportedParamValueTest extends TestCaseBase
Expand Down Expand Up @@ -68,17 +65,12 @@ public static function providerValue(): iterable
new stdClass(),
];

$prefix = PHP_VERSION_ID >= 80200 ? '\\' : '';

yield [
sprintf(
"Value \"%sDateTime::__set_state(array(
"Value \"\DateTime::__set_state(array(
'date' => '2022-02-02 13:31:37.593289',
'timezone_type' => 3,
'timezone' => 'UTC',
))\" is not supported as a parameter",
$prefix,
),
new DateTime('2022-02-02 13:31:37.593289'),
];
}
Expand Down

0 comments on commit a271077

Please sign in to comment.