Make classes readonly when possible

This commit is contained in:
Alejandro Celaya 2024-11-09 09:55:51 +01:00
parent d6b103de83
commit 72f1e243b5
16 changed files with 40 additions and 40 deletions

View File

@ -11,7 +11,7 @@ use Symfony\Component\Console\Output\OutputInterface;
use function sprintf;
readonly final class EndDateOption
final readonly class EndDateOption
{
private DateOption $dateOption;

View File

@ -18,7 +18,7 @@ use function array_unique;
use function Shlinkio\Shlink\Core\ArrayUtils\flatten;
use function Shlinkio\Shlink\Core\splitByComma;
readonly final class ShortUrlDataInput
final readonly class ShortUrlDataInput
{
public function __construct(Command $command, private bool $longUrlAsOption = false)
{

View File

@ -10,7 +10,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
readonly final class ShortUrlIdentifierInput
final readonly class ShortUrlIdentifierInput
{
public function __construct(Command $command, string $shortCodeDesc, string $domainDesc)
{

View File

@ -11,7 +11,7 @@ use Symfony\Component\Console\Output\OutputInterface;
use function sprintf;
readonly final class StartDateOption
final readonly class StartDateOption
{
private DateOption $dateOption;

View File

@ -6,9 +6,9 @@ namespace Shlinkio\Shlink\Core\Crawling;
use Shlinkio\Shlink\Core\ShortUrl\Repository\CrawlableShortCodesQueryInterface;
class CrawlingHelper implements CrawlingHelperInterface
readonly class CrawlingHelper implements CrawlingHelperInterface
{
public function __construct(private readonly CrawlableShortCodesQueryInterface $query)
public function __construct(private CrawlableShortCodesQueryInterface $query)
{
}

View File

@ -9,12 +9,12 @@ use Shlinkio\Shlink\Core\Config\NotFoundRedirectConfigInterface;
use Shlinkio\Shlink\Core\Config\NotFoundRedirects;
use Shlinkio\Shlink\Core\Domain\Entity\Domain;
final class DomainItem implements JsonSerializable
final readonly class DomainItem implements JsonSerializable
{
private function __construct(
private readonly string $authority,
public readonly NotFoundRedirectConfigInterface $notFoundRedirectConfig,
public readonly bool $isDefault,
private string $authority,
public NotFoundRedirectConfigInterface $notFoundRedirectConfig,
public bool $isDefault,
) {
}

View File

@ -11,9 +11,9 @@ use Shlinkio\Shlink\Core\Visit\Model\VisitType;
use function rtrim;
class NotFoundType
readonly class NotFoundType
{
private function __construct(private readonly VisitType|null $type)
private function __construct(private VisitType|null $type)
{
}

View File

@ -13,11 +13,11 @@ use Shlinkio\Shlink\Core\Visit\Geolocation\VisitLocatorInterface;
use Shlinkio\Shlink\Core\Visit\Geolocation\VisitToLocationHelperInterface;
use Shlinkio\Shlink\IpGeolocation\Model\Location;
class LocateUnlocatedVisits implements VisitGeolocationHelperInterface
readonly class LocateUnlocatedVisits implements VisitGeolocationHelperInterface
{
public function __construct(
private readonly VisitLocatorInterface $locator,
private readonly VisitToLocationHelperInterface $visitToLocation,
private VisitLocatorInterface $locator,
private VisitToLocationHelperInterface $visitToLocation,
) {
}

View File

@ -13,12 +13,12 @@ use Throwable;
use function sprintf;
class UpdateGeoLiteDb
readonly class UpdateGeoLiteDb
{
public function __construct(
private readonly GeolocationDbUpdaterInterface $dbUpdater,
private readonly LoggerInterface $logger,
private readonly EventDispatcherInterface $eventDispatcher,
private GeolocationDbUpdaterInterface $dbUpdater,
private LoggerInterface $logger,
private EventDispatcherInterface $eventDispatcher,
) {
}

View File

@ -25,14 +25,14 @@ use function implode;
use function sprintf;
use function trim;
class ExtraPathRedirectMiddleware implements MiddlewareInterface
readonly class ExtraPathRedirectMiddleware implements MiddlewareInterface
{
public function __construct(
private readonly ShortUrlResolverInterface $resolver,
private readonly RequestTrackerInterface $requestTracker,
private readonly ShortUrlRedirectionBuilderInterface $redirectionBuilder,
private readonly RedirectResponseHelperInterface $redirectResponseHelper,
private readonly UrlShortenerOptions $urlShortenerOptions,
private ShortUrlResolverInterface $resolver,
private RequestTrackerInterface $requestTracker,
private ShortUrlRedirectionBuilderInterface $redirectionBuilder,
private RedirectResponseHelperInterface $redirectResponseHelper,
private UrlShortenerOptions $urlShortenerOptions,
) {
}

View File

@ -7,11 +7,11 @@ namespace Shlinkio\Shlink\Core\ShortUrl\Model;
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
use Throwable;
final class UrlShorteningResult
final readonly class UrlShorteningResult
{
private function __construct(
public readonly ShortUrl $shortUrl,
private readonly Throwable|null $errorOnEventDispatching,
public ShortUrl $shortUrl,
private Throwable|null $errorOnEventDispatching,
) {
}

View File

@ -10,11 +10,11 @@ use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier;
use Shlinkio\Shlink\Core\Visit\Repository\VisitDeleterRepositoryInterface;
use Shlinkio\Shlink\Rest\Entity\ApiKey;
class ShortUrlVisitsDeleter implements ShortUrlVisitsDeleterInterface
readonly class ShortUrlVisitsDeleter implements ShortUrlVisitsDeleterInterface
{
public function __construct(
private readonly VisitDeleterRepositoryInterface $repository,
private readonly ShortUrlResolverInterface $resolver,
private VisitDeleterRepositoryInterface $repository,
private ShortUrlResolverInterface $resolver,
) {
}

View File

@ -10,9 +10,9 @@ use Shlinkio\Shlink\Core\Config\Options\RedirectOptions;
use function sprintf;
class RedirectResponseHelper implements RedirectResponseHelperInterface
readonly class RedirectResponseHelper implements RedirectResponseHelperInterface
{
public function __construct(private readonly RedirectOptions $options)
public function __construct(private RedirectOptions $options)
{
}

View File

@ -11,11 +11,11 @@ use Shlinkio\Shlink\Core\Visit\Entity\VisitLocation;
use Shlinkio\Shlink\Core\Visit\Repository\VisitIterationRepositoryInterface;
use Shlinkio\Shlink\IpGeolocation\Model\Location;
class VisitLocator implements VisitLocatorInterface
readonly class VisitLocator implements VisitLocatorInterface
{
public function __construct(
private readonly EntityManagerInterface $em,
private readonly VisitIterationRepositoryInterface $repo,
private EntityManagerInterface $em,
private VisitIterationRepositoryInterface $repo,
) {
}

View File

@ -11,9 +11,9 @@ use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
use Shlinkio\Shlink\IpGeolocation\Model\Location;
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
class VisitToLocationHelper implements VisitToLocationHelperInterface
readonly class VisitToLocationHelper implements VisitToLocationHelperInterface
{
public function __construct(private readonly IpLocationResolverInterface $ipLocationResolver)
public function __construct(private IpLocationResolverInterface $ipLocationResolver)
{
}

View File

@ -9,9 +9,9 @@ use Shlinkio\Shlink\Core\Visit\Repository\VisitDeleterRepositoryInterface;
use Shlinkio\Shlink\Rest\ApiKey\Role;
use Shlinkio\Shlink\Rest\Entity\ApiKey;
class VisitsDeleter implements VisitsDeleterInterface
readonly class VisitsDeleter implements VisitsDeleterInterface
{
public function __construct(private readonly VisitDeleterRepositoryInterface $repository)
public function __construct(private VisitDeleterRepositoryInterface $repository)
{
}