Skip to content

Commit aadde6b

Browse files
authored
fix mr rr (#41)
1 parent 94d484e commit aadde6b

33 files changed

Lines changed: 170 additions & 441 deletions

‎src/API/APIRequestContext.php‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ public function fetch(string $urlOrRequest, array $options = []): APIResponseInt
111111
if (!isset($response['response']) || !is_array($response['response'])) {
112112
throw new ProtocolErrorException('Invalid API response from transport', 0);
113113
}
114-
115-
// Ensure we pass an array<string, mixed> to APIResponse
116114
$respData = [];
117115
foreach ($response['response'] as $key => $value) {
118116
if (is_string($key)) {

‎src/API/APIResponse.php‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,21 @@ public function json(): array
159159
try {
160160
$decoded = json_decode($body, true, 512, \JSON_THROW_ON_ERROR);
161161

162-
return is_array($decoded) ? $decoded : [];
162+
if (!is_array($decoded)) {
163+
return [];
164+
}
165+
166+
$result = [];
167+
foreach ($decoded as $key => $value) {
168+
if (is_string($key)) {
169+
$result[$key] = $value;
170+
continue;
171+
}
172+
173+
$result[(string) $key] = $value;
174+
}
175+
176+
return $result;
163177
} catch (\JsonException $e) {
164178
throw new PlaywrightException('Response body is not valid JSON: '.$e->getMessage(), 0, $e);
165179
}
@@ -174,6 +188,5 @@ public function text(): string
174188

175189
public function dispose(): void
176190
{
177-
// No-op for now - in the future this might release resources
178191
}
179192
}

‎src/Assertions/AssertionOptions.php‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,13 @@
1616

1717
readonly class AssertionOptions
1818
{
19-
// TODO add from/to array
20-
// also allow array anywhere this type is used as argument
21-
2219
public function __construct(
2320
public ?int $timeoutMs = null,
2421
public ?int $intervalMs = 100,
2522
public ?string $message = null,
26-
public ?bool $strict = null, // e.g. exact text match
27-
public ?bool $ignoreCase = null, // text assertions
28-
public ?bool $useInnerText = null, // locator text
23+
public ?bool $strict = null,
24+
public ?bool $ignoreCase = null,
25+
public ?bool $useInnerText = null,
2926
) {
3027
}
3128
}

‎src/Assertions/GenericAssertionsInterface.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ public function toBeFalsy(?AssertionOptions $options = null): self;
2929
public function toBeGreaterThan(int|float $expected, ?AssertionOptions $options = null): self;
3030

3131
/** @return $this */
32-
public function not(): self; // flips to negated mode for next assertion
32+
public function not(): self;
3333
}

‎src/Assertions/Waiter.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ public static function eventually(callable $predicate, int $timeoutMs = self::DE
3333
\usleep($intervalMs * 1000);
3434
} while (\hrtime(true) < $deadline);
3535

36-
throw new TimeoutException('Condition not met within timeout.'); // caught & rethrown as AssertionException by callers
36+
throw new TimeoutException('Condition not met within timeout.');
3737
}
3838
}

‎src/Browser/BrowserContext.php‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,6 @@ public function waitForPopup(callable $action, array $options = []): PageInterfa
517517
if (method_exists($this->transport, 'storePendingCallback')) {
518518
$this->transport->storePendingCallback($requestId, $action);
519519
} else {
520-
// Fallback for transports that don't support callbacks
521520
$action();
522521
}
523522

@@ -563,7 +562,6 @@ private function validateTransportArray(mixed $data, string $context = ''): arra
563562

564563
public function request(): APIRequestContextInterface
565564
{
566-
// No baseURL configured at the context level by default
567565
return new APIRequestContext($this->transport, $this->contextId, null);
568566
}
569567

‎src/Browser/BrowserContextBuilder.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ public function withRecordVideoDir(string $dir): self
9090

9191
public function withColorScheme(string $scheme): self
9292
{
93-
// Expected values: 'light' | 'dark' | 'no-preference'
9493
$this->options['colorScheme'] = $scheme;
9594

9695
return $this;

‎src/Clock/Clock.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function pauseAt(\DateTimeInterface|int|string $time): void
4949
{
5050
$timeValue = $time;
5151
if ($time instanceof \DateTimeInterface) {
52-
$timeValue = $time->getTimestamp() * 1000; // Convert to milliseconds
52+
$timeValue = $time->getTimestamp() * 1000;
5353
}
5454

5555
$this->transport->send([
@@ -80,7 +80,7 @@ public function setFixedTime(\DateTimeInterface|int|string $time): void
8080
{
8181
$timeValue = $time;
8282
if ($time instanceof \DateTimeInterface) {
83-
$timeValue = $time->getTimestamp() * 1000; // Convert to milliseconds
83+
$timeValue = $time->getTimestamp() * 1000;
8484
}
8585

8686
$this->transport->send([
@@ -94,7 +94,7 @@ public function setSystemTime(\DateTimeInterface|int|string $time): void
9494
{
9595
$timeValue = $time;
9696
if ($time instanceof \DateTimeInterface) {
97-
$timeValue = $time->getTimestamp() * 1000; // Convert to milliseconds
97+
$timeValue = $time->getTimestamp() * 1000;
9898
}
9999

100100
$this->transport->send([

‎src/Dialog/Dialog.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
use Playwright\Page\PageInterface;
1818

19-
class Dialog
2019
/**
2120
* @author Simon André <smn.andre@gmail.com>
2221
*/

‎src/Download/Download.php‎

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
* Download class for Playwright PHP.
2424
*/
2525
final class Download implements DownloadInterface
26-
{
27-
* @author Simon André <smn.andre@gmail.com>
28-
*/
29-
final class Download implements DownloadInterface
3026
{
3127
/**
3228
* @param array<string, mixed> $data
@@ -44,7 +40,6 @@ public function __construct(
4440
public function cancel(): void
4541
{
4642
$this->transport->send([
47-
'action' => 'downloadCancel',
4843
'action' => 'download.cancel',
4944
'downloadId' => $this->downloadId,
5045
]);
@@ -73,16 +68,11 @@ public function createReadStream()
7368
rewind($stream);
7469

7570
return $stream;
76-
public function createReadStream(): mixed
77-
{
78-
// TODO: Implement stream handling - PHP streams are different from Node.js Readable
79-
return null;
8071
}
8172

8273
public function delete(): void
8374
{
8475
$this->transport->send([
85-
'action' => 'downloadDelete',
8676
'action' => 'download.delete',
8777
'downloadId' => $this->downloadId,
8878
]);
@@ -95,13 +85,6 @@ public function failure(): ?string
9585
'downloadId' => $this->downloadId,
9686
]);
9787

98-
$error = $response['error'] ?? null;
99-
100-
return is_string($error) ? $error : null;
101-
'action' => 'download.failure',
102-
'downloadId' => $this->downloadId,
103-
]);
104-
10588
if (isset($response['error']) && is_string($response['error'])) {
10689
return $response['error'];
10790
}
@@ -126,24 +109,11 @@ public function path(): string
126109
}
127110

128111
return $response['path'];
129-
public function path(): ?string
130-
{
131-
$response = $this->transport->send([
132-
'action' => 'download.path',
133-
'downloadId' => $this->downloadId,
134-
]);
135-
136-
if (isset($response['path']) && is_string($response['path'])) {
137-
return $response['path'];
138-
}
139-
140-
return null;
141112
}
142113

143114
public function saveAs(string $path): void
144115
{
145116
$this->transport->send([
146-
'action' => 'downloadSaveAs',
147117
'action' => 'download.saveAs',
148118
'downloadId' => $this->downloadId,
149119
'path' => $path,
@@ -152,13 +122,23 @@ public function saveAs(string $path): void
152122

153123
public function suggestedFilename(): string
154124
{
155-
return $this->suggestedFilename;
156-
return is_string($this->data['suggestedFilename'] ?? null) ? $this->data['suggestedFilename'] : '';
125+
if ('' !== $this->suggestedFilename) {
126+
return $this->suggestedFilename;
127+
}
128+
129+
$fallback = $this->data['suggestedFilename'] ?? null;
130+
131+
return is_string($fallback) ? $fallback : '';
157132
}
158133

159134
public function url(): string
160135
{
161-
return $this->url;
162-
return is_string($this->data['url'] ?? null) ? $this->data['url'] : '';
136+
if ('' !== $this->url) {
137+
return $this->url;
138+
}
139+
140+
$fallback = $this->data['url'] ?? null;
141+
142+
return is_string($fallback) ? $fallback : '';
163143
}
164144
}

0 commit comments

Comments
 (0)