Skip to content

Commit e7a9ddd

Browse files
Fix the bug for counter variable type on PR #183 (#184)
Co-authored-by: Graham Campbell <GrahamCampbell@users.noreply.github.com>
1 parent d1fe467 commit e7a9ddd

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

src/Gitonomy/Git/Diff/FileChange.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ class FileChange
2424
protected $rangeNewCount;
2525
protected $lines;
2626

27+
/**
28+
* @param int $rangeOldStart
29+
* @param int $rangeOldCount
30+
* @param int $rangeNewStart
31+
* @param int $rangeNewCount
32+
* @param array $lines
33+
*
34+
* @return void
35+
*/
2736
public function __construct($rangeOldStart, $rangeOldCount, $rangeNewStart, $rangeNewCount, $lines)
2837
{
2938
$this->rangeOldStart = $rangeOldStart;
@@ -33,6 +42,9 @@ public function __construct($rangeOldStart, $rangeOldCount, $rangeNewStart, $ran
3342
$this->lines = $lines;
3443
}
3544

45+
/**
46+
* @return int
47+
*/
3648
public function getCount($type)
3749
{
3850
$result = 0;
@@ -45,31 +57,49 @@ public function getCount($type)
4557
return $result;
4658
}
4759

60+
/**
61+
* @return int
62+
*/
4863
public function getRangeOldStart()
4964
{
5065
return $this->rangeOldStart;
5166
}
5267

68+
/**
69+
* @return int
70+
*/
5371
public function getRangeOldCount()
5472
{
5573
return $this->rangeOldCount;
5674
}
5775

76+
/**
77+
* @return int
78+
*/
5879
public function getRangeNewStart()
5980
{
6081
return $this->rangeNewStart;
6182
}
6283

84+
/**
85+
* @return int
86+
*/
6387
public function getRangeNewCount()
6488
{
6589
return $this->rangeNewCount;
6690
}
6791

92+
/**
93+
* @return array
94+
*/
6895
public function getLines()
6996
{
7097
return $this->lines;
7198
}
7299

100+
/**
101+
* @return array
102+
*/
73103
public function toArray()
74104
{
75105
return [
@@ -81,6 +111,11 @@ public function toArray()
81111
];
82112
}
83113

114+
/**
115+
* @param array $array
116+
*
117+
* @return self
118+
*/
84119
public static function fromArray(array $array)
85120
{
86121
return new self($array['range_old_start'], $array['range_old_count'], $array['range_new_start'], $array['range_new_count'], $array['lines']);

src/Gitonomy/Git/Parser/DiffParser.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ protected function doParse()
9797
// 5. Diff
9898
while ($this->expects('@@ ')) {
9999
$vars = $this->consumeRegexp('/-(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))?/');
100-
$rangeOldStart = $vars[1];
101-
$rangeOldCount = $vars[2];
102-
$rangeNewStart = $vars[3];
103-
$rangeNewCount = isset($vars[4]) ? $vars[4] : $vars[2]; // @todo Ici, t'as pris un gros raccourci mon loulou
100+
$rangeOldStart = (int) $vars[1];
101+
$rangeOldCount = (int) $vars[2];
102+
$rangeNewStart = (int) $vars[3];
103+
$rangeNewCount = isset($vars[4]) ? (int) $vars[4] : (int) $vars[2]; // @todo Ici, t'as pris un gros raccourci mon loulou
104104
$this->consume(' @@');
105105
$this->consumeTo("\n");
106106
$this->consumeNewLine();

tests/Gitonomy/Git/Tests/DiffTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ public function testDiffRangeParse($repository)
134134

135135
$changes = $files[0]->getChanges();
136136

137-
$this->assertEquals(0, $changes[0]->getRangeOldStart());
138-
$this->assertEquals(0, $changes[0]->getRangeOldCount());
137+
$this->assertSame(0, $changes[0]->getRangeOldStart());
138+
$this->assertSame(0, $changes[0]->getRangeOldCount());
139139

140-
$this->assertEquals(1, $changes[0]->getRangeNewStart());
141-
$this->assertEquals(0, $changes[0]->getRangeNewCount());
140+
$this->assertSame(1, $changes[0]->getRangeNewStart());
141+
$this->assertSame(0, $changes[0]->getRangeNewCount());
142142
}
143143
}

0 commit comments

Comments
 (0)