Refactor CounterImageRendererService

This commit is contained in:
antonkomarev
2020-07-12 12:28:18 +03:00
parent 793a8ff0b4
commit b33e9d4fcf
3 changed files with 22 additions and 23 deletions

View File

@@ -13,27 +13,23 @@ declare(strict_types=1);
namespace Komarev\GitHubProfileViewsCounter;
use InvalidArgumentException;
final class CounterImageRendererService
{
private string $sourceImagePath;
private CounterFileRepository $counterRepository;
public function __construct(
string $resourcesPath,
string $sourceImageFileName,
CounterFileRepository $counterRepository
)
public function __construct(string $sourceImagePath)
{
$this->sourceImagePath = $resourcesPath . '/' . $sourceImageFileName;
$this->counterRepository = $counterRepository;
if (!file_exists($sourceImagePath)) {
throw new InvalidArgumentException('Counter source image not found');
}
$this->sourceImagePath = $sourceImagePath;
}
public function getImage(): string
public function getImageWithCount(int $count): string
{
$this->counterRepository->incrementCount();
$count = $this->counterRepository->getCount();
$counterImage = file_get_contents($this->sourceImagePath);
return $this->replaceImagePlaceholders($counterImage, $count);