forked from bmitch/churn-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFossilChangesCountProcess.php
More file actions
52 lines (43 loc) · 1.23 KB
/
FossilChangesCountProcess.php
File metadata and controls
52 lines (43 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
declare(strict_types=1);
namespace Churn\Process\ChangesCount;
use Churn\File\File;
use Churn\Process\ChangesCountInterface;
use Churn\Process\ChurnProcess;
use Symfony\Component\Process\Process;
/**
* @internal
*/
final class FossilChangesCountProcess extends ChurnProcess implements ChangesCountInterface
{
/**
* Class constructor.
*
* @param File $file The file the process is being executed on.
* @param string $dateSince String containing the date of when to look at commits since (Y-m-d).
*/
public function __construct(File $file, string $dateSince)
{
$process = new Process([
'fossil', 'timeline', '-t', 'ci',
'-W', '0', 'after', $dateSince,
'-p', $file->getFullPath(),
], \dirname($file->getFullPath()));
parent::__construct($file, $process);
}
/**
* Returns the number of changes for a file.
*/
#[\Override]
public function countChanges(): int
{
$count = 0;
foreach (\explode("\n", $this->getOutput()) as $row) {
if (!isset($row[0]) || '=' === $row[0] || '+' === $row[0]) {
continue;
}
$count++;
}
return $count;
}
}