Skip to content

Commit

Permalink
report error for single param too since named args can even be used then
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmuffme committed Mar 13, 2024
1 parent 4ea41cb commit a2307ac
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
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
|| ($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

0 comments on commit a2307ac

Please sign in to comment.