Skip to content

Commit a5052fd

Browse files
committed
phpstan 10
1 parent e07e60a commit a5052fd

7 files changed

Lines changed: 82 additions & 41 deletions

File tree

src/Asset/AssetMapperProxy.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ private function findAssetByPublicPath(string $publicPath): ?object
7070
if (method_exists($this->mapper, 'getAssetFromPublicPath')) {
7171
$asset = $this->mapper->getAssetFromPublicPath($publicPath);
7272
if (null !== $asset) {
73+
\assert(is_object($asset));
74+
7375
return $asset;
7476
}
7577
}
@@ -81,6 +83,8 @@ private function findAssetByPublicPath(string $publicPath): ?object
8183
if (method_exists($this->mapper, 'getAsset')) {
8284
$asset = $this->mapper->getAsset(ltrim($publicPath, '/'));
8385
if (null !== $asset) {
86+
\assert(is_object($asset));
87+
8488
return $asset;
8589
}
8690
}
@@ -103,7 +107,11 @@ private function getAssetIndex(): array
103107
return $this->assetIndex;
104108
}
105109

106-
foreach ($this->mapper->allAssets() as $candidate) {
110+
$allAssets = $this->mapper->allAssets();
111+
\assert(is_iterable($allAssets));
112+
113+
foreach ($allAssets as $candidate) {
114+
\assert(is_object($candidate));
107115
$candidatePath = $this->extractPublicPath($candidate);
108116
if (null === $candidatePath || isset($this->assetIndex[$candidatePath])) {
109117
continue;

src/BrowserKit/PlaywrightClient.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ protected function doRequest($request): BrowserKitResponse
104104
$response = $this->submitSyntheticForm(
105105
$uri,
106106
$method,
107-
$request->getParameters(),
108-
$request->getFiles(),
107+
$request->getParameters(), // @phpstan-ignore argument.type
108+
$request->getFiles(), // @phpstan-ignore argument.type
109109
(string) $request->getContent()
110110
);
111111
$this->lastResponse = $response;
@@ -276,7 +276,7 @@ private function applyServerParams(Request $request): void
276276
foreach ($server as $key => $value) {
277277
if (str_starts_with($key, 'HTTP_')) {
278278
$name = str_replace('_', '-', strtolower(substr($key, 5)));
279-
$headers[$name] = (string) $value;
279+
$headers[$name] = is_string($value) ? $value : (is_scalar($value) ? (string) $value : '');
280280
}
281281
}
282282
if (!empty($headers)) {
@@ -287,9 +287,11 @@ private function applyServerParams(Request $request): void
287287

288288
if (isset($server['PHP_AUTH_USER'], $server['PHP_AUTH_PW'])) {
289289
if (method_exists($this->context, 'setHttpCredentials')) {
290+
$username = $server['PHP_AUTH_USER'];
291+
$password = $server['PHP_AUTH_PW'];
290292
$this->context->setHttpCredentials([
291-
'username' => (string) $server['PHP_AUTH_USER'],
292-
'password' => (string) $server['PHP_AUTH_PW'],
293+
'username' => is_string($username) ? $username : (is_scalar($username) ? (string) $username : ''),
294+
'password' => is_string($password) ? $password : (is_scalar($password) ? (string) $password : ''),
293295
]);
294296
}
295297
}

src/Client/PlaywrightClient.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,6 @@ public function getCrawler(): Crawler
190190
return new Crawler($content, $page->url());
191191
}
192192

193-
194-
195193
/**
196194
* @param array<string, mixed> $options
197195
*/
@@ -382,16 +380,22 @@ protected function doRequest(object $request): BrowserKitResponse
382380

383381
private function setupRequestInterception(): void
384382
{
385-
$this->browser->setupRouting(function ($route) {
383+
$this->browser->setupRouting(function (mixed $route): void {
384+
if (!is_object($route) || !method_exists($route, 'request')) {
385+
return;
386+
}
386387
$request = $route->request();
388+
\assert($request instanceof RequestInterface);
387389
$url = parse_url($request->url());
388390

389391
if (!$this->shouldInterceptRequest($url)) {
390392
$this->log('debug', 'Continuing external request', [
391393
'url' => $request->url(),
392394
'method' => $request->method(),
393395
]);
394-
$route->continue();
396+
if (method_exists($route, 'continue')) {
397+
$route->continue();
398+
}
395399

396400
return;
397401
}
@@ -406,7 +410,9 @@ private function setupRequestInterception(): void
406410
'url' => $request->url(),
407411
'method' => $request->method(),
408412
]);
409-
$route->fulfill($assetResponse);
413+
if (method_exists($route, 'fulfill')) {
414+
$route->fulfill($assetResponse);
415+
}
410416

411417
return;
412418
}
@@ -418,7 +424,9 @@ private function setupRequestInterception(): void
418424
}
419425

420426
$response = $this->handleInternalRequest($request);
421-
$route->fulfill($this->responseConverter->prepareFulfillOptions($response));
427+
if (method_exists($route, 'fulfill')) {
428+
$route->fulfill($this->responseConverter->prepareFulfillOptions($response));
429+
}
422430
});
423431
}
424432

src/Client/RequestConverter.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private function extractBoundary(string $contentType): ?string
194194
}
195195

196196
/**
197-
* @return array<string, mixed>
197+
* @return array<mixed>
198198
*/
199199
private function parseContentDisposition(string $header): array
200200
{
@@ -212,10 +212,16 @@ private function parseContentDisposition(string $header): array
212212
}
213213
}
214214

215-
if (!empty($typePart)) {
216-
$assoc['type'] = strtolower($typePart[0]);
215+
if (!empty($typePart) && is_array($typePart) && isset($typePart[0])) {
216+
$firstPart = $typePart[0];
217+
if (is_string($firstPart)) {
218+
$assoc['type'] = strtolower($firstPart);
219+
} elseif (is_scalar($firstPart)) {
220+
$assoc['type'] = strtolower((string) $firstPart);
221+
}
217222
}
218223

224+
/* @var array<string, mixed> */
219225
return $assoc;
220226
}
221227

src/DependencyInjection/PlaywrightExtension.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,24 @@ public function load(array $configs, ContainerBuilder $container): void
4343
return;
4444
}
4545

46-
$container->setParameter('playwright.intercepted_hosts', $config['intercepted_hosts']);
47-
$container->setParameter('playwright.debug', $config['debug']);
48-
$container->setParameter('playwright.playwright_path', $config['playwright_path']);
49-
$container->setParameter('playwright.node_path', $config['node_path']);
50-
$container->setParameter('playwright.base_url', $config['base_url']);
51-
$container->setParameter('playwright.debug_logging', $config['debug_logging']);
46+
$container->setParameter('playwright.intercepted_hosts', $config['intercepted_hosts']); // @phpstan-ignore argument.type
47+
$container->setParameter('playwright.debug', $config['debug']); // @phpstan-ignore argument.type
48+
$container->setParameter('playwright.playwright_path', $config['playwright_path']); // @phpstan-ignore argument.type
49+
$container->setParameter('playwright.node_path', $config['node_path']); // @phpstan-ignore argument.type
50+
$container->setParameter('playwright.base_url', $config['base_url']); // @phpstan-ignore argument.type
51+
$container->setParameter('playwright.debug_logging', $config['debug_logging']); // @phpstan-ignore argument.type
5252
$assetConfig = $config['assets'] ?? [];
53-
$container->setParameter('playwright.asset_prefixes', $assetConfig['prefixes'] ?? ['/assets', '/build', '/_framework/ux']);
54-
$container->setParameter('playwright.asset_public_roots', $assetConfig['public_roots'] ?? ['%kernel.project_dir%/public']);
55-
$container->setParameter('playwright.asset_dev_no_cache', $assetConfig['disable_cache'] ?? true);
56-
57-
$this->registerBrowsers($container, $config['browsers'] ?? [], $config['default_browser'] ?? 'default');
53+
\assert(is_array($assetConfig));
54+
$container->setParameter('playwright.asset_prefixes', $assetConfig['prefixes'] ?? ['/assets', '/build', '/_framework/ux']); // @phpstan-ignore argument.type
55+
$container->setParameter('playwright.asset_public_roots', $assetConfig['public_roots'] ?? ['%kernel.project_dir%/public']); // @phpstan-ignore argument.type
56+
$container->setParameter('playwright.asset_dev_no_cache', $assetConfig['disable_cache'] ?? true); // @phpstan-ignore argument.type
57+
58+
$browsersConfig = $config['browsers'] ?? [];
59+
\assert(is_array($browsersConfig));
60+
/** @var array<string, mixed> $browsersConfig */
61+
$defaultBrowser = $config['default_browser'] ?? 'default';
62+
\assert(is_string($defaultBrowser));
63+
$this->registerBrowsers($container, $browsersConfig, $defaultBrowser);
5864

5965
$container->register(BrowserKitClient::class, BrowserKitClient::class)
6066
->setFactory([BrowserKitClient::class, 'fromContext'])

src/Util/CookieJarSync.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ public static function fromContext(CookieJar $jar, BrowserContextInterface $cont
3030
foreach ($context->cookies() as $c) {
3131
$jar->set(new Cookie(
3232
name: (string) $c['name'],
33-
value: (string) $c['value'],
34-
expires: $c['expires'],
35-
path: (string) $c['path'],
36-
domain: (string) $c['domain'],
37-
secure: (bool) $c['secure'],
38-
httponly: (bool) $c['httpOnly'],
33+
value: (string) ($c['value'] ?? ''), // @phpstan-ignore nullCoalesce.offset
34+
expires: $c['expires'] ?? null, // @phpstan-ignore nullCoalesce.offset
35+
path: (string) ($c['path'] ?? '/'), // @phpstan-ignore nullCoalesce.offset
36+
domain: (string) ($c['domain'] ?? ''), // @phpstan-ignore nullCoalesce.offset
37+
secure: (bool) ($c['secure'] ?? false), // @phpstan-ignore nullCoalesce.offset
38+
httponly: (bool) ($c['httpOnly'] ?? false), // @phpstan-ignore nullCoalesce.offset
3939
));
4040
}
4141
}
@@ -45,12 +45,12 @@ public static function toJarFromUrl(CookieJar $jar, BrowserContextInterface $con
4545
foreach ($context->cookies([$url]) as $c) {
4646
$jar->set(new Cookie(
4747
name: (string) $c['name'],
48-
value: (string) $c['value'],
49-
expires: $c['expires'],
50-
path: (string) $c['path'],
51-
domain: (string) $c['domain'],
52-
secure: (bool) $c['secure'],
53-
httponly: (bool) $c['httpOnly'],
48+
value: (string) ($c['value'] ?? ''), // @phpstan-ignore nullCoalesce.offset
49+
expires: $c['expires'] ?? null, // @phpstan-ignore nullCoalesce.offset
50+
path: (string) ($c['path'] ?? '/'), // @phpstan-ignore nullCoalesce.offset
51+
domain: (string) ($c['domain'] ?? ''), // @phpstan-ignore nullCoalesce.offset
52+
secure: (bool) ($c['secure'] ?? false), // @phpstan-ignore nullCoalesce.offset
53+
httponly: (bool) ($c['httpOnly'] ?? false), // @phpstan-ignore nullCoalesce.offset
5454
));
5555
}
5656
}

src/Util/FormInteractor.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ public static function fill(PageInterface $page, Form $form): void
3636

3737
if ('select' === $node->tagName) {
3838
$values = $field->getValue();
39-
$values = is_array($values) ? $values : [$values];
40-
$locator->selectOption($values);
39+
if (is_array($values)) {
40+
/** @var array<string> $stringValues */
41+
$stringValues = array_map(static fn (mixed $v): string => is_scalar($v) ? (string) $v : '', $values);
42+
$locator->selectOption($stringValues);
43+
} else {
44+
$locator->selectOption(is_scalar($values) ? (string) $values : '');
45+
}
4146
continue;
4247
}
4348

@@ -57,7 +62,13 @@ public static function fill(PageInterface $page, Form $form): void
5762
if ('file' === $type) {
5863
$value = $field->getValue();
5964
if ($value) {
60-
$locator->setInputFiles($value);
65+
if (is_array($value)) {
66+
/** @var array<string> $fileArray */
67+
$fileArray = array_map(static fn (mixed $v): string => is_scalar($v) ? (string) $v : '', $value);
68+
$locator->setInputFiles($fileArray);
69+
} else {
70+
$locator->setInputFiles((string) $value);
71+
}
6172
}
6273
continue;
6374
}

0 commit comments

Comments
 (0)