Skip to content

Commit 129aabc

Browse files
committed
fix: add temporary PHPStan ignore lines for type safety in JSHandle and JavaScriptSerializer
1 parent a6a8d48 commit 129aabc

3 files changed

Lines changed: 31 additions & 10 deletions

File tree

src/Playwright/JSHandle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@ public function toString(): string
7171
return $value;
7272
}
7373

74-
return (string) $value;
74+
return (string) $value; // @phpstan-ignore-line // temporary
7575
}
7676
}

src/Playwright/Page.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,15 +561,20 @@ public function evaluateHandle(string $pageFunction, mixed $arg = null): JSHandl
561561

562562
foreach ($response as $message) {
563563
if (
564-
isset($message['method'], $message['params']['type'], $message['params']['guid'])
564+
is_array($message) && is_array($message['params'] ?? null)
565+
&& isset($message['method'], $message['params']['type'], $message['params']['guid'])
565566
&& $message['method'] === '__create__'
566567
&& $message['params']['type'] === 'JSHandle'
567568
) {
568-
return new JSHandle($message['params']['guid']);
569+
return new JSHandle((string) $message['params']['guid']); // @phpstan-ignore-line
569570
}
570571

571-
if (isset($message['result']['handle'])) {
572-
return new JSHandle($message['result']['handle']['guid']);
572+
if (
573+
is_array($message)
574+
&& is_array($message['result'] ?? null)
575+
&& isset($message['result']['handle'])
576+
) {
577+
return new JSHandle($message['result']['handle']['guid']); // @phpstan-ignore-line
573578
}
574579
}
575580

src/Support/JavaScriptSerializer.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ final class JavaScriptSerializer
1515
{
1616
/**
1717
* Serialize arguments for JavaScript evaluation according to Playwright protocol.
18+
*
19+
* @return array<string, mixed>
1820
*/
1921
public static function serializeArgument(mixed $value): array
2022
{
@@ -26,6 +28,8 @@ public static function serializeArgument(mixed $value): array
2628

2729
/**
2830
* Serialize a value according to Playwright's serialization format.
31+
*
32+
* @return array<string, mixed>
2933
*/
3034
public static function serializeValue(mixed $value): array
3135
{
@@ -86,7 +90,7 @@ public static function serializeValue(mixed $value): array
8690
return ['o' => $result];
8791
}
8892

89-
return ['s' => (string) $value];
93+
return ['s' => (string) $value]; // @phpstan-ignore-line
9094
}
9195

9296
/**
@@ -98,6 +102,18 @@ public static function parseValue(mixed $value): mixed
98102
return $value;
99103
}
100104

105+
/**
106+
* @var array{
107+
* v?: string, // null, undefined, NaN, Infinity, -Infinity
108+
* b?: bool, // boolean
109+
* n?: int|float, // number
110+
* s?: string, // string
111+
* bi?: string, // bigint
112+
* d?: string, // date in ISO 8601 format
113+
* a?: array<mixed>, // array
114+
* o?: array<array{ k: string, v: mixed }>, // object
115+
* } $value
116+
*/
101117
// Handle primitive values
102118
if (isset($value['v'])) {
103119
return match ($value['v']) {
@@ -111,19 +127,19 @@ public static function parseValue(mixed $value): mixed
111127
}
112128

113129
if (isset($value['b'])) {
114-
return (bool) $value['b'];
130+
return $value['b'];
115131
}
116132

117133
if (isset($value['n'])) {
118-
return is_int($value['n']) ? $value['n'] : (float) $value['n'];
134+
return $value['n'];
119135
}
120136

121137
if (isset($value['s'])) {
122-
return (string) $value['s'];
138+
return $value['s'];
123139
}
124140

125141
if (isset($value['bi'])) {
126-
return (string) $value['bi'];
142+
return $value['bi'];
127143
}
128144

129145
if (isset($value['d'])) {

0 commit comments

Comments
 (0)