Add asserts to CounterFileRepository

This commit is contained in:
antonkomarev
2020-07-12 12:51:17 +03:00
parent bf7b636702
commit be53d216c4

View File

@@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Komarev\GitHubProfileViewsCounter;
use Contracts\Komarev\GitHubProfileViewsCounter\CounterRepositoryInterface;
use InvalidArgumentException;
final class CounterFileRepository implements CounterRepositoryInterface
{
@@ -21,6 +22,14 @@ final class CounterFileRepository implements CounterRepositoryInterface
public function __construct(string $storagePath)
{
if (!is_dir($storagePath)) {
throw new InvalidArgumentException('Counter storage is not a directory');
}
if (!is_writable($storagePath)) {
throw new InvalidArgumentException('Counter storage is not writable');
}
$this->storagePath = $storagePath;
}