Skip to content

Commit 159d244

Browse files
committed
nits
Signed-off-by: Jack Cherng <[email protected]>
1 parent 76675e4 commit 159d244

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/Factory/RendererFactory.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,10 @@ public static function resolveTemplate(string $template): ?string
7272
{
7373
static $cache = [];
7474

75-
// the result could be null so do not use isset() here
76-
if (\array_key_exists($template, $cache)) {
75+
if (isset($cache[$template])) {
7776
return $cache[$template];
7877
}
7978

80-
$result = null;
81-
8279
foreach (RendererConstant::TEMPLATE_TYPES as $type) {
8380
$className = RendererConstant::RENDERER_NAMESPACE . "\\{$type}\\{$template}";
8481

@@ -89,6 +86,6 @@ public static function resolveTemplate(string $template): ?string
8986
}
9087
}
9188

92-
return $cache[$template] = $result;
89+
return isset($result) ? ($cache[$template] = $result) : null;
9390
}
9491
}

src/Renderer/Html/LineRenderer/Line.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class Line extends AbstractLineRenderer
1414
*/
1515
public function render(MbString $mbFrom, MbString $mbTo): LineRendererInterface
1616
{
17-
[$start, $end] = $this->getChangedExtentBeginEnd($mbFrom, $mbTo);
17+
[$start, $end] = $this->getChangedExtentRegion($mbFrom, $mbTo);
1818

1919
// two strings are the same
2020
if ($end === 0) {
@@ -46,7 +46,7 @@ public function render(MbString $mbFrom, MbString $mbTo): LineRendererInterface
4646
* @return array Array containing the starting position (non-negative) and the ending position (negative)
4747
* [0, 0] if two strings are the same
4848
*/
49-
protected function getChangedExtentBeginEnd(MbString $mbFrom, MbString $mbTo): array
49+
protected function getChangedExtentRegion(MbString $mbFrom, MbString $mbTo): array
5050
{
5151
// two strings are the same
5252
// most lines should be this cases, an early return could save many function calls
@@ -56,19 +56,19 @@ protected function getChangedExtentBeginEnd(MbString $mbFrom, MbString $mbTo): a
5656

5757
// calculate $start
5858
$start = 0;
59-
$startLimit = \min($mbFrom->strlen(), $mbTo->strlen());
59+
$startMax = \min($mbFrom->strlen(), $mbTo->strlen());
6060
while (
61-
$start < $startLimit && // index out of range
61+
$start < $startMax && // index out of range
6262
$mbFrom->getAtRaw($start) === $mbTo->getAtRaw($start)
6363
) {
6464
++$start;
6565
}
6666

6767
// calculate $end
6868
$end = -1; // trick
69-
$endLimit = $startLimit - $start;
69+
$endMin = $startMax - $start;
7070
while (
71-
-$end <= $endLimit && // index out of range
71+
-$end <= $endMin && // index out of range
7272
$mbFrom->getAtRaw($end) === $mbTo->getAtRaw($end)
7373
) {
7474
--$end;

0 commit comments

Comments
 (0)