mirror of
https://github.com/antonkomarev/github-profile-views-counter.git
synced 2026-08-04 19:15:11 -04:00
Refactor CounterImageRendererService
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user