1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Changelog keeper |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/chkipper |
6
|
|
|
* @package chkipper |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hiqdev\chkipper\modifiers; |
12
|
|
|
|
13
|
|
|
use hiqdev\chkipper\history\History; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Modifier that prepares better links to users (committers) when possible. |
17
|
|
|
* |
18
|
|
|
* Git provides emails of commiters. |
19
|
|
|
* If you provide link to committer's personal page this modifier will spread |
20
|
|
|
* it all over the history. |
21
|
|
|
* |
22
|
|
|
* E.g. git provides my email as [email protected] for all my commits. |
23
|
|
|
* So my commits will look like this in history: |
24
|
|
|
* ``` |
25
|
|
|
* - [0000000] 2017-01-01 commit comment [[email protected]] |
26
|
|
|
* ``` |
27
|
|
|
* I want my commits to link to my github page: https://github.com/hiqsol |
28
|
|
|
* So I add these lines in the links part of the history (at the end of file): |
29
|
|
|
* ``` |
30
|
|
|
* [@hiqsol]: https://github.com/hiqsol |
31
|
|
|
* [[email protected]]: https://github.com/hiqsol |
32
|
|
|
* ``` |
33
|
|
|
* This modifier will change my commits to look like this: |
34
|
|
|
* ``` |
35
|
|
|
* - [0000000] 2017-01-01 commit comment [@hiqsol] |
36
|
|
|
* ``` |
37
|
|
|
* |
38
|
|
|
* @author Andrii Vasyliev <[email protected]> |
39
|
|
|
*/ |
40
|
|
|
class PrettifyUserLinks extends AbstractModifier |
41
|
|
|
{ |
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
2 |
|
public function run(History $history) |
46
|
|
|
{ |
47
|
2 |
|
$users = []; |
48
|
2 |
|
$subs = []; |
49
|
2 |
|
foreach ($history->getLinks() as $link => $href) { |
50
|
2 |
|
if ($link[0] === '@') { |
51
|
1 |
|
$users[$href] = $link; |
52
|
2 |
|
} elseif (isset($users[$href])) { |
53
|
|
|
$subs[$link] = $users[$href]; |
54
|
|
|
} |
55
|
2 |
|
} |
56
|
2 |
|
if (!$subs) { |
|
|
|
|
57
|
2 |
|
return; |
58
|
|
|
} |
59
|
|
|
foreach ($history->getTags() as $tag) { |
60
|
|
|
foreach ($tag->getNotes() as $note) { |
61
|
|
|
foreach ($note->getCommits() as $commit) { |
62
|
|
|
$author = $commit->getAuthor(); |
63
|
|
|
if (isset($subs[$author])) { |
64
|
|
|
$commit->setAuthor($subs[$author]); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.