Skip to content

Commit

Permalink
Consider a property type change as a signature change
Browse files Browse the repository at this point in the history
  • Loading branch information
tscni committed Jun 24, 2023
1 parent 703a4b4 commit a737ca8
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Psalm/Internal/Diff/ClassStatementsDiffer.php
Expand Up @@ -158,6 +158,22 @@ static function (
return false;
}

if ($a->type xor $b->type) {
return false;
}

if ($a->type && $b->type) {
$a_type_start = (int) $a->type->getAttribute('startFilePos');
$a_type_end = (int) $a->type->getAttribute('endFilePos');
$b_type_start = (int) $b->type->getAttribute('startFilePos');
$b_type_end = (int) $b->type->getAttribute('endFilePos');
if (substr($a_code, $a_type_start, $a_type_end - $a_type_start + 1)
!== substr($b_code, $b_type_start, $b_type_end - $b_type_start + 1)
) {
return false;
}
}

$body_change = substr($a_code, $a_comments_end, $a_end - $a_comments_end)
!== substr($b_code, $b_comments_end, $b_end - $b_comments_end);
} else {
Expand Down
57 changes: 57 additions & 0 deletions tests/FileDiffTest.php
Expand Up @@ -544,6 +544,63 @@ class A {
[],
[[84, 133]],
],
'propertyTypeAddition' => [
'<?php
namespace Foo;
class A {
public $a;
}',
'<?php
namespace Foo;
class A {
public string $a;
}',
[],
[],
['foo\a::$a', 'foo\a::$a'],
[],
[[84, 93]],
],
'propertyTypeRemoval' => [
'<?php
namespace Foo;
class A {
public string $a;
}',
'<?php
namespace Foo;
class A {
public $a;
}',
[],
[],
['foo\a::$a', 'foo\a::$a'],
[],
[[84, 100]],
],
'propertyTypeChange' => [
'<?php
namespace Foo;
class A {
public string $a;
}',
'<?php
namespace Foo;
class A {
public ?string $a;
}',
[],
[],
['foo\a::$a', 'foo\a::$a'],
[],
[[84, 100]],
],
'addDocblockToFirst' => [
'<?php
namespace Foo;
Expand Down

0 comments on commit a737ca8

Please sign in to comment.