Skip to content

Commit 4a0ab82

Browse files
committed
Fix SA
1 parent b9b28bf commit 4a0ab82

32 files changed

+353
-302
lines changed

src/Frame/Frame.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use Psr\Log\LoggerInterface;
2424
use Psr\Log\NullLogger;
2525

26-
final class Frame implements FrameInterface
26+
final class Frame implements \Stringable, FrameInterface
2727
{
2828
private LoggerInterface $logger;
2929

src/Frame/FrameLocator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use Psr\Log\LoggerInterface;
2222
use Psr\Log\NullLogger;
2323

24-
final class FrameLocator implements FrameLocatorInterface
24+
final class FrameLocator implements \Stringable, FrameLocatorInterface
2525
{
2626
private LoggerInterface $logger;
2727

src/Locator/Options/CheckOptions.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
namespace Playwright\Locator\Options;
1616

17-
use Playwright\Exception\InvalidArgumentException;
18-
1917
class CheckOptions
2018
{
2119
/**
@@ -30,6 +28,9 @@ public function __construct(
3028
) {
3129
}
3230

31+
/**
32+
* @return array<string, mixed>
33+
*/
3334
public function toArray(): array
3435
{
3536
$options = [];
@@ -61,16 +62,17 @@ public static function from(array|self $options = []): self
6162
return $options;
6263
}
6364

64-
if (!\is_array($options)) {
65-
throw new InvalidArgumentException('Options must be an array or an instance of CheckOptions');
66-
}
65+
/** @var array{x: float, y: float}|null $position */
66+
$position = $options['position'] ?? null;
67+
/** @var bool|null $force */
68+
$force = $options['force'] ?? null;
69+
/** @var bool|null $noWaitAfter */
70+
$noWaitAfter = $options['noWaitAfter'] ?? null;
71+
/** @var float|null $timeout */
72+
$timeout = $options['timeout'] ?? null;
73+
/** @var bool|null $trial */
74+
$trial = $options['trial'] ?? null;
6775

68-
return new self(
69-
$options['position'] ?? null,
70-
$options['force'] ?? null,
71-
$options['noWaitAfter'] ?? null,
72-
$options['timeout'] ?? null,
73-
$options['trial'] ?? null,
74-
);
76+
return new self($position, $force, $noWaitAfter, $timeout, $trial);
7577
}
7678
}

src/Locator/Options/ClearOptions.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
namespace Playwright\Locator\Options;
1616

17-
use Playwright\Exception\InvalidArgumentException;
18-
1917
class ClearOptions
2018
{
2119
public function __construct(
@@ -25,6 +23,9 @@ public function __construct(
2523
) {
2624
}
2725

26+
/**
27+
* @return array<string, mixed>
28+
*/
2829
public function toArray(): array
2930
{
3031
$options = [];
@@ -50,14 +51,13 @@ public static function from(array|self $options = []): self
5051
return $options;
5152
}
5253

53-
if (!\is_array($options)) {
54-
throw new InvalidArgumentException('Options must be an array or an instance of ClearOptions');
55-
}
54+
/** @var bool|null $force */
55+
$force = $options['force'] ?? null;
56+
/** @var bool|null $noWaitAfter */
57+
$noWaitAfter = $options['noWaitAfter'] ?? null;
58+
/** @var float|null $timeout */
59+
$timeout = $options['timeout'] ?? null;
5660

57-
return new self(
58-
$options['force'] ?? null,
59-
$options['noWaitAfter'] ?? null,
60-
$options['timeout'] ?? null,
61-
);
61+
return new self($force, $noWaitAfter, $timeout);
6262
}
6363
}

src/Locator/Options/DblClickOptions.php

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
namespace Playwright\Locator\Options;
1616

17-
use Playwright\Exception\InvalidArgumentException;
18-
1917
class DblClickOptions
2018
{
2119
/**
@@ -36,6 +34,9 @@ public function __construct(
3634
) {
3735
}
3836

37+
/**
38+
* @return array<string, mixed>
39+
*/
3940
public function toArray(): array
4041
{
4142
$options = [];
@@ -79,20 +80,25 @@ public static function from(array|self $options = []): self
7980
return $options;
8081
}
8182

82-
if (!\is_array($options)) {
83-
throw new InvalidArgumentException('Options must be an array or an instance of DblClickOptions');
84-
}
83+
/** @var 'left'|'right'|'middle'|null $button */
84+
$button = $options['button'] ?? null;
85+
/** @var float|null $delay */
86+
$delay = $options['delay'] ?? null;
87+
/** @var array<string>|null $modifiers */
88+
$modifiers = $options['modifiers'] ?? null;
89+
/** @var array{x: float, y: float}|null $position */
90+
$position = $options['position'] ?? null;
91+
/** @var bool|null $force */
92+
$force = $options['force'] ?? null;
93+
/** @var bool|null $noWaitAfter */
94+
$noWaitAfter = $options['noWaitAfter'] ?? null;
95+
/** @var int|null $steps */
96+
$steps = $options['steps'] ?? null;
97+
/** @var float|null $timeout */
98+
$timeout = $options['timeout'] ?? null;
99+
/** @var bool|null $trial */
100+
$trial = $options['trial'] ?? null;
85101

86-
return new self(
87-
$options['button'] ?? null,
88-
$options['delay'] ?? null,
89-
$options['modifiers'] ?? null,
90-
$options['position'] ?? null,
91-
$options['force'] ?? null,
92-
$options['noWaitAfter'] ?? null,
93-
$options['steps'] ?? null,
94-
$options['timeout'] ?? null,
95-
$options['trial'] ?? null,
96-
);
102+
return new self($button, $delay, $modifiers, $position, $force, $noWaitAfter, $steps, $timeout, $trial);
97103
}
98104
}

src/Locator/Options/DragToOptions.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
namespace Playwright\Locator\Options;
1616

17-
use Playwright\Exception\InvalidArgumentException;
18-
1917
class DragToOptions
2018
{
2119
/**
@@ -33,6 +31,9 @@ public function __construct(
3331
) {
3432
}
3533

34+
/**
35+
* @return array<string, mixed>
36+
*/
3637
public function toArray(): array
3738
{
3839
$options = [];
@@ -70,18 +71,21 @@ public static function from(array|self $options = []): self
7071
return $options;
7172
}
7273

73-
if (!\is_array($options)) {
74-
throw new InvalidArgumentException('Options must be an array or an instance of DragToOptions');
75-
}
74+
/** @var array{x: float, y: float}|null $sourcePosition */
75+
$sourcePosition = $options['sourcePosition'] ?? null;
76+
/** @var array{x: float, y: float}|null $targetPosition */
77+
$targetPosition = $options['targetPosition'] ?? null;
78+
/** @var bool|null $force */
79+
$force = $options['force'] ?? null;
80+
/** @var bool|null $noWaitAfter */
81+
$noWaitAfter = $options['noWaitAfter'] ?? null;
82+
/** @var int|null $steps */
83+
$steps = $options['steps'] ?? null;
84+
/** @var float|null $timeout */
85+
$timeout = $options['timeout'] ?? null;
86+
/** @var bool|null $trial */
87+
$trial = $options['trial'] ?? null;
7688

77-
return new self(
78-
$options['sourcePosition'] ?? null,
79-
$options['targetPosition'] ?? null,
80-
$options['force'] ?? null,
81-
$options['noWaitAfter'] ?? null,
82-
$options['steps'] ?? null,
83-
$options['timeout'] ?? null,
84-
$options['trial'] ?? null,
85-
);
89+
return new self($sourcePosition, $targetPosition, $force, $noWaitAfter, $steps, $timeout, $trial);
8690
}
8791
}

src/Locator/Options/FillOptions.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
namespace Playwright\Locator\Options;
1616

17-
use Playwright\Exception\InvalidArgumentException;
18-
1917
class FillOptions
2018
{
2119
public function __construct(
@@ -25,6 +23,9 @@ public function __construct(
2523
) {
2624
}
2725

26+
/**
27+
* @return array<string, mixed>
28+
*/
2829
public function toArray(): array
2930
{
3031
$options = [];
@@ -50,14 +51,13 @@ public static function from(array|self $options = []): self
5051
return $options;
5152
}
5253

53-
if (!\is_array($options)) {
54-
throw new InvalidArgumentException('Options must be an array or an instance of FillOptions');
55-
}
54+
/** @var bool|null $force */
55+
$force = $options['force'] ?? null;
56+
/** @var bool|null $noWaitAfter */
57+
$noWaitAfter = $options['noWaitAfter'] ?? null;
58+
/** @var float|null $timeout */
59+
$timeout = $options['timeout'] ?? null;
5660

57-
return new self(
58-
$options['force'] ?? null,
59-
$options['noWaitAfter'] ?? null,
60-
$options['timeout'] ?? null,
61-
);
61+
return new self($force, $noWaitAfter, $timeout);
6262
}
6363
}

src/Locator/Options/GetAttributeOptions.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414

1515
namespace Playwright\Locator\Options;
1616

17-
use Playwright\Exception\InvalidArgumentException;
18-
1917
class GetAttributeOptions
2018
{
2119
public function __construct(
2220
public ?float $timeout = null,
2321
) {
2422
}
2523

24+
/**
25+
* @return array<string, mixed>
26+
*/
2627
public function toArray(): array
2728
{
2829
$options = [];
@@ -42,12 +43,9 @@ public static function from(array|self $options = []): self
4243
return $options;
4344
}
4445

45-
if (!\is_array($options)) {
46-
throw new InvalidArgumentException('Options must be an array or an instance of GetAttributeOptions');
47-
}
46+
/** @var float|null $timeout */
47+
$timeout = $options['timeout'] ?? null;
4848

49-
return new self(
50-
$options['timeout'] ?? null,
51-
);
49+
return new self($timeout);
5250
}
5351
}

src/Locator/Options/GetByRoleOptions.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public function toArray(): array
8888
return $options;
8989
}
9090

91+
/**
92+
* @param array<string, mixed> $options
93+
*/
9194
private static function extractBool(array $options, string $key): ?bool
9295
{
9396
if (!array_key_exists($key, $options)) {
@@ -106,6 +109,9 @@ private static function extractBool(array $options, string $key): ?bool
106109
return $value;
107110
}
108111

112+
/**
113+
* @param array<string, mixed> $options
114+
*/
109115
private static function extractLevel(array $options): ?int
110116
{
111117
if (!array_key_exists('level', $options)) {
@@ -128,6 +134,9 @@ private static function extractLevel(array $options): ?int
128134
throw new RuntimeException('getByRole option "level" must be an integer.');
129135
}
130136

137+
/**
138+
* @param array<string, mixed> $options
139+
*/
131140
private static function extractName(array $options): ?string
132141
{
133142
if (!array_key_exists('name', $options)) {
@@ -146,16 +155,24 @@ private static function extractName(array $options): ?string
146155
throw new RuntimeException('getByRole option "name" must be stringable.');
147156
}
148157

158+
/**
159+
* @return array<string, mixed>
160+
*/
149161
private function filteredLocatorOptions(): array
150162
{
151163
$options = $this->locatorOptions->toArray();
152164
foreach (self::ROLE_KEYS as $key) {
153-
unset($options[$key]);
165+
if (array_key_exists($key, $options)) {
166+
unset($options[$key]);
167+
}
154168
}
155169

156170
return $options;
157171
}
158172

173+
/**
174+
* @param array<string, mixed> $options
175+
*/
159176
private function appendIfNotNull(array &$options, string $key, mixed $value): void
160177
{
161178
if (null === $value) {

src/Locator/Options/HoverOptions.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
namespace Playwright\Locator\Options;
1616

17-
use Playwright\Exception\InvalidArgumentException;
18-
1917
class HoverOptions
2018
{
2119
/**
@@ -32,6 +30,9 @@ public function __construct(
3230
) {
3331
}
3432

33+
/**
34+
* @return array<string, mixed>
35+
*/
3536
public function toArray(): array
3637
{
3738
$options = [];
@@ -66,17 +67,19 @@ public static function from(array|self $options = []): self
6667
return $options;
6768
}
6869

69-
if (!\is_array($options)) {
70-
throw new InvalidArgumentException('Options must be an array or an instance of HoverOptions');
71-
}
70+
/** @var array<string>|null $modifiers */
71+
$modifiers = $options['modifiers'] ?? null;
72+
/** @var array{x: float, y: float}|null $position */
73+
$position = $options['position'] ?? null;
74+
/** @var bool|null $force */
75+
$force = $options['force'] ?? null;
76+
/** @var bool|null $noWaitAfter */
77+
$noWaitAfter = $options['noWaitAfter'] ?? null;
78+
/** @var float|null $timeout */
79+
$timeout = $options['timeout'] ?? null;
80+
/** @var bool|null $trial */
81+
$trial = $options['trial'] ?? null;
7282

73-
return new self(
74-
$options['modifiers'] ?? null,
75-
$options['position'] ?? null,
76-
$options['force'] ?? null,
77-
$options['noWaitAfter'] ?? null,
78-
$options['timeout'] ?? null,
79-
$options['trial'] ?? null,
80-
);
83+
return new self($modifiers, $position, $force, $noWaitAfter, $timeout, $trial);
8184
}
8285
}

0 commit comments

Comments
 (0)