Code cleanup

This commit is contained in:
antonkomarev
2020-07-11 23:45:03 +03:00
parent 422c88b370
commit 8a5e36dddc

View File

@@ -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;
}