Skip to content
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

report error for single param name mismatch too since named args can even be used then #10822

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/Psalm/Internal/Analyzer/MethodComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
use Psalm\Type\Union;

use function array_filter;
use function count;
use function in_array;
use function strpos;
use function strtolower;
Expand Down Expand Up @@ -457,10 +456,8 @@ private static function compareMethodParams(
$implementer_param->location->file_path,
)
) {
if (!$guide_classlike_storage->user_defined && $i === 0 && count($guide_method_storage->params) < 2) {
// if it's third party defined and a single arg, renaming is unnecessary
// if we still want to psalter it, move this if and change the else below to elseif
} elseif ($config->allow_named_arg_calls
// even if it's just a single arg, it needs to be renamed in case it's called with a single named arg
if ($config->allow_named_arg_calls
kkmuffme marked this conversation as resolved.
Show resolved Hide resolved
|| ($guide_classlike_storage->location
&& !$config->isInProjectDirs($guide_classlike_storage->location->file_path)
)
Expand Down
4 changes: 2 additions & 2 deletions tests/MethodCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1144,9 +1144,9 @@ public static function new() : self {

class Datetime extends \DateTime
{
public static function createFromInterface(\DateTimeInterface $datetime): static
public static function createFromInterface(\DateTimeInterface $object): static
{
return parent::createFromInterface($datetime);
return parent::createFromInterface($object);
}
}',
'assertions' => [],
Expand Down
25 changes: 20 additions & 5 deletions tests/MethodSignatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,13 @@ class A implements Serializable {
private $id = 1;

/**
* @param string $serialized
* @param string $data
*/
public function unserialize($serialized) : void
public function unserialize($data) : void
{
[
$this->id,
] = (array) \unserialize($serialized);
] = (array) \unserialize($data);
}

public function serialize() : string
Expand Down Expand Up @@ -1060,6 +1060,21 @@ public function fooFoo(int $a, bool $c): void {
}',
'error_message' => 'ParamNameMismatch',
],
'differentArgumentName' => [
'code' => '<?php
class A {
public function fooFoo(int $a): void {

}
}

class B extends A {
public function fooFoo(int $b): void {

}
}',
'error_message' => 'ParamNameMismatch',
],
'nonNullableSubclassParam' => [
'code' => '<?php
class A {
Expand Down Expand Up @@ -1398,8 +1413,8 @@ public function foo($s) : void {}
'preventImplementingSerializableWithWrongDocblockType' => [
'code' => '<?php
class Foo implements \Serializable {
/** @param int $serialized */
public function unserialize($serialized) {}
/** @param int $data */
public function unserialize($data) {}
public function serialize() {}
}',
'error_message' => 'ImplementedParamTypeMismatch',
Expand Down
2 changes: 1 addition & 1 deletion tests/UnusedCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ public function serialize() : string {
return "";
}

public function unserialize($_serialized) : void {}
public function unserialize($data) : void {}
}

new Foo();',
Expand Down