Skip to content

Commit 4c22ea1

Browse files
authored
ci: fix PHPStan and PHP CS Fixer (#483)
* fix: PHPStan * fix: php-cs-fixer
1 parent 66c1e38 commit 4c22ea1

25 files changed

+66
-78
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/.php_cs.cache
2-
/.php_cs
1+
/.php-cs-fixer.php
2+
/.php-cs-fixer.cache
33
/.phpunit.result.cache
44
/composer.phar
55
/composer.lock

.php_cs.dist renamed to .php-cs-fixer.dist.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
$finder = PhpCsFixer\Finder::create()->in(__DIR__);
1313

14-
return PhpCsFixer\Config::create()
14+
return (new PhpCsFixer\Config())
1515
->setRiskyAllowed(true)
1616
->setRules([
1717
'@Symfony' => true,
@@ -29,25 +29,13 @@
2929
],
3030
'modernize_types_casting' => true,
3131
'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced'],
32-
'no_extra_consecutive_blank_lines' => [
33-
'break',
34-
'continue',
35-
'curly_brace_block',
36-
'extra',
37-
'parenthesis_brace_block',
38-
'return',
39-
'square_brace_block',
40-
'throw',
41-
'use',
42-
],
4332
'no_useless_else' => true,
4433
'no_useless_return' => true,
4534
'ordered_imports' => true,
4635
'phpdoc_add_missing_param_annotation' => [
4736
'only_untyped' => true,
4837
],
4938
'phpdoc_order' => true,
50-
'psr4' => true,
5139
'semicolon_after_instruction' => true,
5240
'strict_comparison' => true,
5341
'strict_param' => true,

src/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public function request(string $method, string $uri, array $parameters = [], arr
269269

270270
foreach (['parameters', 'files', 'server'] as $arg) {
271271
if ([] !== $$arg) {
272-
throw new \InvalidArgumentException(\sprintf('The parameter "$%s" is not supported when using WebDriver.', $arg));
272+
throw new \InvalidArgumentException(sprintf('The parameter "$%s" is not supported when using WebDriver.', $arg));
273273
}
274274
}
275275

@@ -524,7 +524,7 @@ public function get($url): self
524524
$this->start();
525525

526526
// Prepend the base URI to URIs without a host
527-
if (null !== $this->baseUri && (false !== $components = \parse_url($url)) && !isset($components['host'])) {
527+
if (null !== $this->baseUri && (false !== $components = parse_url($url)) && !isset($components['host'])) {
528528
$url = $this->baseUri.$url;
529529
}
530530

src/DomCrawler/Crawler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,19 +247,19 @@ public function filter($selector): self
247247
public function selectLink($value): self
248248
{
249249
return $this->selectFromXpath(
250-
\sprintf('descendant-or-self::a[contains(concat(\' \', normalize-space(string(.)), \' \'), %1$s) or ./img[contains(concat(\' \', normalize-space(string(@alt)), \' \'), %1$s)]]', self::xpathLiteral(' '.$value.' '))
250+
sprintf('descendant-or-self::a[contains(concat(\' \', normalize-space(string(.)), \' \'), %1$s) or ./img[contains(concat(\' \', normalize-space(string(@alt)), \' \'), %1$s)]]', self::xpathLiteral(' '.$value.' '))
251251
);
252252
}
253253

254254
public function selectImage($value): self
255255
{
256-
return $this->selectFromXpath(\sprintf('descendant-or-self::img[contains(normalize-space(string(@alt)), %s)]', self::xpathLiteral($value)));
256+
return $this->selectFromXpath(sprintf('descendant-or-self::img[contains(normalize-space(string(@alt)), %s)]', self::xpathLiteral($value)));
257257
}
258258

259259
public function selectButton($value): self
260260
{
261261
return $this->selectFromXpath(
262-
\sprintf(
262+
sprintf(
263263
'descendant-or-self::input[((contains(%1$s, "submit") or contains(%1$s, "button")) and contains(concat(\' \', normalize-space(string(@value)), \' \'), %2$s)) or (contains(%1$s, "image") and contains(concat(\' \', normalize-space(string(@alt)), \' \'), %2$s)) or @id=%3$s or @name=%3$s] | descendant-or-self::button[contains(concat(\' \', normalize-space(string(.)), \' \'), %2$s) or @id=%3$s or @name=%3$s]',
264264
'translate(@type, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")',
265265
self::xpathLiteral(' '.$value.' '),
@@ -376,7 +376,7 @@ private function createSubCrawlerFromXpath(string $selector, bool $reverse = fal
376376
return $this->createSubCrawler();
377377
}
378378

379-
return $this->createSubCrawler($reverse ? \array_reverse($elements) : $elements);
379+
return $this->createSubCrawler($reverse ? array_reverse($elements) : $elements);
380380
}
381381

382382
private function filterWebDriverBy(WebDriverBy $selector): self

src/DomCrawler/Field/ChoiceFormField.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function select($value): void
5959
public function tick(): void
6060
{
6161
if ('checkbox' !== $type = $this->element->getAttribute('type')) {
62-
throw new \LogicException(\sprintf('You cannot tick "%s" as it is not a checkbox (%s).', $this->element->getAttribute('name'), $type));
62+
throw new \LogicException(sprintf('You cannot tick "%s" as it is not a checkbox (%s).', $this->element->getAttribute('name'), $type));
6363
}
6464

6565
$this->setValue(true);
@@ -73,7 +73,7 @@ public function tick(): void
7373
public function untick(): void
7474
{
7575
if ('checkbox' !== $type = $this->element->getAttribute('type')) {
76-
throw new \LogicException(\sprintf('You cannot tick "%s" as it is not a checkbox (%s).', $this->element->getAttribute('name'), $type));
76+
throw new \LogicException(sprintf('You cannot tick "%s" as it is not a checkbox (%s).', $this->element->getAttribute('name'), $type));
7777
}
7878

7979
$this->setValue(false);
@@ -97,7 +97,7 @@ public function getValue()
9797

9898
$count = \count($value);
9999
if (1 === $count && 'checkbox' === $type) {
100-
return \current($value);
100+
return current($value);
101101
}
102102

103103
return $value;
@@ -121,7 +121,7 @@ public function setValue($value): void
121121
{
122122
if (\is_bool($value)) {
123123
if ('checkbox' !== $this->type) {
124-
throw new \InvalidArgumentException(\sprintf('Invalid argument of type "%s"', \gettype($value)));
124+
throw new \InvalidArgumentException(sprintf('Invalid argument of type "%s"', \gettype($value)));
125125
}
126126

127127
if ($value) {
@@ -196,12 +196,12 @@ protected function initialize(): void
196196
{
197197
$tagName = $this->element->getTagName();
198198
if ('input' !== $tagName && 'select' !== $tagName) {
199-
throw new \LogicException(\sprintf('A ChoiceFormField can only be created from an input or select tag (%s given).', $tagName));
199+
throw new \LogicException(sprintf('A ChoiceFormField can only be created from an input or select tag (%s given).', $tagName));
200200
}
201201

202-
$type = \strtolower((string) $this->element->getAttribute('type'));
202+
$type = strtolower((string) $this->element->getAttribute('type'));
203203
if ('input' === $tagName && 'checkbox' !== $type && 'radio' !== $type) {
204-
throw new \LogicException(\sprintf('A ChoiceFormField can only be created from an input tag with a type of checkbox or radio (given type is %s).', $type));
204+
throw new \LogicException(sprintf('A ChoiceFormField can only be created from an input tag with a type of checkbox or radio (given type is %s).', $type));
205205
}
206206

207207
$this->type = 'select' === $tagName ? 'select' : $type;

src/DomCrawler/Field/FileFormField.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public function setValue($value): void
3636
{
3737
$value = $this->sanitizeValue($value);
3838

39-
if (null !== $value && \is_readable($value)) {
39+
if (null !== $value && is_readable($value)) {
4040
$error = \UPLOAD_ERR_OK;
41-
$size = \filesize($value);
42-
$name = \pathinfo($value, \PATHINFO_BASENAME);
41+
$size = filesize($value);
42+
$name = pathinfo($value, \PATHINFO_BASENAME);
4343

4444
$this->setFilePath($value);
4545
$value = $this->element->getAttribute('value');
@@ -72,12 +72,12 @@ protected function initialize(): void
7272
{
7373
$tagName = $this->element->getTagName();
7474
if ('input' !== $tagName) {
75-
throw new \LogicException(\sprintf('A FileFormField can only be created from an input tag (%s given).', $tagName));
75+
throw new \LogicException(sprintf('A FileFormField can only be created from an input tag (%s given).', $tagName));
7676
}
7777

78-
$type = \strtolower($this->element->getAttribute('type'));
78+
$type = strtolower($this->element->getAttribute('type'));
7979
if ('file' !== $type) {
80-
throw new \LogicException(\sprintf('A FileFormField can only be created from an input tag with a type of file (given type is %s).', $type));
80+
throw new \LogicException(sprintf('A FileFormField can only be created from an input tag with a type of file (given type is %s).', $type));
8181
}
8282

8383
$value = $this->element->getAttribute('value');
@@ -95,16 +95,16 @@ private function setValueFromTmp(string $tmpValue): void
9595
// size not determinable
9696
$size = 0;
9797
// C:\fakepath\filename.extension
98-
$basename = \pathinfo($value, \PATHINFO_BASENAME);
99-
$nameParts = \explode('\\', $basename);
100-
$name = \end($nameParts);
98+
$basename = pathinfo($value, \PATHINFO_BASENAME);
99+
$nameParts = explode('\\', $basename);
100+
$name = end($nameParts);
101101

102102
$this->value = ['name' => $name, 'type' => '', 'tmp_name' => $value, 'error' => $error, 'size' => $size];
103103
}
104104

105105
private function sanitizeValue(?string $value): ?string
106106
{
107-
$realpathValue = \is_string($value) && $value ? \realpath($value) : false;
107+
$realpathValue = \is_string($value) && $value ? realpath($value) : false;
108108
if (\is_string($realpathValue)) {
109109
$value = $realpathValue;
110110
}

src/DomCrawler/Field/FormFieldTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private function setTextValue($value): void
6868
}
6969

7070
$existingValueLength = \strlen($v);
71-
$deleteKeys = \str_repeat(WebDriverKeys::BACKSPACE.WebDriverKeys::DELETE, $existingValueLength);
71+
$deleteKeys = str_repeat(WebDriverKeys::BACKSPACE.WebDriverKeys::DELETE, $existingValueLength);
7272
$this->element->sendKeys($deleteKeys.$value);
7373
}
7474
}

src/DomCrawler/Field/InputFormField.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ protected function initialize(): void
4848
{
4949
$tagName = $this->element->getTagName();
5050
if ('input' !== $tagName && 'button' !== $tagName) {
51-
throw new \LogicException(\sprintf('An InputFormField can only be created from an input or button tag (%s given).', $tagName));
51+
throw new \LogicException(sprintf('An InputFormField can only be created from an input or button tag (%s given).', $tagName));
5252
}
5353

54-
$type = \strtolower((string) $this->element->getAttribute('type'));
54+
$type = strtolower((string) $this->element->getAttribute('type'));
5555
if ('checkbox' === $type) {
5656
throw new \LogicException('Checkboxes should be instances of ChoiceFormField.');
5757
}

src/DomCrawler/Field/TextareaFormField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected function initialize(): void
3636
{
3737
$tagName = $this->element->getTagName();
3838
if ('textarea' !== $tagName) {
39-
throw new \LogicException(\sprintf('A TextareaFormField can only be created from a textarea tag (%s given).', $tagName));
39+
throw new \LogicException(sprintf('A TextareaFormField can only be created from a textarea tag (%s given).', $tagName));
4040
}
4141
}
4242
}

src/DomCrawler/Form.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ private function setElement(WebDriverElement $element): void
6060
{
6161
$this->button = $element;
6262
$tagName = $element->getTagName();
63-
if ('button' === $tagName || ('input' === $tagName && \in_array(\strtolower($element->getAttribute('type')), ['submit', 'button', 'image'], true))) {
63+
if ('button' === $tagName || ('input' === $tagName && \in_array(strtolower($element->getAttribute('type')), ['submit', 'button', 'image'], true))) {
6464
if (null !== $formId = $element->getAttribute('form')) {
6565
// if the node has the HTML5-compliant 'form' attribute, use it
6666
try {
6767
$form = $this->webDriver->findElement(WebDriverBy::id($formId));
6868
} catch (NoSuchElementException $e) {
69-
throw new \LogicException(\sprintf('The selected node has an invalid form attribute (%s).', $formId));
69+
throw new \LogicException(sprintf('The selected node has an invalid form attribute (%s).', $formId));
7070
}
7171

7272
$this->element = $form;
@@ -82,7 +82,7 @@ private function setElement(WebDriverElement $element): void
8282
}
8383
} while ('form' !== $element->getTagName());
8484
} elseif ('form' !== $tagName = $element->getTagName()) {
85-
throw new \LogicException(\sprintf('Unable to submit on a "%s" tag.', $tagName));
85+
throw new \LogicException(sprintf('Unable to submit on a "%s" tag.', $tagName));
8686
}
8787

8888
$this->element = $element;
@@ -132,10 +132,10 @@ public function getValues(): array
132132

133133
$value = $this->getValue($element);
134134

135-
$isArrayElement = \is_array($value) && '[]' === \substr($name, -2);
135+
$isArrayElement = \is_array($value) && '[]' === substr($name, -2);
136136
if ($isArrayElement) {
137137
// compatibility with the DomCrawler API
138-
$name = \substr($name, 0, -2);
138+
$name = substr($name, 0, -2);
139139
}
140140

141141
if ('checkbox' === $type) {
@@ -185,10 +185,10 @@ public function getMethod(): string
185185

186186
// If the form was created from a button rather than the form node, check for HTML5 method override
187187
if ($this->button !== $this->element && null !== $this->button->getAttribute('formmethod')) {
188-
return \strtoupper($this->button->getAttribute('formmethod'));
188+
return strtoupper($this->button->getAttribute('formmethod'));
189189
}
190190

191-
return $this->element->getAttribute('method') ? \strtoupper($this->element->getAttribute('method')) : 'GET';
191+
return $this->element->getAttribute('method') ? strtoupper($this->element->getAttribute('method')) : 'GET';
192192
}
193193

194194
public function has($name): bool
@@ -263,7 +263,7 @@ protected function getRawUri(): string
263263
private function getFormElement(string $name): WebDriverElement
264264
{
265265
return $this->element->findElement(WebDriverBy::xpath(
266-
\sprintf('.//input[@name=%1$s] | .//textarea[@name=%1$s] | .//select[@name=%1$s] | .//button[@name=%1$s] | .//input[@name=%2$s] | .//textarea[@name=%2$s] | .//select[@name=%2$s] | .//button[@name=%2$s]', XPathEscaper::escapeQuotes($name), XPathEscaper::escapeQuotes($name.'[]'))
266+
sprintf('.//input[@name=%1$s] | .//textarea[@name=%1$s] | .//select[@name=%1$s] | .//button[@name=%1$s] | .//input[@name=%2$s] | .//textarea[@name=%2$s] | .//select[@name=%2$s] | .//button[@name=%2$s]', XPathEscaper::escapeQuotes($name), XPathEscaper::escapeQuotes($name.'[]'))
267267
));
268268
}
269269

src/DomCrawler/Image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class Image extends BaseImage
2929
public function __construct(WebDriverElement $element)
3030
{
3131
if ('img' !== $tagName = $element->getTagName()) {
32-
throw new \LogicException(\sprintf('Unable to visualize a "%s" tag.', $tagName));
32+
throw new \LogicException(sprintf('Unable to visualize a "%s" tag.', $tagName));
3333
}
3434

3535
$this->element = $element;

src/DomCrawler/Link.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(WebDriverElement $element, string $currentUri)
3030
{
3131
$tagName = $element->getTagName();
3232
if ('a' !== $tagName && 'area' !== $tagName && 'link' !== $tagName) {
33-
throw new \LogicException(\sprintf('Unable to navigate from a "%s" tag.', $tagName));
33+
throw new \LogicException(sprintf('Unable to navigate from a "%s" tag.', $tagName));
3434
}
3535

3636
$this->element = $element;

src/ExceptionThrower.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ trait ExceptionThrower
2222
{
2323
private function createNotSupportedException(string $method): \InvalidArgumentException
2424
{
25-
return new \InvalidArgumentException(\sprintf('The "%s" method is not supported when using WebDriver.', $method));
25+
return new \InvalidArgumentException(sprintf('The "%s" method is not supported when using WebDriver.', $method));
2626
}
2727
}

src/PantherTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use PHPUnit\Framework\TestCase;
1717
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
1818

19-
if (\class_exists(WebTestCase::class)) {
19+
if (class_exists(WebTestCase::class)) {
2020
abstract class PantherTestCase extends WebTestCase
2121
{
2222
use WebTestAssertionsTrait;

src/PantherTestCaseTrait.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ public static function isWebServerStarted(): bool
147147

148148
public function takeScreenshotIfTestFailed(): void
149149
{
150-
if (!in_array($this->getStatus(), [BaseTestRunner::STATUS_ERROR, BaseTestRunner::STATUS_FAILURE])) {
150+
if (!\in_array($this->getStatus(), [BaseTestRunner::STATUS_ERROR, BaseTestRunner::STATUS_FAILURE], true)) {
151151
return;
152152
}
153153

154-
$type = $this->getStatus() === BaseTestRunner::STATUS_FAILURE ? 'failure' : 'error';
154+
$type = BaseTestRunner::STATUS_FAILURE === $this->getStatus() ? 'failure' : 'error';
155155
$test = $this->toString();
156156

157157
ServerExtension::takeScreenshots($type, $test);
@@ -186,7 +186,7 @@ protected static function createPantherClient(array $options = [], array $kernel
186186
self::$pantherClients[0] = self::$pantherClient = Client::createFirefoxClient(null, null, $managerOptions, self::$baseUri);
187187
}
188188

189-
if (\is_a(self::class, KernelTestCase::class, true)) {
189+
if (is_a(self::class, KernelTestCase::class, true)) {
190190
static::bootKernel($kernelOptions); // @phpstan-ignore-line
191191
}
192192

@@ -224,7 +224,7 @@ protected static function createHttpBrowserClient(array $options = [], array $ke
224224
self::$httpBrowserClient = new HttpBrowserClient(HttpClient::create());
225225
}
226226

227-
if (\is_a(self::class, KernelTestCase::class, true)) {
227+
if (is_a(self::class, KernelTestCase::class, true)) {
228228
static::bootKernel($kernelOptions); // @phpstan-ignore-line
229229
}
230230

src/ProcessManager/WebServerReadinessProbeTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ private function checkPortAvailable(string $hostname, int $port, bool $throw = t
3636
if (\is_resource($resource)) {
3737
fclose($resource);
3838
if ($throw) {
39-
throw new \RuntimeException(\sprintf('The port %d is already in use.', $port));
39+
throw new \RuntimeException(sprintf('The port %d is already in use.', $port));
4040
}
4141
}
4242
}

src/ServerExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class ServerExtension implements BeforeFirstTestHook, AfterLastTestHook, B
3535

3636
public static function registerClient(Client $client): void
3737
{
38-
if (self::$enabled && !in_array($client, self::$registeredClients, true)) {
38+
if (self::$enabled && !\in_array($client, self::$registeredClients, true)) {
3939
self::$registeredClients[] = $client;
4040
}
4141
}

0 commit comments

Comments
 (0)