Skip to content

Commit f466be0

Browse files
Merge pull request #54 from stevegrunwell/phpstan-2.x
Update to PHPStan 2.x (and reach level 10)
2 parents 69cc9b2 + fdca2a1 commit f466be0

File tree

5 files changed

+23
-17
lines changed

5 files changed

+23
-17
lines changed

.phpcs.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<exclude-pattern>tests/*</exclude-pattern>
1919
</rule>
2020

21-
<!-- Ensure we're compatible with PHP 5.6+ -->
21+
<!-- Ensure we're compatible with PHP 7.1+ -->
2222
<rule ref="PHPCompatibility"/>
2323
<config name="testVersion" value="7.1-"/>
2424
</ruleset>

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"require-dev": {
2323
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
2424
"phpcompatibility/php-compatibility": "^9.3",
25-
"phpstan/phpstan": "^1.10",
25+
"phpstan/phpstan": "^2.1",
2626
"squizlabs/php_codesniffer": "^3.7",
2727
"symfony/phpunit-bridge": "^5.2 || ^6.2 || ^7.0"
2828
},

phpstan.neon.dist

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
parameters:
2-
level: 6
2+
level: 10
3+
4+
# Code to be analyzed
35
paths:
46
- src
57
- tests
8+
9+
# Don't worry about the coverage reports
610
excludePaths:
7-
- tests/coverage
11+
- tests/coverage (?)
12+
13+
# PHPUnit Bridge puts the PHPUnit source in an unconventional location
14+
scanDirectories:
15+
- vendor/bin/.phpunit/phpunit

src/MarkupAssertionsTrait.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,7 @@ public function assertNotHasElementWithAttributes($attributes = [], $markup = ''
127127
*/
128128
public function assertElementContains($contents, $selector = '', $markup = '', $message = '')
129129
{
130-
$method = method_exists($this, 'assertStringContainsString')
131-
? 'assertStringContainsString'
132-
: 'assertContains'; // @codeCoverageIgnore
133-
134-
$this->$method(
130+
$this->assertStringContainsString(
135131
$contents,
136132
$this->getInnerHtmlOfMatchedElements($markup, $selector),
137133
$message
@@ -152,11 +148,7 @@ public function assertElementContains($contents, $selector = '', $markup = '', $
152148
*/
153149
public function assertElementNotContains($contents, $selector = '', $markup = '', $message = '')
154150
{
155-
$method = method_exists($this, 'assertStringNotContainsString')
156-
? 'assertStringNotContainsString'
157-
: 'assertNotContains'; // @codeCoverageIgnore
158-
159-
$this->$method(
151+
$this->assertStringNotContainsString(
160152
$contents,
161153
$this->getInnerHtmlOfMatchedElements($markup, $selector),
162154
$message
@@ -177,6 +169,7 @@ public function assertElementNotContains($contents, $selector = '', $markup = ''
177169
*/
178170
public function assertElementRegExp($regexp, $selector = '', $markup = '', $message = '')
179171
{
172+
// @phpstan-ignore function.alreadyNarrowedType (Introduced in PHPUnit 9.x, PHP 7.3+)
180173
$method = method_exists($this, 'assertMatchesRegularExpression')
181174
? 'assertMatchesRegularExpression'
182175
: 'assertRegExp'; // @codeCoverageIgnore
@@ -202,6 +195,7 @@ public function assertElementRegExp($regexp, $selector = '', $markup = '', $mess
202195
*/
203196
public function assertElementNotRegExp($regexp, $selector = '', $markup = '', $message = '')
204197
{
198+
// @phpstan-ignore function.alreadyNarrowedType (Introduced in PHPUnit 9.x, PHP 7.3+)
205199
$method = method_exists($this, 'assertDoesNotMatchRegularExpression')
206200
? 'assertDoesNotMatchRegularExpression'
207201
: 'assertNotRegExp'; // @codeCoverageIgnore
@@ -252,7 +246,7 @@ private function flattenAttributeArray(array $attributes)
252246
if (empty($value)) {
253247
$value = sprintf('[%s]', $key);
254248
} else {
255-
$value = sprintf('[%s="%s"]', $key, htmlspecialchars($value));
249+
$value = sprintf('[%s="%s"]', $key, htmlspecialchars((string) $value));
256250
}
257251
});
258252

@@ -276,10 +270,14 @@ private function getInnerHtmlOfMatchedElements($markup, $query)
276270

277271
// Loop through results and collect their innerHTML values.
278272
foreach ($results as $result) {
273+
if (!isset($result->firstChild)) {
274+
continue;
275+
}
276+
279277
$document = new \DOMDocument();
280278
$document->appendChild($document->importNode($result->firstChild, true));
281279

282-
$contents[] = trim(html_entity_decode($document->saveHTML()));
280+
$contents[] = trim(html_entity_decode((string) $document->saveHTML()));
283281
}
284282

285283
return implode(PHP_EOL, $contents);

tests/MarkupAssertionsTraitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public function getInnerHtmlOfMatchedElements_should_retrieve_the_inner_HTML(
285285
/**
286286
* Data provider for testFlattenAttributeArray().
287287
*
288-
* @return array<string,array{array<string,string>,string}>
288+
* @return array<string,array{array<string,?string>,string}>
289289
*/
290290
public function provideAttributes(): array
291291
{

0 commit comments

Comments
 (0)