mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Migrated DeleteShortUrlsOptions to immutable object
This commit is contained in:
@@ -22,7 +22,7 @@ return [
|
|||||||
ErrorHandler\NotFoundTemplateHandler::class => InvokableFactory::class,
|
ErrorHandler\NotFoundTemplateHandler::class => InvokableFactory::class,
|
||||||
|
|
||||||
Options\AppOptions::class => [ValinorConfigFactory::class, 'config.app_options'],
|
Options\AppOptions::class => [ValinorConfigFactory::class, 'config.app_options'],
|
||||||
Options\DeleteShortUrlsOptions::class => ConfigAbstractFactory::class,
|
Options\DeleteShortUrlsOptions::class => [ValinorConfigFactory::class, 'config.delete_short_urls'],
|
||||||
Options\NotFoundRedirectOptions::class => ConfigAbstractFactory::class,
|
Options\NotFoundRedirectOptions::class => ConfigAbstractFactory::class,
|
||||||
Options\RedirectOptions::class => ConfigAbstractFactory::class,
|
Options\RedirectOptions::class => ConfigAbstractFactory::class,
|
||||||
Options\UrlShortenerOptions::class => ConfigAbstractFactory::class,
|
Options\UrlShortenerOptions::class => ConfigAbstractFactory::class,
|
||||||
@@ -86,7 +86,6 @@ return [
|
|||||||
Domain\DomainService::class,
|
Domain\DomainService::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
Options\DeleteShortUrlsOptions::class => ['config.delete_short_urls'],
|
|
||||||
Options\NotFoundRedirectOptions::class => ['config.not_found_redirects'],
|
Options\NotFoundRedirectOptions::class => ['config.not_found_redirects'],
|
||||||
Options\RedirectOptions::class => ['config.redirects'],
|
Options\RedirectOptions::class => ['config.redirects'],
|
||||||
Options\UrlShortenerOptions::class => ['config.url_shortener'],
|
Options\UrlShortenerOptions::class => ['config.url_shortener'],
|
||||||
|
|||||||
@@ -4,34 +4,13 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Shlinkio\Shlink\Core\Options;
|
namespace Shlinkio\Shlink\Core\Options;
|
||||||
|
|
||||||
use Laminas\Stdlib\AbstractOptions;
|
|
||||||
|
|
||||||
use const Shlinkio\Shlink\DEFAULT_DELETE_SHORT_URL_THRESHOLD;
|
use const Shlinkio\Shlink\DEFAULT_DELETE_SHORT_URL_THRESHOLD;
|
||||||
|
|
||||||
class DeleteShortUrlsOptions extends AbstractOptions
|
final class DeleteShortUrlsOptions
|
||||||
{
|
{
|
||||||
private int $visitsThreshold = DEFAULT_DELETE_SHORT_URL_THRESHOLD;
|
public function __construct(
|
||||||
private bool $checkVisitsThreshold = true;
|
public readonly int $visitsThreshold = DEFAULT_DELETE_SHORT_URL_THRESHOLD,
|
||||||
|
public readonly bool $checkVisitsThreshold = true,
|
||||||
public function getVisitsThreshold(): int
|
) {
|
||||||
{
|
|
||||||
return $this->visitsThreshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function setVisitsThreshold(int $visitsThreshold): self
|
|
||||||
{
|
|
||||||
$this->visitsThreshold = $visitsThreshold;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function doCheckVisitsThreshold(): bool
|
|
||||||
{
|
|
||||||
return $this->checkVisitsThreshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function setCheckVisitsThreshold(bool $checkVisitsThreshold): self
|
|
||||||
{
|
|
||||||
$this->checkVisitsThreshold = $checkVisitsThreshold;
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class DeleteShortUrlService implements DeleteShortUrlServiceInterface
|
|||||||
$shortUrl = $this->urlResolver->resolveShortUrl($identifier, $apiKey);
|
$shortUrl = $this->urlResolver->resolveShortUrl($identifier, $apiKey);
|
||||||
if (! $ignoreThreshold && $this->isThresholdReached($shortUrl)) {
|
if (! $ignoreThreshold && $this->isThresholdReached($shortUrl)) {
|
||||||
throw Exception\DeleteShortUrlException::fromVisitsThreshold(
|
throw Exception\DeleteShortUrlException::fromVisitsThreshold(
|
||||||
$this->deleteShortUrlsOptions->getVisitsThreshold(),
|
$this->deleteShortUrlsOptions->visitsThreshold,
|
||||||
$identifier,
|
$identifier,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -43,10 +43,10 @@ class DeleteShortUrlService implements DeleteShortUrlServiceInterface
|
|||||||
|
|
||||||
private function isThresholdReached(ShortUrl $shortUrl): bool
|
private function isThresholdReached(ShortUrl $shortUrl): bool
|
||||||
{
|
{
|
||||||
if (! $this->deleteShortUrlsOptions->doCheckVisitsThreshold()) {
|
if (! $this->deleteShortUrlsOptions->checkVisitsThreshold) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $shortUrl->getVisitsCount() >= $this->deleteShortUrlsOptions->getVisitsThreshold();
|
return $shortUrl->getVisitsCount() >= $this->deleteShortUrlsOptions->visitsThreshold;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,9 +102,9 @@ class DeleteShortUrlServiceTest extends TestCase
|
|||||||
|
|
||||||
private function createService(bool $checkVisitsThreshold = true, int $visitsThreshold = 5): DeleteShortUrlService
|
private function createService(bool $checkVisitsThreshold = true, int $visitsThreshold = 5): DeleteShortUrlService
|
||||||
{
|
{
|
||||||
return new DeleteShortUrlService($this->em->reveal(), new DeleteShortUrlsOptions([
|
return new DeleteShortUrlService($this->em->reveal(), new DeleteShortUrlsOptions(
|
||||||
'visitsThreshold' => $visitsThreshold,
|
$visitsThreshold,
|
||||||
'checkVisitsThreshold' => $checkVisitsThreshold,
|
$checkVisitsThreshold,
|
||||||
]), $this->urlResolver->reveal());
|
), $this->urlResolver->reveal());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user