Skip to content

Commit e07e60a

Browse files
committed
phpstan 9
1 parent e7c2703 commit e07e60a

5 files changed

Lines changed: 26 additions & 37 deletions

File tree

phpstan.dist.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
parameters:
2-
level: 9
2+
level: 10
33
paths:
44
- src/

src/Client/PlaywrightClient.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class PlaywrightClient extends AbstractBrowser
4949
{
5050
private ?SymfonyRequest $lastSymfonyRequest = null;
5151
private ?SymfonyResponse $lastSymfonyResponse = null;
52-
private ?Crawler $lastCrawler = null;
5352
/** @var string[] */
5453
private array $interceptedHosts = ['localhost', '127.0.0.1', 'testapp.local'];
5554
private ?object $hookReceiver = null;
@@ -167,7 +166,7 @@ public function getCrawler(): Crawler
167166
{
168167
$page = $this->getPage();
169168
if (null === $page) {
170-
return $this->lastCrawler = new Crawler('', $this->baseUrl);
169+
return new Crawler('', $this->baseUrl);
171170
}
172171

173172
$content = '';
@@ -188,19 +187,10 @@ public function getCrawler(): Crawler
188187
}
189188
}
190189

191-
return $this->lastCrawler = new Crawler($content, $page->url());
190+
return new Crawler($content, $page->url());
192191
}
193192

194-
private function getNodeFromField(mixed $field): \DOMElement
195-
{
196-
$reflection = new \ReflectionClass($field);
197-
$property = $reflection->getProperty('node');
198-
$node = $property->getValue($field);
199-
200-
\assert($node instanceof \DOMElement);
201193

202-
return $node;
203-
}
204194

205195
/**
206196
* @param array<string, mixed> $options

src/Test/Assert/PlaywrightTestAssertionsTrait.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,21 @@ protected function assertResponseStatusCode(int $expectedCode): void
6565
{
6666
$response = $this->getLastResponse();
6767
$this->assertNotNull($response, 'No response available');
68-
if (null !== $response) {
69-
$this->assertSame($expectedCode, $response->getStatusCode(), sprintf('Expected status code %d, got %d', $expectedCode, $response->getStatusCode()));
70-
}
68+
$this->assertSame($expectedCode, $response->getStatusCode(), sprintf('Expected status code %d, got %d', $expectedCode, $response->getStatusCode()));
7169
}
7270

7371
protected function assertResponseIsSuccessful(): void
7472
{
7573
$response = $this->getLastResponse();
7674
$this->assertNotNull($response, 'No response available');
77-
if (null !== $response) {
78-
$this->assertTrue($response->isSuccessful(), sprintf('Expected successful response, got %d', $response->getStatusCode()));
79-
}
75+
$this->assertTrue($response->isSuccessful(), sprintf('Expected successful response, got %d', $response->getStatusCode()));
8076
}
8177

8278
protected function assertResponseIsRedirect(): void
8379
{
8480
$response = $this->getLastResponse();
8581
$this->assertNotNull($response, 'No response available');
86-
if (null !== $response) {
87-
$this->assertTrue($response->isRedirect(), sprintf('Expected redirect response, got %d', $response->getStatusCode()));
88-
}
82+
$this->assertTrue($response->isRedirect(), sprintf('Expected redirect response, got %d', $response->getStatusCode()));
8983
}
9084

9185
protected function click(string $selector): void

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: isset($c['expires']) ? (int) $c['expires'] : null,
35-
path: (string) ($c['path'] ?? '/'),
36-
domain: (string) ($c['domain'] ?? ''),
37-
secure: (bool) ($c['secure'] ?? false),
38-
httponly: (bool) ($c['httpOnly'] ?? false),
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'],
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: isset($c['expires']) ? (int) $c['expires'] : null,
50-
path: (string) ($c['path'] ?? '/'),
51-
domain: (string) ($c['domain'] ?? ''),
52-
secure: (bool) ($c['secure'] ?? false),
53-
httponly: (bool) ($c['httpOnly'] ?? false),
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'],
5454
));
5555
}
5656
}

src/Util/FormInteractor.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
namespace Playwright\Symfony\Util;
1616

1717
use Playwright\Page\PageInterface;
18+
use Symfony\Component\DomCrawler\Field\FormField;
1819
use Symfony\Component\DomCrawler\Form;
1920

2021
/**
@@ -31,7 +32,7 @@ public static function fill(PageInterface $page, Form $form): void
3132
$xpath = XPathHelper::buildXPath($node);
3233
$locator = $page->locator('xpath='.$xpath);
3334

34-
$type = strtolower($node->getAttribute('type') ?? '');
35+
$type = $node->getAttribute('type') ?: '';
3536

3637
if ('select' === $node->tagName) {
3738
$values = $field->getValue();
@@ -62,11 +63,15 @@ public static function fill(PageInterface $page, Form $form): void
6263
}
6364

6465
// Default: text-like inputs and textarea
65-
$locator->fill((string) $field->getValue());
66+
$value = $field->getValue();
67+
if (\is_array($value)) {
68+
$value = implode('', $value);
69+
}
70+
$locator->fill((string) $value);
6671
}
6772
}
6873

69-
private static function getNodeFromField(mixed $field): \DOMElement
74+
private static function getNodeFromField(FormField $field): \DOMElement
7075
{
7176
$reflection = new \ReflectionClass($field);
7277
$property = $reflection->getProperty('node');

0 commit comments

Comments
 (0)