Skip to content

Commit

Permalink
Merge pull request #10821 from kkmuffme/consistent-constructor-param-…
Browse files Browse the repository at this point in the history
…name-mismatch
  • Loading branch information
weirdan committed Mar 20, 2024
2 parents 3a1b10f + 9cfce37 commit cc5ad67
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/running_psalm/issues/ConstructorSignatureMismatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Emitted when a constructor parameter differs from a parent constructor parameter
* @psalm-consistent-constructor
*/
class A {
public function __construct(int $i) {}
public function __construct(int $s) {}
}
class B extends A {
public function __construct(string $s) {}
Expand Down
4 changes: 3 additions & 1 deletion src/Psalm/Internal/Analyzer/MethodComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,9 @@ private static function compareMethodParams(
&& $implementer_classlike_storage->user_defined
&& $implementer_param->location
&& $guide_method_storage->cased_name
&& strpos($guide_method_storage->cased_name, '__') !== 0
&& (strpos($guide_method_storage->cased_name, '__') !== 0
|| ($guide_classlike_storage->preserve_constructor_signature
&& $guide_method_storage->cased_name === '__construct'))
&& $config->isInProjectDirs(
$implementer_param->location->file_path,
)
Expand Down
23 changes: 23 additions & 0 deletions tests/ClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,29 @@ class A {}
echo A::HELLO;',
'error_message' => 'UndefinedConstant',
],
'consistentNamesConstructor' => [
'code' => '<?php
/**
* @psalm-consistent-constructor
*/
class A
{
public function __construct(
string $name,
string $email,
) {}
}
class B extends A
{
public function __construct(
string $names,
string $email,
) {}
}
',
'error_message' => 'ParamNameMismatch',
],
'overridePublicAccessLevelToPrivate' => [
'code' => '<?php
class A {
Expand Down

0 comments on commit cc5ad67

Please sign in to comment.