1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Churn\Process; |
6
|
|
|
|
7
|
|
|
use Churn\File\File; |
8
|
|
|
use Churn\Process\ChangesCount\FossilChangesCountProcess; |
9
|
|
|
use Churn\Process\ChangesCount\GitChangesCountProcess; |
10
|
|
|
use Churn\Process\ChangesCount\MercurialChangesCountProcess; |
11
|
|
|
use Churn\Process\ChangesCount\NoVcsChangesCountProcess; |
12
|
|
|
use Closure; |
13
|
|
|
use InvalidArgumentException; |
14
|
|
|
|
15
|
|
|
class ChangesCountProcessBuilder |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @param string $vcs Name of the version control system. |
20
|
|
|
* @param string $commitsSince String containing the date of when to look at commits since. |
21
|
|
|
* @throws InvalidArgumentException If VCS is not supported. |
22
|
|
|
*/ |
23
|
|
|
public function getBuilder(string $vcs, string $commitsSince): Closure |
24
|
|
|
{ |
25
|
|
|
if ('git' === $vcs) { |
26
|
|
|
return $this->getGitChangesCountProcessBuilder($commitsSince); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
if ('mercurial' === $vcs) { |
30
|
|
|
return $this->getMercurialChangesCountProcessBuilder($commitsSince); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
if ('fossil' === $vcs) { |
34
|
|
|
return $this->getFossilChangesCountProcessBuilder($commitsSince); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
if ('none' === $vcs) { |
38
|
|
|
return static function (File $file): ChangesCountInterface { |
39
|
|
|
return new NoVcsChangesCountProcess($file); |
40
|
|
|
}; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
throw new InvalidArgumentException('Unsupported VCS: ' . $vcs); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param string $commitsSince String containing the date of when to look at commits since. |
48
|
|
|
*/ |
49
|
|
|
private function getGitChangesCountProcessBuilder(string $commitsSince): Closure |
50
|
|
|
{ |
51
|
|
|
return static function (File $file) use ($commitsSince): ChangesCountInterface { |
52
|
|
|
return new GitChangesCountProcess($file, $commitsSince); |
53
|
|
|
}; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string $commitsSince String containing the date of when to look at commits since. |
58
|
|
|
*/ |
59
|
|
|
private function getMercurialChangesCountProcessBuilder(string $commitsSince): Closure |
60
|
|
|
{ |
61
|
|
|
$date = \date('Y-m-d', \strtotime($commitsSince)); |
62
|
|
|
|
63
|
|
|
return static function (File $file) use ($date): ChangesCountInterface { |
64
|
|
|
return new MercurialChangesCountProcess($file, $date); |
65
|
|
|
}; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $commitsSince String containing the date of when to look at commits since. |
70
|
|
|
*/ |
71
|
|
|
private function getFossilChangesCountProcessBuilder(string $commitsSince): Closure |
72
|
|
|
{ |
73
|
|
|
$date = \date('Y-m-d', \strtotime($commitsSince)); |
74
|
|
|
|
75
|
|
|
return static function (File $file) use ($date): ChangesCountInterface { |
76
|
|
|
return new FossilChangesCountProcess($file, $date); |
77
|
|
|
}; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|