Skip to content

Commit 10b0765

Browse files
Narrow types
1 parent 8d82a6f commit 10b0765

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Diff.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@
1111

1212
final class Diff
1313
{
14+
/**
15+
* @psalm-var non-empty-string
16+
*/
1417
private string $from;
18+
19+
/**
20+
* @psalm-var non-empty-string
21+
*/
1522
private string $to;
1623

1724
/**
@@ -20,6 +27,8 @@ final class Diff
2027
private array $chunks;
2128

2229
/**
30+
* @psalm-param non-empty-string $from
31+
* @psalm-param non-empty-string $to
2332
* @psalm-param list<Chunk> $chunks
2433
*/
2534
public function __construct(string $from, string $to, array $chunks = [])
@@ -29,11 +38,17 @@ public function __construct(string $from, string $to, array $chunks = [])
2938
$this->chunks = $chunks;
3039
}
3140

41+
/**
42+
* @psalm-return non-empty-string
43+
*/
3244
public function from(): string
3345
{
3446
return $this->from;
3547
}
3648

49+
/**
50+
* @psalm-return non-empty-string
51+
*/
3752
public function to(): string
3853
{
3954
return $this->to;
@@ -56,6 +71,8 @@ public function setChunks(array $chunks): void
5671
}
5772

5873
/**
74+
* @psalm-return non-empty-string
75+
*
5976
* @deprecated
6077
*/
6178
public function getFrom(): string
@@ -64,6 +81,8 @@ public function getFrom(): string
6481
}
6582

6683
/**
84+
* @psalm-return non-empty-string
85+
*
6786
* @deprecated
6887
*/
6988
public function getTo(): string

src/Parser.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace SebastianBergmann\Diff;
1111

1212
use function array_pop;
13+
use function assert;
1314
use function count;
1415
use function max;
1516
use function preg_match;
@@ -46,6 +47,9 @@ public function parse(string $string): array
4647
$collected = [];
4748
}
4849

50+
assert(!empty($fromMatch['file']));
51+
assert(!empty($toMatch['file']));
52+
4953
$diff = new Diff($fromMatch['file'], $toMatch['file']);
5054

5155
$i++;

0 commit comments

Comments
 (0)