Add PDO repository (#2)

* Add PDO repository

* Make file storage path configurable

* Name username query property required

* Add special exception class
This commit is contained in:
Anton Komarev
2020-07-12 18:46:42 +03:00
committed by GitHub
parent 042b26ea71
commit e4f24b04f7
13 changed files with 604 additions and 42 deletions

View File

@@ -14,7 +14,7 @@ declare(strict_types=1);
namespace Komarev\GitHubProfileViewsCounter;
use Contracts\Komarev\GitHubProfileViewsCounter\CounterRepositoryInterface;
use InvalidArgumentException;
use Contracts\Komarev\GitHubProfileViewsCounter\InvalidPathException;
final class CounterFileRepository implements CounterRepositoryInterface
{
@@ -23,11 +23,11 @@ final class CounterFileRepository implements CounterRepositoryInterface
public function __construct(string $storagePath)
{
if (!is_dir($storagePath)) {
throw new InvalidArgumentException('Counter storage is not a directory');
throw new InvalidPathException('Counter storage is not a directory');
}
if (!is_writable($storagePath)) {
throw new InvalidArgumentException('Counter storage is not writable');
throw new InvalidPathException('Counter storage is not writable');
}
$this->storagePath = $storagePath;
@@ -49,12 +49,6 @@ final class CounterFileRepository implements CounterRepositoryInterface
private function getCounterFilePath(string $username): string
{
if ($username === '') {
$counterFileName = 'views-count';
} else {
$counterFileName = $username . '-views-count';
}
return $this->storagePath . '/' . $counterFileName;
return $this->storagePath . '/' . $username . '-views-count';
}
}