1 | <?php |
||
37 | class Commit implements TreeishInterface, \Countable |
||
38 | { |
||
39 | /** |
||
40 | * @var \GitElephant\Repository |
||
41 | */ |
||
42 | private $repository; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | private $ref; |
||
48 | |||
49 | /** |
||
50 | * sha |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | private $sha; |
||
55 | |||
56 | /** |
||
57 | * tree |
||
58 | * |
||
59 | * @var string |
||
60 | */ |
||
61 | private $tree; |
||
62 | |||
63 | /** |
||
64 | * the commit parents |
||
65 | * |
||
66 | * @var array |
||
67 | */ |
||
68 | private $parents = []; |
||
69 | |||
70 | /** |
||
71 | * the Author instance for author |
||
72 | * |
||
73 | * @var Author |
||
74 | */ |
||
75 | private $author; |
||
76 | |||
77 | /** |
||
78 | * the Author instance for committer |
||
79 | * |
||
80 | * @var Author |
||
81 | */ |
||
82 | private $committer; |
||
83 | |||
84 | /** |
||
85 | * the Message instance |
||
86 | * |
||
87 | * @var Commit\Message |
||
88 | */ |
||
89 | private $message; |
||
90 | |||
91 | /** |
||
92 | * the date for author |
||
93 | * |
||
94 | * @var \DateTime |
||
95 | */ |
||
96 | private $datetimeAuthor; |
||
97 | |||
98 | /** |
||
99 | * the date for committer |
||
100 | * |
||
101 | * @var \Datetime |
||
102 | */ |
||
103 | private $datetimeCommitter; |
||
104 | |||
105 | /** |
||
106 | * Class constructor |
||
107 | * |
||
108 | * @param \GitElephant\Repository $repository the repository |
||
109 | * @param TreeishInterface|string $treeish a treeish reference |
||
110 | */ |
||
111 | 37 | private function __construct(Repository $repository, $treeish = 'HEAD') |
|
117 | |||
118 | /** |
||
119 | * factory method to create a commit |
||
120 | * |
||
121 | * @param Repository $repository repository instance |
||
122 | * @param string $message commit message |
||
123 | * @param bool $stageAll automatically stage the dirty working tree. Alternatively call stage() on the repo |
||
124 | * @param string|Author $author override the author for this commit |
||
125 | * |
||
126 | * @throws \RuntimeException |
||
127 | * @throws \Symfony\Component\Process\Exception\LogicException |
||
128 | * @throws \InvalidArgumentException |
||
129 | * @throws \Symfony\Component\Process\Exception\InvalidArgumentException |
||
130 | * @throws \Symfony\Component\Process\Exception\RuntimeException |
||
131 | * @return Commit |
||
132 | */ |
||
133 | 5 | public static function create( |
|
143 | |||
144 | /** |
||
145 | * pick an existing commit |
||
146 | * |
||
147 | * @param Repository $repository repository |
||
148 | * @param TreeishInterface|string $treeish treeish |
||
149 | * |
||
150 | * @throws \RuntimeException |
||
151 | * @throws \Symfony\Component\Process\Exception\RuntimeException |
||
152 | * @return Commit |
||
153 | */ |
||
154 | 18 | public static function pick(Repository $repository, $treeish = null): Commit |
|
161 | |||
162 | /** |
||
163 | * static generator to generate a single commit from output of command.show service |
||
164 | * |
||
165 | * @param \GitElephant\Repository $repository repository |
||
166 | * @param array $outputLines output lines |
||
167 | * |
||
168 | * @return Commit |
||
169 | */ |
||
170 | 20 | public static function createFromOutputLines(Repository $repository, array $outputLines): Commit |
|
177 | |||
178 | /** |
||
179 | * get the commit properties from command |
||
180 | * |
||
181 | * @see ShowCommand::commitInfo |
||
182 | */ |
||
183 | 18 | public function createFromCommand(): void |
|
189 | |||
190 | /** |
||
191 | * get the branches this commit is contained in |
||
192 | * |
||
193 | * @see BranchCommand::contains |
||
194 | */ |
||
195 | public function getContainedIn(): array |
||
201 | |||
202 | /** |
||
203 | * number of commits that lead to this one |
||
204 | * |
||
205 | * @throws \RuntimeException |
||
206 | * @throws \Symfony\Component\Process\Exception\LogicException |
||
207 | * @throws \Symfony\Component\Process\Exception\InvalidArgumentException |
||
208 | * @throws \Symfony\Component\Process\Exception\RuntimeException |
||
209 | * @return int |
||
210 | */ |
||
211 | 3 | public function count(): int |
|
217 | |||
218 | 1 | public function getDiff(): \GitElephant\Objects\Diff\Diff |
|
222 | |||
223 | /** |
||
224 | * parse the output of a git command showing a commit |
||
225 | * |
||
226 | * @param Iterable $outputLines output lines |
||
227 | */ |
||
228 | 37 | private function parseOutputLines($outputLines): void |
|
272 | |||
273 | /** |
||
274 | * Returns true if the commit is a root commit. Usually the first of the repository |
||
275 | * |
||
276 | * @return bool |
||
277 | */ |
||
278 | 3 | public function isRoot(): bool |
|
279 | { |
||
280 | 3 | return empty($this->parents); |
|
281 | } |
||
282 | |||
283 | /** |
||
284 | * toString magic method |
||
285 | * |
||
286 | * @return string the sha |
||
287 | */ |
||
288 | 8 | public function __toString(): string |
|
292 | |||
293 | /** |
||
294 | * @return CallerInterface |
||
295 | */ |
||
296 | 18 | private function getCaller(): CallerInterface |
|
300 | |||
301 | /** |
||
302 | * Repository setter |
||
303 | * |
||
304 | * @param \GitElephant\Repository $repository repository variable |
||
305 | */ |
||
306 | public function setRepository(Repository $repository): void |
||
310 | |||
311 | /** |
||
312 | * Repository getter |
||
313 | * |
||
314 | * @return \GitElephant\Repository |
||
315 | */ |
||
316 | 18 | public function getRepository(): \GitElephant\Repository |
|
320 | |||
321 | /** |
||
322 | * author getter |
||
323 | * |
||
324 | * @return Author |
||
325 | */ |
||
326 | 4 | public function getAuthor(): ?Author |
|
330 | |||
331 | /** |
||
332 | * committer getter |
||
333 | * |
||
334 | * @return Author |
||
335 | */ |
||
336 | 4 | public function getCommitter(): ?Author |
|
340 | |||
341 | /** |
||
342 | * message getter |
||
343 | * |
||
344 | * @return Message |
||
345 | */ |
||
346 | 11 | public function getMessage(): ?Message |
|
350 | |||
351 | /** |
||
352 | * parent getter |
||
353 | * |
||
354 | * @return array |
||
355 | */ |
||
356 | 2 | public function getParents(): array |
|
360 | |||
361 | /** |
||
362 | * sha getter |
||
363 | * |
||
364 | * @param bool $short short version |
||
365 | * |
||
366 | * @return string |
||
367 | */ |
||
368 | 23 | public function getSha(bool $short = false): ?string |
|
372 | |||
373 | /** |
||
374 | * tree getter |
||
375 | * |
||
376 | * @return string |
||
377 | */ |
||
378 | 3 | public function getTree(): ?string |
|
382 | |||
383 | /** |
||
384 | * datetimeAuthor getter |
||
385 | * |
||
386 | * @return \DateTime |
||
387 | */ |
||
388 | 4 | public function getDatetimeAuthor(): ?\DateTime |
|
392 | |||
393 | /** |
||
394 | * datetimeCommitter getter |
||
395 | * |
||
396 | * @return \DateTime |
||
397 | */ |
||
398 | 4 | public function getDatetimeCommitter(): ?\DateTime |
|
402 | |||
403 | /** |
||
404 | * rev-parse command - often used to return a commit tag. |
||
405 | * |
||
406 | * @param array $options the options to apply to rev-parse |
||
407 | * |
||
408 | * @throws \RuntimeException |
||
409 | * @throws \InvalidArgumentException |
||
410 | * @throws \Symfony\Component\Process\Exception\RuntimeException |
||
411 | * @return array |
||
412 | */ |
||
413 | 1 | public function revParse(array $options = []): array |
|
421 | |||
422 | /** |
||
423 | * Is the commit tagged? |
||
424 | * |
||
425 | * return true if some tag of repository point to this commit |
||
426 | * return false otherwise |
||
427 | * |
||
428 | * @return bool |
||
429 | */ |
||
430 | 2 | public function tagged(): bool |
|
444 | |||
445 | /** |
||
446 | * Return Tags that point to this commit |
||
447 | * |
||
448 | * @return Tag[] |
||
449 | */ |
||
450 | 1 | public function getTags(): array |
|
463 | } |
||
464 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.