mirror of
https://github.com/antonkomarev/github-profile-views-counter.git
synced 2026-07-22 05:32:28 -04:00
Code cleanup
This commit is contained in:
@@ -34,18 +34,30 @@ final class CounterImageRendererService
|
||||
$this->counterRepository->incrementCount();
|
||||
$count = $this->counterRepository->getCount();
|
||||
|
||||
$counterImage = file_get_contents($this->sourceImagePath);
|
||||
|
||||
return $this->replaceImagePlaceholders($counterImage, $count);
|
||||
}
|
||||
|
||||
private function replaceImagePlaceholders(string $counterImage, int $count): string
|
||||
{
|
||||
$countLength = $this->countIntegerLength($count);
|
||||
|
||||
$minImageWidth = 98;
|
||||
$minCounterBackgroundWidth = 17;
|
||||
$minCounterTextLength = 70;
|
||||
$minCounterTextMarginLeft = 885;
|
||||
|
||||
$countLength = $this->countIntegerLength($count);
|
||||
$counterImage = file_get_contents($this->sourceImagePath);
|
||||
$imageWidth = $minImageWidth + (8 * $countLength);
|
||||
$counterBackgroundWidth = $minCounterBackgroundWidth + (8 * $countLength);
|
||||
$counterTextLength = $minCounterTextLength + (80 * $countLength);
|
||||
$counterTextMarginLeft = $minCounterTextMarginLeft + (40 * $countLength);
|
||||
|
||||
$counterImage = str_replace('%COUNT%', $count, $counterImage);
|
||||
$counterImage = str_replace('%IMAGE_WIDTH%', $minImageWidth + (8 * $countLength), $counterImage);
|
||||
$counterImage = str_replace('%COUNTER_BACKGROUND_WIDTH%', $minCounterBackgroundWidth + (8 * $countLength), $counterImage);
|
||||
$counterImage = str_replace('%COUNTER_TEXT_LENGTH%', $minCounterTextLength + (80 * $countLength), $counterImage);
|
||||
$counterImage = str_replace('%COUNTER_TEXT_MARGIN_LEFT%', $minCounterTextMarginLeft + (40 * $countLength), $counterImage);
|
||||
$counterImage = str_replace('%IMAGE_WIDTH%', $imageWidth, $counterImage);
|
||||
$counterImage = str_replace('%COUNTER_BACKGROUND_WIDTH%', $counterBackgroundWidth, $counterImage);
|
||||
$counterImage = str_replace('%COUNTER_TEXT_LENGTH%', $counterTextLength, $counterImage);
|
||||
$counterImage = str_replace('%COUNTER_TEXT_MARGIN_LEFT%', $counterTextMarginLeft, $counterImage);
|
||||
|
||||
return $counterImage;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user