-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(deps): phpstan major version 2 #305
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,7 +147,7 @@ function repeatingElements(Writer $writer, array $items, string $childElementNam | |
* | ||
* You can even mix the two array syntaxes. | ||
* | ||
* @param string|int|float|bool|array<int|string, mixed>|object $value | ||
* @param string|int|float|bool|array<int|string, mixed>|object|null $value | ||
*/ | ||
function standardSerializer(Writer $writer, $value): void | ||
{ | ||
|
@@ -181,7 +181,7 @@ function standardSerializer(Writer $writer, $value): void | |
// This item has a numeric index. We just loop through the | ||
// array and throw it back in the writer. | ||
standardSerializer($writer, $item); | ||
} elseif (is_string($name) && is_array($item) && isset($item['attributes'])) { | ||
} elseif (is_array($item) && isset($item['attributes'])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Array keys (name) have to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But as a result of looking into this, I don't understand why PHPstan allows the code at line 193, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. array keys are pretty magic and some auto-conversions are going on in the background in php-src (some strings are turned into numbers) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If someone tries to have a key |
||
// The key is used for a name, but $item has 'attributes' and | ||
// possibly 'value' | ||
$writer->startElement($name); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
parameters: | ||
ignoreErrors: | ||
ignoreErrors: | ||
- | ||
message: "#^Call to function is_null\\(\\) with null will always evaluate to true\\.$#" | ||
path: lib/Serializer/functions.php | ||
count: 1 | ||
Comment on lines
+4
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This message is emitted because of line 204
The if-else cases already processed all the possible types according to the type declaration of But someone could pass some other unusual type of value to |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,9 +182,6 @@ public function testEmptyPropfind(string $xml): void | |
$util->namespaceMap = [ | ||
'http://sabre.io/ns' => 'stdClass', | ||
]; | ||
/** | ||
* @var PropFindTestAsset | ||
*/ | ||
Comment on lines
-185
to
-187
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better not to tell the test code what |
||
$result = $util->expect('{DAV:}propfind', $xml); | ||
self::assertIsObject($result); | ||
self::assertInstanceOf(PropFindTestAsset::class, $result); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function actually does let you pass
null
to it, and will just "do nothing" to the Writer object. In that case there is nothing to serialize but it does not complain about that.Telling PHPstan that
null
is possible, stops it complaining aboutelseif (is_object($value))
below - it now understands that$value
could benull
or an object at that point.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the "good thing" to do for situations like this?
An input parameter allows some "complicated" set of inputs/types.
It is too complicated to be expressed in the actual PHP function declaration.
So at run-time PHP will actually let the caller pass anything in the parameter.
The function code checks the input parameter, doing "the expected thing" to process inputs of each of the "officially allowed" inputs.
The function code throws an exception if the passed-in value is not one of the "officially allowed" inputs. But PHPstan is going to consider that that is "useless" code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this defensive style of programming you should set
treatPhpDocTypesAsCertain: false
in the PHPStan configThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I do that, it will apply to all the code. So I just added the entry to
ignoreErrors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, if you are fine with ignoring the error thats fine, too.