1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Gitilicious\GitClient\Git; |
4
|
|
|
|
5
|
|
|
use Gitilicious\GitClient\Cli\Input\LongFlag; |
6
|
|
|
use Gitilicious\GitClient\Cli\Input\PlainArgument; |
7
|
|
|
use Gitilicious\GitClient\Cli\Input\ShortFlag; |
8
|
|
|
use Gitilicious\GitClient\Client; |
9
|
|
|
use Gitilicious\GitClient\FileSystem\Directory; |
10
|
|
|
use Gitilicious\GitClient\FileSystem\File; |
11
|
|
|
|
12
|
|
|
class Repository |
13
|
|
|
{ |
14
|
|
|
private $client; |
15
|
|
|
|
16
|
|
|
private $directory; |
17
|
|
|
|
18
|
|
|
public function __construct(Client $client, Directory $directory) |
19
|
|
|
{ |
20
|
10 |
|
$this->client = $client; |
21
|
|
|
$this->directory = $directory; |
22
|
10 |
|
} |
23
|
10 |
|
|
24
|
10 |
|
public static function createBare(Client $client, Directory $directory): Repository |
25
|
10 |
|
{ |
26
|
|
|
$client->run($directory, new PlainArgument('init'), new LongFlag('bare')); |
27
|
4 |
|
|
28
|
|
|
return new self($client, $directory); |
29
|
4 |
|
} |
30
|
|
|
|
31
|
4 |
|
public static function create(Client $client, Directory $directory): Repository |
32
|
|
|
{ |
33
|
4 |
|
$client->run($directory, new PlainArgument('init')); |
34
|
1 |
|
|
35
|
|
|
return new self($client, $directory); |
36
|
|
|
} |
37
|
3 |
|
|
38
|
|
|
public function clone(Directory $directory): Repository |
39
|
|
|
{ |
40
|
8 |
|
$this->client->run( |
41
|
|
|
$directory, |
42
|
8 |
|
new PlainArgument('clone'), |
43
|
|
|
new PlainArgument($this->directory->getPath()), |
44
|
8 |
|
new PlainArgument($directory->getPath()) |
45
|
|
|
); |
46
|
8 |
|
|
47
|
1 |
|
return new self($this->client, $directory); |
48
|
|
|
} |
49
|
|
|
|
50
|
7 |
|
public function getPath(): string |
51
|
|
|
{ |
52
|
|
|
return $this->directory->getPath(); |
53
|
3 |
|
} |
54
|
|
|
|
55
|
3 |
|
public function getActiveBranch(): Branch |
56
|
|
|
{ |
57
|
3 |
|
$branches = $this->getBranches(); |
58
|
|
|
|
59
|
3 |
|
if (!count($branches)) { |
60
|
3 |
|
return new Branch('* master'); |
61
|
3 |
|
} |
62
|
|
|
|
63
|
|
|
foreach ($branches as $branch) { |
64
|
3 |
|
if ($branch->isActive()) { |
65
|
1 |
|
return $branch; |
66
|
|
|
} |
67
|
|
|
} |
68
|
2 |
|
} |
69
|
|
|
|
70
|
|
|
public function getBranches(): Branches |
71
|
4 |
|
{ |
72
|
|
|
$result = $this->client->run($this->directory, new PlainArgument('branch')); |
73
|
4 |
|
|
74
|
|
|
$branches = new Branches($this->client); |
|
|
|
|
75
|
|
|
|
76
|
|
|
foreach ($result->getOutput() as $branch) { |
|
|
|
|
77
|
|
|
$branches->add(new Branch($branch)); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return $branches; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
View Code Duplication |
public function createBranch(string $name): Branch |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
$this->client->run( |
86
|
|
|
$this->directory, |
87
|
|
|
new PlainArgument('checkout'), |
88
|
|
|
new ShortFlag('b'), |
89
|
|
|
new PlainArgument($name) |
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
return new Branch($name); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
View Code Duplication |
public function checkout(string $name): Branch |
|
|
|
|
96
|
|
|
{ |
97
|
|
|
$this->client->run( |
98
|
|
|
$this->directory, |
99
|
|
|
new PlainArgument('checkout'), |
100
|
|
|
new PlainArgument($name) |
101
|
|
|
); |
102
|
|
|
|
103
|
|
|
return new Branch('* ' . $name); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function add(File $file) |
107
|
|
|
{ |
108
|
|
|
$this->client->run($this->directory, new PlainArgument('add'), new PlainArgument($file->getPath())); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function commit(Author $author, string $message) |
112
|
|
|
{ |
113
|
|
|
$this->client->run( |
114
|
|
|
$this->directory, |
115
|
|
|
new PlainArgument('commit'), |
116
|
|
|
new ShortFlag('m'), |
117
|
|
|
new PlainArgument($message), |
118
|
|
|
new LongFlag('author'), |
119
|
|
|
new PlainArgument($author->getFormatted()) |
120
|
|
|
); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function push() |
124
|
|
|
{ |
125
|
|
|
$this->client->run($this->directory, new PlainArgument('push')); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.