Skip to content

Commit a3e0e5a

Browse files
committed
Codify pattern updates, name replacements
1 parent 1bbfa9b commit a3e0e5a

2 files changed

Lines changed: 25 additions & 10 deletions

File tree

src/CommitFormatter.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ class CommitFormatter {
66
private array $commitsList = [];
77

88
private array $commitsGroupedByAuthor = [];
9+
10+
private array $nameReplacements = [];
911
private const EOL = "\r\n";
1012

11-
public function __construct(array $inputCommits) {
13+
public function __construct(array $inputCommits, array $nameReplacements = []) {
1214
$this->process($inputCommits);
15+
$this->nameReplacements = $nameReplacements;
1316
}
1417

1518
private function process(array $inputCommits): void {
@@ -35,7 +38,15 @@ private function process(array $inputCommits): void {
3538
}
3639

3740
$this->commitsList = $formattedCommits;
38-
ksort($this->commitsGroupedByAuthor);
41+
42+
foreach ($this->nameReplacements as $originalName => $newName) {
43+
if (isset($this->commitsGroupedByAuthor[$originalName])) {
44+
$this->commitsGroupedByAuthor[$newName] = $this->commitsGroupedByAuthor[$originalName];
45+
unset($this->commitsGroupedByAuthor[$originalName]);
46+
}
47+
}
48+
49+
ksort($this->commitsGroupedByAuthor, SORT_NATURAL | SORT_FLAG_CASE);
3950
}
4051

4152
private function splitCommit(\stdClass $commit): array {
@@ -88,7 +99,7 @@ public function getFormattedCommitList(): array {
8899
public function getFormattedCommitListMarkup(): string {
89100
$output = '';
90101
foreach ($this->getFormattedCommitList() as $commit) {
91-
$output .= $this->getFormattedCommitListMarkup($commit['formatted'] . ' by ' . $commit['author']);
102+
$output .= self::markdownListItem($commit['formatted'] . ' by ' . ($this->nameReplacements[$commit['author']] ?? $commit['author']));
92103
}
93104

94105
return $output;
@@ -114,6 +125,8 @@ public function getFormattedCommitListGroupedByAuthorMarkup(): string {
114125
foreach ($commitList as $commit) {
115126
$output .= self::markdownListItem($commit['formatted']);
116127
}
128+
129+
$output .= self::EOL . self::EOL;
117130
}
118131

119132
return $output;

src/KeywordEnhancer.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
class KeywordEnhancer {
66
protected const CODIFY_PATTERNS = [
77
'/\b(?<!`)(?:zend|php)_[a-z_]+\(\)(?!`)/i', // zend_foo_bar()
8-
'/\b(?<!`)(?:zend|php)_[a-z_*]+\b(?![`.(])\*?/i', // zend_foo_bar()
8+
'/\b(?<!`)(?:zend|php|_php)_[a-z_*]+\b(?![`.(=])\*?/i', // zend_foo_bar
99
'/\b(?<![`\/])[a-z][a-z\d_-]+(.stubs?)?\.(phpt?|c|h)(?![`.?])/', // run-tests.php / foo.stub.php foo.stubs.php / test-foo-bar.phpt,
1010
'/\b(?<!`)ext\/[a-z_]+\b(?![`\/])/', // ext-names
11-
'/\b(?<!`)[A-Z][A-Za-z]+::[a-z][A-Za-z_]+\(\)(?![`\/])/', // Class::methods()
12-
'/\b(?<!`)[A-Z][A-Za-z]+::[A-Z_]+\b(?![`\/])/', // Class::CONSTANTS
13-
'/\b(?<!`)[A-Z][A-Za-z]+::[a-z][A-Za-z_\d]+\b(?![`\/])/', // Class::constants
14-
'/\b(?<!`)[a-z]+_[a-z]+(?:_[a-z_]+)?\(\)(?![`\/])/', // Functions with underscores and ()
15-
'/\b(?<!`)(?:ldap|ftp|array|mb|stream|open|hash)_[a-z_]+\d?\b(?![`\/])/', // Functions with underscores and no ()
16-
'/\b(?<!`)xleak\b(?![`\/])/i', // xleak
11+
'/\b(?<!`)[A-Z][A-Za-z]+::[a-z][A-Za-z\d_]+\(\)(?![`\/-])/', // Class::methods()
12+
'/\b(?<!`)[A-Z][A-Za-z]+::[A-Z_]+\b(?![`\/(])/', // Class::CONSTANTS
13+
'/\b(?<!`)[A-Z][A-Za-z]+::[a-z][A-Za-z_\d]+\b(?![`\/(])/', // Class::constants
14+
'/\b(?<!`-)[a-z]+_[a-z]+(?:_[a-z_]+)?\(\)(?![`\/])/', // Functions with underscores and ()
15+
'/\b(?<![`>])[a-z_][a-z][a-z\d_]+\(\)(?![`.>\/-])/', // Functions with underscores and ()
16+
'/\b(?<!`)(?:ldap|ftp|array|mb|stream|open|hash|xml)_[a-z_]+\d?\b(?![`\/])/', // Functions with underscores and no ()
17+
'/\b(?<!`)(xleak|xfail|skipif)\b(?![`\/])/i', // xleak
18+
'/(?<![`>()-])--[a-z][a-z-]+(?![`])/i', // --flags, --flags-and-more
1719
];
1820

1921
public static function enhance(string $inputText): string {

0 commit comments

Comments
 (0)