-
Notifications
You must be signed in to change notification settings - Fork 77
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
Increase phpstan from level 6 to level 8 #251
Changes from 6 commits
25373c4
c8795a0
ade9d87
0f54dcf
924cd8b
afdfb31
fe75c5e
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 |
---|---|---|
|
@@ -73,7 +73,7 @@ public function xmlSerialize(Xml\Writer $writer): void | |
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to | ||
* the next element. | ||
* | ||
* @return array<string, mixed>|string|null | ||
* @return array<int,array<string, mixed>>|string|null | ||
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 was an existing error in the PHPdoc. This thing returns an array of arrays. |
||
*/ | ||
public static function xmlDeserialize(Xml\Reader $reader) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,7 @@ public function xmlSerialize(Xml\Writer $writer): void | |
{ | ||
$writer->text( | ||
resolve( | ||
$writer->contextUri, | ||
$writer->contextUri ?? '', | ||
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->value | ||
) | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,7 +105,7 @@ public function parse(): array | |
* | ||
* @param array<string, mixed>|null $elementMap | ||
* | ||
* @return array<string, mixed> | ||
* @return array<int,array<string, mixed>> | ||
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 was an existing error in the PHPdoc. This thing returns an array of arrays. |
||
*/ | ||
public function parseGetElements(array $elementMap = null): array | ||
{ | ||
|
@@ -130,7 +130,7 @@ public function parseGetElements(array $elementMap = null): array | |
* | ||
* @param array<string, mixed>|null $elementMap | ||
* | ||
* @return array<string, mixed>|string|null | ||
* @return array<int,array<string, mixed>>|string|null | ||
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 was an existing error in the PHPdoc. This thing returns an array of arrays. |
||
*/ | ||
public function parseInnerTree(array $elementMap = null) | ||
{ | ||
|
@@ -298,14 +298,14 @@ public function getDeserializerForElementName(string $name): callable | |
} | ||
|
||
$deserializer = $this->elementMap[$name]; | ||
if (is_subclass_of($deserializer, 'Sabre\\Xml\\XmlDeserializable')) { | ||
return [$deserializer, 'xmlDeserialize']; | ||
} | ||
|
||
if (is_callable($deserializer)) { | ||
return $deserializer; | ||
} | ||
|
||
if (is_subclass_of($deserializer, 'Sabre\\Xml\\XmlDeserializable')) { | ||
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.
|
||
return [$deserializer, 'xmlDeserialize']; | ||
} | ||
|
||
$type = gettype($deserializer); | ||
if (is_string($deserializer)) { | ||
$type .= ' ('.$deserializer.')'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -241,6 +241,7 @@ public function write(string $rootElementName, $value, string $contextUri = null | |
public function mapValueObject(string $elementName, string $className): void | ||
{ | ||
list($namespace) = self::parseClarkNotation($elementName); | ||
$namespace = $namespace ?? ''; | ||
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.
Same for a few place in Writer.php below. |
||
|
||
$this->elementMap[$elementName] = function (Reader $reader) use ($className, $namespace) { | ||
return \Sabre\Xml\Deserializer\valueObject($reader, $className, $namespace); | ||
|
phil-davis marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
I can't see a way to get to this code.
When I try to make a unit test that passes a function reference like "SomeValidClass::unknownMethod", then PHP notices that during the call to
functionCaller
. Even though the string passed looks like a reasonable format for a callable thing, at run-time PHP checks if the method exists in the class. And the test fails with:So PHP really verifies that the thing passed in as parameter
$func
not only looks like it could be callable, but that it is actually callable.So in real-life we don't need all this double-checking.
I will see if there is a simpler way of coding this and keeping phpstan happy at the same time.