From e0f0bb5523e6a739c223ed1b08f3b86c146c8fef Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 23 May 2021 11:57:31 +0200 Subject: [PATCH] Migrated all constructor props to property promotion when possible --- .github/workflows/ci.yml | 22 +++++++-------- .github/workflows/publish-release.yml | 4 +-- README.md | 2 +- composer.json | 2 +- data/infra/examples/nginx-vhost.conf | 2 +- module/CLI/src/ApiKey/RoleResolver.php | 5 +--- .../CLI/src/Command/Api/DisableKeyCommand.php | 5 +--- .../src/Command/Api/GenerateKeyCommand.php | 11 +++----- .../CLI/src/Command/Api/ListKeysCommand.php | 5 +--- .../Command/Db/AbstractDatabaseCommand.php | 4 +-- .../src/Command/Db/CreateDatabaseCommand.php | 9 ++----- .../src/Command/Domain/ListDomainsCommand.php | 5 +--- .../ShortUrl/DeleteShortUrlCommand.php | 5 +--- .../ShortUrl/GenerateShortUrlCommand.php | 13 +++------ .../src/Command/ShortUrl/GetVisitsCommand.php | 5 +--- .../Command/ShortUrl/ListShortUrlsCommand.php | 11 +++----- .../Command/ShortUrl/ResolveUrlCommand.php | 5 +--- .../CLI/src/Command/Tag/CreateTagCommand.php | 5 +--- .../CLI/src/Command/Tag/DeleteTagsCommand.php | 5 +--- .../CLI/src/Command/Tag/ListTagsCommand.php | 5 +--- .../CLI/src/Command/Tag/RenameTagCommand.php | 5 +--- .../Command/Util/AbstractLockedCommand.php | 5 +--- .../src/Command/Util/LockedCommandConfig.php | 14 ++++------ .../Visit/DownloadGeoLiteDbCommand.php | 4 +-- .../src/Command/Visit/LocateVisitsCommand.php | 9 ++----- module/CLI/src/Util/GeolocationDbUpdater.php | 14 ++++------ module/CLI/src/Util/ProcessRunner.php | 4 +-- module/CLI/src/Util/ShlinkTable.php | 5 +--- module/Core/functions/functions.php | 20 +++++--------- .../src/Action/AbstractTrackingAction.php | 12 +++------ module/Core/src/Action/QrCodeAction.php | 8 ++---- module/Core/src/Action/RedirectAction.php | 5 +--- module/Core/src/Action/RobotsAction.php | 5 +--- module/Core/src/Crawling/CrawlingHelper.php | 5 +--- module/Core/src/Domain/DomainService.php | 7 +---- module/Core/src/Domain/Model/DomainItem.php | 7 +---- module/Core/src/Entity/Domain.php | 5 +--- module/Core/src/Entity/Tag.php | 4 +-- .../src/ErrorHandler/Model/NotFoundType.php | 25 +++++++---------- .../ErrorHandler/NotFoundRedirectHandler.php | 9 ++----- .../ErrorHandler/NotFoundTemplateHandler.php | 1 + .../NotFoundTrackerMiddleware.php | 5 +--- .../NotFoundTypeResolverMiddleware.php | 5 +--- .../CloseDbConnectionEventListener.php | 4 +-- .../Event/AbstractVisitEvent.php | 5 +--- .../src/EventDispatcher/Event/UrlVisited.php | 5 +--- .../Core/src/EventDispatcher/LocateVisit.php | 21 ++++----------- .../EventDispatcher/NotifyVisitToMercure.php | 17 +++--------- .../EventDispatcher/NotifyVisitToWebHooks.php | 27 +++++-------------- .../src/EventDispatcher/UpdateGeoLiteDb.php | 7 +---- .../src/Importer/ImportedLinksProcessor.php | 18 ++++--------- .../Core/src/Importer/ShortUrlImporting.php | 7 +---- .../src/Mercure/MercureUpdatesGenerator.php | 9 ++----- module/Core/src/Model/ShortUrlIdentifier.php | 7 +---- module/Core/src/Model/VisitsParams.php | 8 ++---- .../Adapter/OrphanVisitsPaginatorAdapter.php | 7 +---- .../Adapter/ShortUrlRepositoryAdapter.php | 14 ++++------ .../Adapter/VisitsForTagPaginatorAdapter.php | 17 +++--------- .../Adapter/VisitsPaginatorAdapter.php | 17 +++--------- .../ShortUrl/DeleteShortUrlService.php | 13 +++------ .../src/Service/ShortUrl/ShortCodeHelper.php | 5 +--- .../src/Service/ShortUrl/ShortUrlResolver.php | 5 +--- module/Core/src/Service/ShortUrlService.php | 17 +++--------- module/Core/src/Service/UrlShortener.php | 17 +++--------- .../ShortUrl/Helper/ShortUrlStringifier.php | 7 +---- .../Helper/ShortUrlTitleResolutionHelper.php | 5 +--- .../PersistenceShortUrlRelationResolver.php | 5 +--- .../src/ShortUrl/Spec/BelongsToApiKey.php | 7 +---- .../ShortUrl/Spec/BelongsToApiKeyInlined.php | 5 +--- .../src/ShortUrl/Spec/BelongsToDomain.php | 7 +---- .../ShortUrl/Spec/BelongsToDomainInlined.php | 5 +--- .../Transformer/ShortUrlDataTransformer.php | 5 +--- module/Core/src/Spec/InDateRange.php | 7 +---- module/Core/src/Tag/Model/TagInfo.php | 9 +------ .../Core/src/Tag/Spec/CountTagsWithName.php | 5 +--- module/Core/src/Tag/TagService.php | 5 +--- .../src/Util/CocurSymfonySluggerBridge.php | 5 +--- module/Core/src/Util/DoctrineBatchHelper.php | 5 +--- .../Core/src/Util/RedirectResponseHelper.php | 5 +--- module/Core/src/Util/UrlValidator.php | 7 +---- module/Core/src/Visit/Model/VisitsStats.php | 7 +---- .../Persistence/VisitsCountFiltering.php | 14 ++++------ .../Visit/Persistence/VisitsListFiltering.php | 9 ++----- .../src/Visit/Spec/CountOfOrphanVisits.php | 5 +--- .../src/Visit/Spec/CountOfShortUrlVisits.php | 5 +--- module/Core/src/Visit/VisitLocator.php | 5 +--- module/Core/src/Visit/VisitsStatsHelper.php | 5 +--- module/Core/src/Visit/VisitsTracker.php | 13 +++------ .../Repository/DomainRepositoryTest.php | 5 +--- module/Core/test/Visit/VisitLocatorTest.php | 5 +--- .../src/Action/Domain/ListDomainsAction.php | 5 +--- module/Rest/src/Action/HealthAction.php | 9 ++----- module/Rest/src/Action/MercureInfoAction.php | 7 +---- .../ShortUrl/AbstractCreateShortUrlAction.php | 11 +++----- .../Action/ShortUrl/DeleteShortUrlAction.php | 5 +--- .../Action/ShortUrl/EditShortUrlAction.php | 11 +++----- .../ShortUrl/EditShortUrlTagsAction.php | 5 +--- .../Action/ShortUrl/ListShortUrlsAction.php | 11 +++----- .../Action/ShortUrl/ResolveShortUrlAction.php | 11 +++----- .../Rest/src/Action/Tag/CreateTagsAction.php | 5 +--- .../Rest/src/Action/Tag/DeleteTagsAction.php | 5 +--- module/Rest/src/Action/Tag/ListTagsAction.php | 5 +--- .../Rest/src/Action/Tag/UpdateTagAction.php | 5 +--- .../src/Action/Visit/GlobalVisitsAction.php | 5 +--- .../src/Action/Visit/OrphanVisitsAction.php | 9 ++----- .../src/Action/Visit/ShortUrlVisitsAction.php | 5 +--- .../Rest/src/Action/Visit/TagVisitsAction.php | 5 +--- module/Rest/src/ApiKey/Model/ApiKeyMeta.php | 16 +++++------ .../Rest/src/ApiKey/Model/RoleDefinition.php | 7 +---- .../Spec/WithApiKeySpecsEnsuringJoin.php | 7 +---- module/Rest/src/Entity/ApiKeyRole.php | 9 +------ .../Middleware/AuthenticationMiddleware.php | 13 +++------ .../src/Middleware/CrossDomainMiddleware.php | 5 +--- .../DefaultShortCodesLengthMiddleware.php | 5 +--- ...DropDefaultDomainFromRequestMiddleware.php | 5 +--- .../ShortUrl/OverrideDomainMiddleware.php | 5 +--- module/Rest/src/Service/ApiKeyCheckResult.php | 5 +--- module/Rest/src/Service/ApiKeyService.php | 27 +++++++------------ 118 files changed, 237 insertions(+), 713 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f1aefb80..741f80c0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,7 +48,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - php-version: ['7.4', '8.0'] + php-version: ['8.0'] steps: - name: Checkout code uses: actions/checkout@v2 @@ -63,7 +63,7 @@ jobs: - run: composer install --no-interaction --prefer-dist - run: composer test:unit:ci - uses: actions/upload-artifact@v2 - if: ${{ matrix.php-version == '7.4' }} + if: ${{ matrix.php-version == '8.0' }} with: name: coverage-unit path: | @@ -74,7 +74,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - php-version: ['7.4', '8.0'] + php-version: ['8.0'] steps: - name: Checkout code uses: actions/checkout@v2 @@ -89,7 +89,7 @@ jobs: - run: composer install --no-interaction --prefer-dist - run: composer test:db:sqlite:ci - uses: actions/upload-artifact@v2 - if: ${{ matrix.php-version == '7.4' }} + if: ${{ matrix.php-version == '8.0' }} with: name: coverage-db path: | @@ -100,7 +100,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - php-version: ['7.4', '8.0'] + php-version: ['8.0'] steps: - name: Checkout code uses: actions/checkout@v2 @@ -120,7 +120,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - php-version: ['7.4', '8.0'] + php-version: ['8.0'] steps: - name: Checkout code uses: actions/checkout@v2 @@ -140,7 +140,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - php-version: ['7.4', '8.0'] + php-version: ['8.0'] steps: - name: Checkout code uses: actions/checkout@v2 @@ -160,7 +160,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - php-version: ['7.4', '8.0'] + php-version: ['8.0'] steps: - name: Checkout code uses: actions/checkout@v2 @@ -184,7 +184,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - php-version: ['7.4', '8.0'] + php-version: ['8.0'] steps: - name: Checkout code uses: actions/checkout@v2 @@ -201,7 +201,7 @@ jobs: - run: composer install --no-interaction --prefer-dist - run: bin/test/run-api-tests.sh - uses: actions/upload-artifact@v2 - if: ${{ matrix.php-version == '7.4' }} + if: ${{ matrix.php-version == '8.0' }} with: name: coverage-api path: | @@ -216,7 +216,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - php-version: ['7.4', '8.0'] + php-version: ['8.0'] test-group: ['unit', 'db'] steps: - name: Checkout code diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 26ee4ac0..6ce63cf3 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - php-version: ['7.4', '8.0'] + php-version: ['8.0'] swoole: ['yes', 'no'] steps: - name: Checkout code @@ -54,7 +54,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - php-version: [ '7.4', '8.0' ] + php-version: [ '8.0' ] swoole: [ 'yes', 'no' ] steps: - uses: geekyeggo/delete-artifact@v1 diff --git a/README.md b/README.md index 8d51f05b..cd15bb5c 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ The idea is that you can just generate a container using the image and provide t First, make sure the host where you are going to run shlink fulfills these requirements: -* PHP 7.4 or 8.0 +* PHP 8.0 * The next PHP extensions: json, curl, pdo, intl, gd and gmp. * apcu extension is recommended if you don't plan to use swoole. * xml extension is required if you want to generate QR codes in svg format. diff --git a/composer.json b/composer.json index 7a84c886..1c601b63 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ } ], "require": { - "php": "^7.4 || ^8.0", + "php": "^8.0", "ext-json": "*", "ext-pdo": "*", "akrabat/ip-address-middleware": "^2.0", diff --git a/data/infra/examples/nginx-vhost.conf b/data/infra/examples/nginx-vhost.conf index d5bb0a2c..80ff8afd 100644 --- a/data/infra/examples/nginx-vhost.conf +++ b/data/infra/examples/nginx-vhost.conf @@ -11,7 +11,7 @@ server { location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; - fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; + fastcgi_pass unix:/var/run/php/php8.0-fpm.sock; fastcgi_index index.php; include fastcgi.conf; } diff --git a/module/CLI/src/ApiKey/RoleResolver.php b/module/CLI/src/ApiKey/RoleResolver.php index 67747983..179fff53 100644 --- a/module/CLI/src/ApiKey/RoleResolver.php +++ b/module/CLI/src/ApiKey/RoleResolver.php @@ -10,11 +10,8 @@ use Symfony\Component\Console\Input\InputInterface; class RoleResolver implements RoleResolverInterface { - private DomainServiceInterface $domainService; - - public function __construct(DomainServiceInterface $domainService) + public function __construct(private DomainServiceInterface $domainService) { - $this->domainService = $domainService; } public function determineRoles(InputInterface $input): array diff --git a/module/CLI/src/Command/Api/DisableKeyCommand.php b/module/CLI/src/Command/Api/DisableKeyCommand.php index 1a8024ec..7296632a 100644 --- a/module/CLI/src/Command/Api/DisableKeyCommand.php +++ b/module/CLI/src/Command/Api/DisableKeyCommand.php @@ -19,12 +19,9 @@ class DisableKeyCommand extends Command { public const NAME = 'api-key:disable'; - private ApiKeyServiceInterface $apiKeyService; - - public function __construct(ApiKeyServiceInterface $apiKeyService) + public function __construct(private ApiKeyServiceInterface $apiKeyService) { parent::__construct(); - $this->apiKeyService = $apiKeyService; } protected function configure(): void diff --git a/module/CLI/src/Command/Api/GenerateKeyCommand.php b/module/CLI/src/Command/Api/GenerateKeyCommand.php index 31df82a1..c8f607a4 100644 --- a/module/CLI/src/Command/Api/GenerateKeyCommand.php +++ b/module/CLI/src/Command/Api/GenerateKeyCommand.php @@ -23,14 +23,11 @@ class GenerateKeyCommand extends BaseCommand { public const NAME = 'api-key:generate'; - private ApiKeyServiceInterface $apiKeyService; - private RoleResolverInterface $roleResolver; - - public function __construct(ApiKeyServiceInterface $apiKeyService, RoleResolverInterface $roleResolver) - { + public function __construct( + private ApiKeyServiceInterface $apiKeyService, + private RoleResolverInterface $roleResolver + ) { parent::__construct(); - $this->apiKeyService = $apiKeyService; - $this->roleResolver = $roleResolver; } protected function configure(): void diff --git a/module/CLI/src/Command/Api/ListKeysCommand.php b/module/CLI/src/Command/Api/ListKeysCommand.php index e8326826..6a7124e3 100644 --- a/module/CLI/src/Command/Api/ListKeysCommand.php +++ b/module/CLI/src/Command/Api/ListKeysCommand.php @@ -27,12 +27,9 @@ class ListKeysCommand extends BaseCommand public const NAME = 'api-key:list'; - private ApiKeyServiceInterface $apiKeyService; - - public function __construct(ApiKeyServiceInterface $apiKeyService) + public function __construct(private ApiKeyServiceInterface $apiKeyService) { parent::__construct(); - $this->apiKeyService = $apiKeyService; } protected function configure(): void diff --git a/module/CLI/src/Command/Db/AbstractDatabaseCommand.php b/module/CLI/src/Command/Db/AbstractDatabaseCommand.php index e4515ab5..1b0a4f9b 100644 --- a/module/CLI/src/Command/Db/AbstractDatabaseCommand.php +++ b/module/CLI/src/Command/Db/AbstractDatabaseCommand.php @@ -13,16 +13,14 @@ use Symfony\Component\Process\PhpExecutableFinder; abstract class AbstractDatabaseCommand extends AbstractLockedCommand { - private ProcessRunnerInterface $processRunner; private string $phpBinary; public function __construct( LockFactory $locker, - ProcessRunnerInterface $processRunner, + private ProcessRunnerInterface $processRunner, PhpExecutableFinder $phpFinder ) { parent::__construct($locker); - $this->processRunner = $processRunner; $this->phpBinary = $phpFinder->find(false) ?: 'php'; } diff --git a/module/CLI/src/Command/Db/CreateDatabaseCommand.php b/module/CLI/src/Command/Db/CreateDatabaseCommand.php index ca68f818..ad3959ca 100644 --- a/module/CLI/src/Command/Db/CreateDatabaseCommand.php +++ b/module/CLI/src/Command/Db/CreateDatabaseCommand.php @@ -21,19 +21,14 @@ class CreateDatabaseCommand extends AbstractDatabaseCommand public const DOCTRINE_SCRIPT = 'vendor/doctrine/orm/bin/doctrine.php'; public const DOCTRINE_CREATE_SCHEMA_COMMAND = 'orm:schema-tool:create'; - private Connection $regularConn; - private Connection $noDbNameConn; - public function __construct( LockFactory $locker, ProcessRunnerInterface $processRunner, PhpExecutableFinder $phpFinder, - Connection $conn, - Connection $noDbNameConn + private Connection $regularConn, + private Connection $noDbNameConn ) { parent::__construct($locker, $processRunner, $phpFinder); - $this->regularConn = $conn; - $this->noDbNameConn = $noDbNameConn; } protected function configure(): void diff --git a/module/CLI/src/Command/Domain/ListDomainsCommand.php b/module/CLI/src/Command/Domain/ListDomainsCommand.php index ddcfa1bd..6fa25097 100644 --- a/module/CLI/src/Command/Domain/ListDomainsCommand.php +++ b/module/CLI/src/Command/Domain/ListDomainsCommand.php @@ -18,12 +18,9 @@ class ListDomainsCommand extends Command { public const NAME = 'domain:list'; - private DomainServiceInterface $domainService; - - public function __construct(DomainServiceInterface $domainService) + public function __construct(private DomainServiceInterface $domainService) { parent::__construct(); - $this->domainService = $domainService; } protected function configure(): void diff --git a/module/CLI/src/Command/ShortUrl/DeleteShortUrlCommand.php b/module/CLI/src/Command/ShortUrl/DeleteShortUrlCommand.php index f57001b0..fc4e8331 100644 --- a/module/CLI/src/Command/ShortUrl/DeleteShortUrlCommand.php +++ b/module/CLI/src/Command/ShortUrl/DeleteShortUrlCommand.php @@ -21,12 +21,9 @@ class DeleteShortUrlCommand extends Command { public const NAME = 'short-url:delete'; - private DeleteShortUrlServiceInterface $deleteShortUrlService; - - public function __construct(DeleteShortUrlServiceInterface $deleteShortUrlService) + public function __construct(private DeleteShortUrlServiceInterface $deleteShortUrlService) { parent::__construct(); - $this->deleteShortUrlService = $deleteShortUrlService; } protected function configure(): void diff --git a/module/CLI/src/Command/ShortUrl/GenerateShortUrlCommand.php b/module/CLI/src/Command/ShortUrl/GenerateShortUrlCommand.php index cafd0e5a..e0d2babc 100644 --- a/module/CLI/src/Command/ShortUrl/GenerateShortUrlCommand.php +++ b/module/CLI/src/Command/ShortUrl/GenerateShortUrlCommand.php @@ -30,19 +30,12 @@ class GenerateShortUrlCommand extends BaseCommand { public const NAME = 'short-url:generate'; - private UrlShortenerInterface $urlShortener; - private ShortUrlStringifierInterface $stringifier; - private int $defaultShortCodeLength; - public function __construct( - UrlShortenerInterface $urlShortener, - ShortUrlStringifierInterface $stringifier, - int $defaultShortCodeLength + private UrlShortenerInterface $urlShortener, + private ShortUrlStringifierInterface $stringifier, + private int $defaultShortCodeLength ) { parent::__construct(); - $this->urlShortener = $urlShortener; - $this->stringifier = $stringifier; - $this->defaultShortCodeLength = $defaultShortCodeLength; } protected function configure(): void diff --git a/module/CLI/src/Command/ShortUrl/GetVisitsCommand.php b/module/CLI/src/Command/ShortUrl/GetVisitsCommand.php index 7b020356..aac45aff 100644 --- a/module/CLI/src/Command/ShortUrl/GetVisitsCommand.php +++ b/module/CLI/src/Command/ShortUrl/GetVisitsCommand.php @@ -27,11 +27,8 @@ class GetVisitsCommand extends AbstractWithDateRangeCommand { public const NAME = 'short-url:visits'; - private VisitsStatsHelperInterface $visitsHelper; - - public function __construct(VisitsStatsHelperInterface $visitsHelper) + public function __construct(private VisitsStatsHelperInterface $visitsHelper) { - $this->visitsHelper = $visitsHelper; parent::__construct(); } diff --git a/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php b/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php index 0d637f5f..9673641d 100644 --- a/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php +++ b/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php @@ -33,14 +33,11 @@ class ListShortUrlsCommand extends AbstractWithDateRangeCommand public const NAME = 'short-url:list'; - private ShortUrlServiceInterface $shortUrlService; - private DataTransformerInterface $transformer; - - public function __construct(ShortUrlServiceInterface $shortUrlService, DataTransformerInterface $transformer) - { + public function __construct( + private ShortUrlServiceInterface $shortUrlService, + private DataTransformerInterface $transformer + ) { parent::__construct(); - $this->shortUrlService = $shortUrlService; - $this->transformer = $transformer; } protected function doConfigure(): void diff --git a/module/CLI/src/Command/ShortUrl/ResolveUrlCommand.php b/module/CLI/src/Command/ShortUrl/ResolveUrlCommand.php index e6fdef3d..47a30c8e 100644 --- a/module/CLI/src/Command/ShortUrl/ResolveUrlCommand.php +++ b/module/CLI/src/Command/ShortUrl/ResolveUrlCommand.php @@ -21,12 +21,9 @@ class ResolveUrlCommand extends Command { public const NAME = 'short-url:parse'; - private ShortUrlResolverInterface $urlResolver; - - public function __construct(ShortUrlResolverInterface $urlResolver) + public function __construct(private ShortUrlResolverInterface $urlResolver) { parent::__construct(); - $this->urlResolver = $urlResolver; } protected function configure(): void diff --git a/module/CLI/src/Command/Tag/CreateTagCommand.php b/module/CLI/src/Command/Tag/CreateTagCommand.php index 0003319d..99eef614 100644 --- a/module/CLI/src/Command/Tag/CreateTagCommand.php +++ b/module/CLI/src/Command/Tag/CreateTagCommand.php @@ -17,12 +17,9 @@ class CreateTagCommand extends Command { public const NAME = 'tag:create'; - private TagServiceInterface $tagService; - - public function __construct(TagServiceInterface $tagService) + public function __construct(private TagServiceInterface $tagService) { parent::__construct(); - $this->tagService = $tagService; } protected function configure(): void diff --git a/module/CLI/src/Command/Tag/DeleteTagsCommand.php b/module/CLI/src/Command/Tag/DeleteTagsCommand.php index 2b3eae14..5a4f81ac 100644 --- a/module/CLI/src/Command/Tag/DeleteTagsCommand.php +++ b/module/CLI/src/Command/Tag/DeleteTagsCommand.php @@ -16,12 +16,9 @@ class DeleteTagsCommand extends Command { public const NAME = 'tag:delete'; - private TagServiceInterface $tagService; - - public function __construct(TagServiceInterface $tagService) + public function __construct(private TagServiceInterface $tagService) { parent::__construct(); - $this->tagService = $tagService; } protected function configure(): void diff --git a/module/CLI/src/Command/Tag/ListTagsCommand.php b/module/CLI/src/Command/Tag/ListTagsCommand.php index 11e22a4f..99889fa3 100644 --- a/module/CLI/src/Command/Tag/ListTagsCommand.php +++ b/module/CLI/src/Command/Tag/ListTagsCommand.php @@ -18,12 +18,9 @@ class ListTagsCommand extends Command { public const NAME = 'tag:list'; - private TagServiceInterface $tagService; - - public function __construct(TagServiceInterface $tagService) + public function __construct(private TagServiceInterface $tagService) { parent::__construct(); - $this->tagService = $tagService; } protected function configure(): void diff --git a/module/CLI/src/Command/Tag/RenameTagCommand.php b/module/CLI/src/Command/Tag/RenameTagCommand.php index 8bfb0242..23c1568d 100644 --- a/module/CLI/src/Command/Tag/RenameTagCommand.php +++ b/module/CLI/src/Command/Tag/RenameTagCommand.php @@ -19,12 +19,9 @@ class RenameTagCommand extends Command { public const NAME = 'tag:rename'; - private TagServiceInterface $tagService; - - public function __construct(TagServiceInterface $tagService) + public function __construct(private TagServiceInterface $tagService) { parent::__construct(); - $this->tagService = $tagService; } protected function configure(): void diff --git a/module/CLI/src/Command/Util/AbstractLockedCommand.php b/module/CLI/src/Command/Util/AbstractLockedCommand.php index 8a43653d..9482694b 100644 --- a/module/CLI/src/Command/Util/AbstractLockedCommand.php +++ b/module/CLI/src/Command/Util/AbstractLockedCommand.php @@ -14,12 +14,9 @@ use function sprintf; abstract class AbstractLockedCommand extends Command { - private LockFactory $locker; - - public function __construct(LockFactory $locker) + public function __construct(private LockFactory $locker) { parent::__construct(); - $this->locker = $locker; } final protected function execute(InputInterface $input, OutputInterface $output): ?int diff --git a/module/CLI/src/Command/Util/LockedCommandConfig.php b/module/CLI/src/Command/Util/LockedCommandConfig.php index 8de204c5..af9d704d 100644 --- a/module/CLI/src/Command/Util/LockedCommandConfig.php +++ b/module/CLI/src/Command/Util/LockedCommandConfig.php @@ -8,15 +8,11 @@ final class LockedCommandConfig { public const DEFAULT_TTL = 600.0; // 10 minutes - private string $lockName; - private bool $isBlocking; - private float $ttl; - - private function __construct(string $lockName, bool $isBlocking, float $ttl = self::DEFAULT_TTL) - { - $this->lockName = $lockName; - $this->isBlocking = $isBlocking; - $this->ttl = $ttl; + private function __construct( + private string $lockName, + private bool $isBlocking, + private float $ttl = self::DEFAULT_TTL + ) { } public static function blocking(string $lockName): self diff --git a/module/CLI/src/Command/Visit/DownloadGeoLiteDbCommand.php b/module/CLI/src/Command/Visit/DownloadGeoLiteDbCommand.php index 3d76663a..f86edfd1 100644 --- a/module/CLI/src/Command/Visit/DownloadGeoLiteDbCommand.php +++ b/module/CLI/src/Command/Visit/DownloadGeoLiteDbCommand.php @@ -19,13 +19,11 @@ class DownloadGeoLiteDbCommand extends Command { public const NAME = 'visit:download-db'; - private GeolocationDbUpdaterInterface $dbUpdater; private ?ProgressBar $progressBar = null; - public function __construct(GeolocationDbUpdaterInterface $dbUpdater) + public function __construct(private GeolocationDbUpdaterInterface $dbUpdater) { parent::__construct(); - $this->dbUpdater = $dbUpdater; } protected function configure(): void diff --git a/module/CLI/src/Command/Visit/LocateVisitsCommand.php b/module/CLI/src/Command/Visit/LocateVisitsCommand.php index 0bcfb1d7..a9854c5b 100644 --- a/module/CLI/src/Command/Visit/LocateVisitsCommand.php +++ b/module/CLI/src/Command/Visit/LocateVisitsCommand.php @@ -30,19 +30,14 @@ class LocateVisitsCommand extends AbstractLockedCommand implements VisitGeolocat { public const NAME = 'visit:locate'; - private VisitLocatorInterface $visitLocator; - private IpLocationResolverInterface $ipLocationResolver; - private SymfonyStyle $io; public function __construct( - VisitLocatorInterface $visitLocator, - IpLocationResolverInterface $ipLocationResolver, + private VisitLocatorInterface $visitLocator, + private IpLocationResolverInterface $ipLocationResolver, LockFactory $locker ) { parent::__construct($locker); - $this->visitLocator = $visitLocator; - $this->ipLocationResolver = $ipLocationResolver; } protected function configure(): void diff --git a/module/CLI/src/Util/GeolocationDbUpdater.php b/module/CLI/src/Util/GeolocationDbUpdater.php index 6e7c2da2..215ee85c 100644 --- a/module/CLI/src/Util/GeolocationDbUpdater.php +++ b/module/CLI/src/Util/GeolocationDbUpdater.php @@ -18,15 +18,11 @@ class GeolocationDbUpdater implements GeolocationDbUpdaterInterface { private const LOCK_NAME = 'geolocation-db-update'; - private DbUpdaterInterface $dbUpdater; - private Reader $geoLiteDbReader; - private LockFactory $locker; - - public function __construct(DbUpdaterInterface $dbUpdater, Reader $geoLiteDbReader, LockFactory $locker) - { - $this->dbUpdater = $dbUpdater; - $this->geoLiteDbReader = $geoLiteDbReader; - $this->locker = $locker; + public function __construct( + private DbUpdaterInterface $dbUpdater, + private Reader $geoLiteDbReader, + private LockFactory $locker + ) { } /** diff --git a/module/CLI/src/Util/ProcessRunner.php b/module/CLI/src/Util/ProcessRunner.php index 1a6b826e..66e94eb6 100644 --- a/module/CLI/src/Util/ProcessRunner.php +++ b/module/CLI/src/Util/ProcessRunner.php @@ -18,12 +18,10 @@ use function str_replace; class ProcessRunner implements ProcessRunnerInterface { - private ProcessHelper $helper; private Closure $createProcess; - public function __construct(ProcessHelper $helper, ?callable $createProcess = null) + public function __construct(private ProcessHelper $helper, ?callable $createProcess = null) { - $this->helper = $helper; $this->createProcess = $createProcess !== null ? Closure::fromCallable($createProcess) : static fn (array $cmd) => new Process($cmd, null, null, null, LockedCommandConfig::DEFAULT_TTL); diff --git a/module/CLI/src/Util/ShlinkTable.php b/module/CLI/src/Util/ShlinkTable.php index ac8733ad..5788ce12 100644 --- a/module/CLI/src/Util/ShlinkTable.php +++ b/module/CLI/src/Util/ShlinkTable.php @@ -12,11 +12,8 @@ final class ShlinkTable private const DEFAULT_STYLE_NAME = 'default'; private const TABLE_TITLE_STYLE = ' %s '; - private ?Table $baseTable; - - public function __construct(Table $baseTable) + public function __construct(private Table $baseTable) { - $this->baseTable = $baseTable; } public static function fromOutput(OutputInterface $output): self diff --git a/module/Core/functions/functions.php b/module/Core/functions/functions.php index 867f7c7d..7910ad1a 100644 --- a/module/Core/functions/functions.php +++ b/module/Core/functions/functions.php @@ -51,20 +51,12 @@ function parseDateRangeFromQuery(array $query, string $startDateName, string $en $startDate = parseDateFromQuery($query, $startDateName); $endDate = parseDateFromQuery($query, $endDateName); - // TODO Use match expression when migrating to PHP8 - if ($startDate === null && $endDate === null) { - return DateRange::emptyInstance(); - } - - if ($startDate !== null && $endDate !== null) { - return DateRange::withStartAndEndDate($startDate, $endDate); - } - - if ($startDate !== null) { - return DateRange::withStartDate($startDate); - } - - return DateRange::withEndDate($endDate); + return match (true) { + $startDate === null && $endDate === null => DateRange::emptyInstance(), + $startDate !== null && $endDate !== null => DateRange::withStartAndEndDate($startDate, $endDate), + $startDate !== null => DateRange::withStartDate($startDate), + default => DateRange::withEndDate($endDate), + }; } /** diff --git a/module/Core/src/Action/AbstractTrackingAction.php b/module/Core/src/Action/AbstractTrackingAction.php index 567e930c..582b7bce 100644 --- a/module/Core/src/Action/AbstractTrackingAction.php +++ b/module/Core/src/Action/AbstractTrackingAction.php @@ -27,20 +27,14 @@ use function array_merge; abstract class AbstractTrackingAction implements MiddlewareInterface, RequestMethodInterface { - private ShortUrlResolverInterface $urlResolver; - private VisitsTrackerInterface $visitTracker; - private TrackingOptions $trackingOptions; private LoggerInterface $logger; public function __construct( - ShortUrlResolverInterface $urlResolver, - VisitsTrackerInterface $visitTracker, - TrackingOptions $trackingOptions, + private ShortUrlResolverInterface $urlResolver, + private VisitsTrackerInterface $visitTracker, + private TrackingOptions $trackingOptions, ?LoggerInterface $logger = null ) { - $this->urlResolver = $urlResolver; - $this->visitTracker = $visitTracker; - $this->trackingOptions = $trackingOptions; $this->logger = $logger ?? new NullLogger(); } diff --git a/module/Core/src/Action/QrCodeAction.php b/module/Core/src/Action/QrCodeAction.php index 1b2b5012..177d90fc 100644 --- a/module/Core/src/Action/QrCodeAction.php +++ b/module/Core/src/Action/QrCodeAction.php @@ -24,18 +24,14 @@ class QrCodeAction implements MiddlewareInterface private const MIN_SIZE = 50; private const MAX_SIZE = 1000; - private ShortUrlResolverInterface $urlResolver; - private ShortUrlStringifierInterface $stringifier; private LoggerInterface $logger; public function __construct( - ShortUrlResolverInterface $urlResolver, - ShortUrlStringifierInterface $stringifier, + private ShortUrlResolverInterface $urlResolver, + private ShortUrlStringifierInterface $stringifier, ?LoggerInterface $logger = null ) { - $this->urlResolver = $urlResolver; $this->logger = $logger ?? new NullLogger(); - $this->stringifier = $stringifier; } public function process(Request $request, RequestHandlerInterface $handler): Response diff --git a/module/Core/src/Action/RedirectAction.php b/module/Core/src/Action/RedirectAction.php index 7da67b59..e1c6757c 100644 --- a/module/Core/src/Action/RedirectAction.php +++ b/module/Core/src/Action/RedirectAction.php @@ -16,17 +16,14 @@ use Shlinkio\Shlink\Core\Visit\VisitsTrackerInterface; class RedirectAction extends AbstractTrackingAction implements StatusCodeInterface { - private RedirectResponseHelperInterface $redirectResponseHelper; - public function __construct( ShortUrlResolverInterface $urlResolver, VisitsTrackerInterface $visitTracker, Options\TrackingOptions $trackingOptions, - RedirectResponseHelperInterface $redirectResponseHelper, + private RedirectResponseHelperInterface $redirectResponseHelper, ?LoggerInterface $logger = null ) { parent::__construct($urlResolver, $visitTracker, $trackingOptions, $logger); - $this->redirectResponseHelper = $redirectResponseHelper; } protected function createSuccessResp(string $longUrl): Response diff --git a/module/Core/src/Action/RobotsAction.php b/module/Core/src/Action/RobotsAction.php index 31539b92..b7fa7d42 100644 --- a/module/Core/src/Action/RobotsAction.php +++ b/module/Core/src/Action/RobotsAction.php @@ -17,11 +17,8 @@ use const PHP_EOL; class RobotsAction implements RequestHandlerInterface, StatusCodeInterface { - private CrawlingHelperInterface $crawlingHelper; - - public function __construct(CrawlingHelperInterface $crawlingHelper) + public function __construct(private CrawlingHelperInterface $crawlingHelper) { - $this->crawlingHelper = $crawlingHelper; } public function handle(ServerRequestInterface $request): ResponseInterface diff --git a/module/Core/src/Crawling/CrawlingHelper.php b/module/Core/src/Crawling/CrawlingHelper.php index 5f688645..e620370f 100644 --- a/module/Core/src/Crawling/CrawlingHelper.php +++ b/module/Core/src/Crawling/CrawlingHelper.php @@ -10,11 +10,8 @@ use Shlinkio\Shlink\Core\Repository\ShortUrlRepositoryInterface; class CrawlingHelper implements CrawlingHelperInterface { - private EntityManagerInterface $em; - - public function __construct(EntityManagerInterface $em) + public function __construct(private EntityManagerInterface $em) { - $this->em = $em; } public function listCrawlableShortCodes(): iterable diff --git a/module/Core/src/Domain/DomainService.php b/module/Core/src/Domain/DomainService.php index 5a573799..3a582ee6 100644 --- a/module/Core/src/Domain/DomainService.php +++ b/module/Core/src/Domain/DomainService.php @@ -16,13 +16,8 @@ use function Functional\map; class DomainService implements DomainServiceInterface { - private EntityManagerInterface $em; - private string $defaultDomain; - - public function __construct(EntityManagerInterface $em, string $defaultDomain) + public function __construct(private EntityManagerInterface $em, private string $defaultDomain) { - $this->em = $em; - $this->defaultDomain = $defaultDomain; } /** diff --git a/module/Core/src/Domain/Model/DomainItem.php b/module/Core/src/Domain/Model/DomainItem.php index 4006b186..f389f1e7 100644 --- a/module/Core/src/Domain/Model/DomainItem.php +++ b/module/Core/src/Domain/Model/DomainItem.php @@ -8,13 +8,8 @@ use JsonSerializable; final class DomainItem implements JsonSerializable { - private string $domain; - private bool $isDefault; - - public function __construct(string $domain, bool $isDefault) + public function __construct(private string $domain, private bool $isDefault) { - $this->domain = $domain; - $this->isDefault = $isDefault; } public function jsonSerialize(): array diff --git a/module/Core/src/Entity/Domain.php b/module/Core/src/Entity/Domain.php index f836f7ed..ee094576 100644 --- a/module/Core/src/Entity/Domain.php +++ b/module/Core/src/Entity/Domain.php @@ -9,11 +9,8 @@ use Shlinkio\Shlink\Common\Entity\AbstractEntity; class Domain extends AbstractEntity implements JsonSerializable { - private string $authority; - - public function __construct(string $authority) + public function __construct(private string $authority) { - $this->authority = $authority; } public function getAuthority(): string diff --git a/module/Core/src/Entity/Tag.php b/module/Core/src/Entity/Tag.php index 54c05c56..8dc5cf29 100644 --- a/module/Core/src/Entity/Tag.php +++ b/module/Core/src/Entity/Tag.php @@ -10,12 +10,10 @@ use Shlinkio\Shlink\Common\Entity\AbstractEntity; class Tag extends AbstractEntity implements JsonSerializable { - private string $name; private Collections\Collection $shortUrls; - public function __construct(string $name) + public function __construct(private string $name) { - $this->name = $name; $this->shortUrls = new Collections\ArrayCollection(); } diff --git a/module/Core/src/ErrorHandler/Model/NotFoundType.php b/module/Core/src/ErrorHandler/Model/NotFoundType.php index 57176e84..39970dea 100644 --- a/module/Core/src/ErrorHandler/Model/NotFoundType.php +++ b/module/Core/src/ErrorHandler/Model/NotFoundType.php @@ -13,31 +13,24 @@ use function rtrim; class NotFoundType { - private string $type; - - private function __construct(string $type) + private function __construct(private string $type) { - $this->type = $type; } public static function fromRequest(ServerRequestInterface $request, string $basePath): self { - $isBaseUrl = rtrim($request->getUri()->getPath(), '/') === $basePath; - if ($isBaseUrl) { - return new self(Visit::TYPE_BASE_URL); - } - /** @var RouteResult $routeResult */ $routeResult = $request->getAttribute(RouteResult::class, RouteResult::fromRouteFailure(null)); - if ($routeResult->isFailure()) { - return new self(Visit::TYPE_REGULAR_404); - } + $isBaseUrl = rtrim($request->getUri()->getPath(), '/') === $basePath; - if ($routeResult->getMatchedRouteName() === RedirectAction::class) { - return new self(Visit::TYPE_INVALID_SHORT_URL); - } + $type = match (true) { + $isBaseUrl => Visit::TYPE_BASE_URL, + $routeResult->isFailure() => Visit::TYPE_REGULAR_404, + $routeResult->getMatchedRouteName() === RedirectAction::class => Visit::TYPE_INVALID_SHORT_URL, + default => self::class, + }; - return new self(self::class); + return new self($type); } public function isBaseUrl(): bool diff --git a/module/Core/src/ErrorHandler/NotFoundRedirectHandler.php b/module/Core/src/ErrorHandler/NotFoundRedirectHandler.php index 1f3b4fed..27fcf991 100644 --- a/module/Core/src/ErrorHandler/NotFoundRedirectHandler.php +++ b/module/Core/src/ErrorHandler/NotFoundRedirectHandler.php @@ -14,15 +14,10 @@ use Shlinkio\Shlink\Core\Util\RedirectResponseHelperInterface; class NotFoundRedirectHandler implements MiddlewareInterface { - private Options\NotFoundRedirectOptions $redirectOptions; - private RedirectResponseHelperInterface $redirectResponseHelper; - public function __construct( - Options\NotFoundRedirectOptions $redirectOptions, - RedirectResponseHelperInterface $redirectResponseHelper + private Options\NotFoundRedirectOptions $redirectOptions, + private RedirectResponseHelperInterface $redirectResponseHelper ) { - $this->redirectOptions = $redirectOptions; - $this->redirectResponseHelper = $redirectResponseHelper; } public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface diff --git a/module/Core/src/ErrorHandler/NotFoundTemplateHandler.php b/module/Core/src/ErrorHandler/NotFoundTemplateHandler.php index 61d67403..cd0f60be 100644 --- a/module/Core/src/ErrorHandler/NotFoundTemplateHandler.php +++ b/module/Core/src/ErrorHandler/NotFoundTemplateHandler.php @@ -20,6 +20,7 @@ class NotFoundTemplateHandler implements RequestHandlerInterface private const TEMPLATES_BASE_DIR = __DIR__ . '/../../templates'; public const NOT_FOUND_TEMPLATE = '404.html'; public const INVALID_SHORT_CODE_TEMPLATE = 'invalid-short-code.html'; + private Closure $readFile; public function __construct(?callable $readFile = null) diff --git a/module/Core/src/ErrorHandler/NotFoundTrackerMiddleware.php b/module/Core/src/ErrorHandler/NotFoundTrackerMiddleware.php index b81e55de..473a0b60 100644 --- a/module/Core/src/ErrorHandler/NotFoundTrackerMiddleware.php +++ b/module/Core/src/ErrorHandler/NotFoundTrackerMiddleware.php @@ -14,11 +14,8 @@ use Shlinkio\Shlink\Core\Visit\VisitsTrackerInterface; class NotFoundTrackerMiddleware implements MiddlewareInterface { - private VisitsTrackerInterface $visitsTracker; - - public function __construct(VisitsTrackerInterface $visitsTracker) + public function __construct(private VisitsTrackerInterface $visitsTracker) { - $this->visitsTracker = $visitsTracker; } public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface diff --git a/module/Core/src/ErrorHandler/NotFoundTypeResolverMiddleware.php b/module/Core/src/ErrorHandler/NotFoundTypeResolverMiddleware.php index 6f13db73..7e36135a 100644 --- a/module/Core/src/ErrorHandler/NotFoundTypeResolverMiddleware.php +++ b/module/Core/src/ErrorHandler/NotFoundTypeResolverMiddleware.php @@ -12,11 +12,8 @@ use Shlinkio\Shlink\Core\ErrorHandler\Model\NotFoundType; class NotFoundTypeResolverMiddleware implements MiddlewareInterface { - private string $shlinkBasePath; - - public function __construct(string $shlinkBasePath) + public function __construct(private string $shlinkBasePath) { - $this->shlinkBasePath = $shlinkBasePath; } public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface diff --git a/module/Core/src/EventDispatcher/CloseDbConnectionEventListener.php b/module/Core/src/EventDispatcher/CloseDbConnectionEventListener.php index 7f2c7297..079c6195 100644 --- a/module/Core/src/EventDispatcher/CloseDbConnectionEventListener.php +++ b/module/Core/src/EventDispatcher/CloseDbConnectionEventListener.php @@ -8,13 +8,11 @@ use Shlinkio\Shlink\Common\Doctrine\ReopeningEntityManagerInterface; class CloseDbConnectionEventListener { - private ReopeningEntityManagerInterface $em; /** @var callable */ private $wrapped; - public function __construct(ReopeningEntityManagerInterface $em, callable $wrapped) + public function __construct(private ReopeningEntityManagerInterface $em, callable $wrapped) { - $this->em = $em; $this->wrapped = $wrapped; } diff --git a/module/Core/src/EventDispatcher/Event/AbstractVisitEvent.php b/module/Core/src/EventDispatcher/Event/AbstractVisitEvent.php index 09869cb2..c4bc1818 100644 --- a/module/Core/src/EventDispatcher/Event/AbstractVisitEvent.php +++ b/module/Core/src/EventDispatcher/Event/AbstractVisitEvent.php @@ -8,11 +8,8 @@ use JsonSerializable; abstract class AbstractVisitEvent implements JsonSerializable { - protected string $visitId; - - public function __construct(string $visitId) + public function __construct(protected string $visitId) { - $this->visitId = $visitId; } public function visitId(): string diff --git a/module/Core/src/EventDispatcher/Event/UrlVisited.php b/module/Core/src/EventDispatcher/Event/UrlVisited.php index 87b9e4cb..633b439e 100644 --- a/module/Core/src/EventDispatcher/Event/UrlVisited.php +++ b/module/Core/src/EventDispatcher/Event/UrlVisited.php @@ -6,12 +6,9 @@ namespace Shlinkio\Shlink\Core\EventDispatcher\Event; final class UrlVisited extends AbstractVisitEvent { - private ?string $originalIpAddress; - - public function __construct(string $visitId, ?string $originalIpAddress = null) + public function __construct(string $visitId, private ?string $originalIpAddress = null) { parent::__construct($visitId); - $this->originalIpAddress = $originalIpAddress; } public function originalIpAddress(): ?string diff --git a/module/Core/src/EventDispatcher/LocateVisit.php b/module/Core/src/EventDispatcher/LocateVisit.php index 0150c529..046430df 100644 --- a/module/Core/src/EventDispatcher/LocateVisit.php +++ b/module/Core/src/EventDispatcher/LocateVisit.php @@ -19,24 +19,13 @@ use Throwable; class LocateVisit { - private IpLocationResolverInterface $ipLocationResolver; - private EntityManagerInterface $em; - private LoggerInterface $logger; - private DbUpdaterInterface $dbUpdater; - private EventDispatcherInterface $eventDispatcher; - public function __construct( - IpLocationResolverInterface $ipLocationResolver, - EntityManagerInterface $em, - LoggerInterface $logger, - DbUpdaterInterface $dbUpdater, - EventDispatcherInterface $eventDispatcher + private IpLocationResolverInterface $ipLocationResolver, + private EntityManagerInterface $em, + private LoggerInterface $logger, + private DbUpdaterInterface $dbUpdater, + private EventDispatcherInterface $eventDispatcher ) { - $this->ipLocationResolver = $ipLocationResolver; - $this->em = $em; - $this->logger = $logger; - $this->dbUpdater = $dbUpdater; - $this->eventDispatcher = $eventDispatcher; } public function __invoke(UrlVisited $shortUrlVisited): void diff --git a/module/Core/src/EventDispatcher/NotifyVisitToMercure.php b/module/Core/src/EventDispatcher/NotifyVisitToMercure.php index 33adf965..d1ad8201 100644 --- a/module/Core/src/EventDispatcher/NotifyVisitToMercure.php +++ b/module/Core/src/EventDispatcher/NotifyVisitToMercure.php @@ -17,21 +17,12 @@ use function Functional\each; class NotifyVisitToMercure { - private HubInterface $hub; - private MercureUpdatesGeneratorInterface $updatesGenerator; - private EntityManagerInterface $em; - private LoggerInterface $logger; - public function __construct( - HubInterface $hub, - MercureUpdatesGeneratorInterface $updatesGenerator, - EntityManagerInterface $em, - LoggerInterface $logger + private HubInterface $hub, + private MercureUpdatesGeneratorInterface $updatesGenerator, + private EntityManagerInterface $em, + private LoggerInterface $logger ) { - $this->hub = $hub; - $this->em = $em; - $this->logger = $logger; - $this->updatesGenerator = $updatesGenerator; } public function __invoke(VisitLocated $shortUrlLocated): void diff --git a/module/Core/src/EventDispatcher/NotifyVisitToWebHooks.php b/module/Core/src/EventDispatcher/NotifyVisitToWebHooks.php index b236a1c1..5b4e2818 100644 --- a/module/Core/src/EventDispatcher/NotifyVisitToWebHooks.php +++ b/module/Core/src/EventDispatcher/NotifyVisitToWebHooks.php @@ -24,28 +24,15 @@ use function Functional\partial_left; class NotifyVisitToWebHooks { - private ClientInterface $httpClient; - private EntityManagerInterface $em; - private LoggerInterface $logger; - /** @var string[] */ - private array $webhooks; - private DataTransformerInterface $transformer; - private AppOptions $appOptions; - public function __construct( - ClientInterface $httpClient, - EntityManagerInterface $em, - LoggerInterface $logger, - array $webhooks, - DataTransformerInterface $transformer, - AppOptions $appOptions + private ClientInterface $httpClient, + private EntityManagerInterface $em, + private LoggerInterface $logger, + /** @var string[] */ + private array $webhooks, + private DataTransformerInterface $transformer, + private AppOptions $appOptions ) { - $this->httpClient = $httpClient; - $this->em = $em; - $this->logger = $logger; - $this->webhooks = $webhooks; - $this->transformer = $transformer; - $this->appOptions = $appOptions; } public function __invoke(VisitLocated $shortUrlLocated): void diff --git a/module/Core/src/EventDispatcher/UpdateGeoLiteDb.php b/module/Core/src/EventDispatcher/UpdateGeoLiteDb.php index f17a7ffb..13941f43 100644 --- a/module/Core/src/EventDispatcher/UpdateGeoLiteDb.php +++ b/module/Core/src/EventDispatcher/UpdateGeoLiteDb.php @@ -12,13 +12,8 @@ use function sprintf; class UpdateGeoLiteDb { - private GeolocationDbUpdaterInterface $dbUpdater; - private LoggerInterface $logger; - - public function __construct(GeolocationDbUpdaterInterface $dbUpdater, LoggerInterface $logger) + public function __construct(private GeolocationDbUpdaterInterface $dbUpdater, private LoggerInterface $logger) { - $this->dbUpdater = $dbUpdater; - $this->logger = $logger; } public function __invoke(): void diff --git a/module/Core/src/Importer/ImportedLinksProcessor.php b/module/Core/src/Importer/ImportedLinksProcessor.php index e700e8a8..7427057f 100644 --- a/module/Core/src/Importer/ImportedLinksProcessor.php +++ b/module/Core/src/Importer/ImportedLinksProcessor.php @@ -20,22 +20,14 @@ use function sprintf; class ImportedLinksProcessor implements ImportedLinksProcessorInterface { - private EntityManagerInterface $em; - private ShortUrlRelationResolverInterface $relationResolver; - private ShortCodeHelperInterface $shortCodeHelper; - private DoctrineBatchHelperInterface $batchHelper; private ShortUrlRepositoryInterface $shortUrlRepo; public function __construct( - EntityManagerInterface $em, - ShortUrlRelationResolverInterface $relationResolver, - ShortCodeHelperInterface $shortCodeHelper, - DoctrineBatchHelperInterface $batchHelper + private EntityManagerInterface $em, + private ShortUrlRelationResolverInterface $relationResolver, + private ShortCodeHelperInterface $shortCodeHelper, + private DoctrineBatchHelperInterface $batchHelper ) { - $this->em = $em; - $this->relationResolver = $relationResolver; - $this->shortCodeHelper = $shortCodeHelper; - $this->batchHelper = $batchHelper; $this->shortUrlRepo = $this->em->getRepository(ShortUrl::class); // @phpstan-ignore-line } @@ -64,7 +56,7 @@ class ImportedLinksProcessor implements ImportedLinksProcessorInterface try { $shortUrlImporting = $this->resolveShortUrl($importedUrl, $importShortCodes, $skipOnShortCodeConflict); - } catch (NonUniqueSlugException $e) { + } catch (NonUniqueSlugException) { $io->text(sprintf('%s: Error', $longUrl)); continue; } diff --git a/module/Core/src/Importer/ShortUrlImporting.php b/module/Core/src/Importer/ShortUrlImporting.php index b5ae4651..9b3fa998 100644 --- a/module/Core/src/Importer/ShortUrlImporting.php +++ b/module/Core/src/Importer/ShortUrlImporting.php @@ -14,13 +14,8 @@ use function sprintf; final class ShortUrlImporting { - private ShortUrl $shortUrl; - private bool $isNew; - - private function __construct(ShortUrl $shortUrl, bool $isNew) + private function __construct(private ShortUrl $shortUrl, private bool $isNew) { - $this->shortUrl = $shortUrl; - $this->isNew = $isNew; } public static function fromExistingShortUrl(ShortUrl $shortUrl): self diff --git a/module/Core/src/Mercure/MercureUpdatesGenerator.php b/module/Core/src/Mercure/MercureUpdatesGenerator.php index 23b3796c..c6c7a4d6 100644 --- a/module/Core/src/Mercure/MercureUpdatesGenerator.php +++ b/module/Core/src/Mercure/MercureUpdatesGenerator.php @@ -18,15 +18,10 @@ final class MercureUpdatesGenerator implements MercureUpdatesGeneratorInterface private const NEW_VISIT_TOPIC = 'https://shlink.io/new-visit'; private const NEW_ORPHAN_VISIT_TOPIC = 'https://shlink.io/new-orphan-visit'; - private DataTransformerInterface $shortUrlTransformer; - private DataTransformerInterface $orphanVisitTransformer; - public function __construct( - DataTransformerInterface $shortUrlTransformer, - DataTransformerInterface $orphanVisitTransformer + private DataTransformerInterface $shortUrlTransformer, + private DataTransformerInterface $orphanVisitTransformer ) { - $this->shortUrlTransformer = $shortUrlTransformer; - $this->orphanVisitTransformer = $orphanVisitTransformer; } public function newVisitUpdate(Visit $visit): Update diff --git a/module/Core/src/Model/ShortUrlIdentifier.php b/module/Core/src/Model/ShortUrlIdentifier.php index a277782c..cf7c17d3 100644 --- a/module/Core/src/Model/ShortUrlIdentifier.php +++ b/module/Core/src/Model/ShortUrlIdentifier.php @@ -10,13 +10,8 @@ use Symfony\Component\Console\Input\InputInterface; final class ShortUrlIdentifier { - private string $shortCode; - private ?string $domain; - - public function __construct(string $shortCode, ?string $domain = null) + public function __construct(private string $shortCode, private ?string $domain = null) { - $this->shortCode = $shortCode; - $this->domain = $domain; } public static function fromApiRequest(ServerRequestInterface $request): self diff --git a/module/Core/src/Model/VisitsParams.php b/module/Core/src/Model/VisitsParams.php index f8498c7a..659eb5dc 100644 --- a/module/Core/src/Model/VisitsParams.php +++ b/module/Core/src/Model/VisitsParams.php @@ -14,20 +14,16 @@ final class VisitsParams private const ALL_ITEMS = -1; private ?DateRange $dateRange; - private int $page; private int $itemsPerPage; - private bool $excludeBots; public function __construct( ?DateRange $dateRange = null, - int $page = self::FIRST_PAGE, + private int $page = self::FIRST_PAGE, ?int $itemsPerPage = null, - bool $excludeBots = false + private bool $excludeBots = false ) { $this->dateRange = $dateRange ?? new DateRange(); - $this->page = $page; $this->itemsPerPage = $this->determineItemsPerPage($itemsPerPage); - $this->excludeBots = $excludeBots; } private function determineItemsPerPage(?int $itemsPerPage): int diff --git a/module/Core/src/Paginator/Adapter/OrphanVisitsPaginatorAdapter.php b/module/Core/src/Paginator/Adapter/OrphanVisitsPaginatorAdapter.php index d7361fb3..18c2c435 100644 --- a/module/Core/src/Paginator/Adapter/OrphanVisitsPaginatorAdapter.php +++ b/module/Core/src/Paginator/Adapter/OrphanVisitsPaginatorAdapter.php @@ -11,13 +11,8 @@ use Shlinkio\Shlink\Core\Visit\Persistence\VisitsListFiltering; class OrphanVisitsPaginatorAdapter extends AbstractCacheableCountPaginatorAdapter { - private VisitRepositoryInterface $repo; - private VisitsParams $params; - - public function __construct(VisitRepositoryInterface $repo, VisitsParams $params) + public function __construct(private VisitRepositoryInterface $repo, private VisitsParams $params) { - $this->repo = $repo; - $this->params = $params; } protected function doCount(): int diff --git a/module/Core/src/Paginator/Adapter/ShortUrlRepositoryAdapter.php b/module/Core/src/Paginator/Adapter/ShortUrlRepositoryAdapter.php index 093bd8fd..a0d4305f 100644 --- a/module/Core/src/Paginator/Adapter/ShortUrlRepositoryAdapter.php +++ b/module/Core/src/Paginator/Adapter/ShortUrlRepositoryAdapter.php @@ -12,15 +12,11 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class ShortUrlRepositoryAdapter implements AdapterInterface { - private ShortUrlRepositoryInterface $repository; - private ShortUrlsParams $params; - private ?ApiKey $apiKey; - - public function __construct(ShortUrlRepositoryInterface $repository, ShortUrlsParams $params, ?ApiKey $apiKey) - { - $this->repository = $repository; - $this->params = $params; - $this->apiKey = $apiKey; + public function __construct( + private ShortUrlRepositoryInterface $repository, + private ShortUrlsParams $params, + private ?ApiKey $apiKey + ) { } public function getSlice($offset, $length): array // phpcs:ignore diff --git a/module/Core/src/Paginator/Adapter/VisitsForTagPaginatorAdapter.php b/module/Core/src/Paginator/Adapter/VisitsForTagPaginatorAdapter.php index d7c0580f..2dfdc618 100644 --- a/module/Core/src/Paginator/Adapter/VisitsForTagPaginatorAdapter.php +++ b/module/Core/src/Paginator/Adapter/VisitsForTagPaginatorAdapter.php @@ -13,21 +13,12 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class VisitsForTagPaginatorAdapter extends AbstractCacheableCountPaginatorAdapter { - private VisitRepositoryInterface $visitRepository; - private string $tag; - private VisitsParams $params; - private ?ApiKey $apiKey; - public function __construct( - VisitRepositoryInterface $visitRepository, - string $tag, - VisitsParams $params, - ?ApiKey $apiKey + private VisitRepositoryInterface $visitRepository, + private string $tag, + private VisitsParams $params, + private ?ApiKey $apiKey ) { - $this->visitRepository = $visitRepository; - $this->params = $params; - $this->tag = $tag; - $this->apiKey = $apiKey; } public function getSlice($offset, $length): array // phpcs:ignore diff --git a/module/Core/src/Paginator/Adapter/VisitsPaginatorAdapter.php b/module/Core/src/Paginator/Adapter/VisitsPaginatorAdapter.php index d651b1b5..fa6833f8 100644 --- a/module/Core/src/Paginator/Adapter/VisitsPaginatorAdapter.php +++ b/module/Core/src/Paginator/Adapter/VisitsPaginatorAdapter.php @@ -13,21 +13,12 @@ use Shlinkio\Shlink\Core\Visit\Persistence\VisitsListFiltering; class VisitsPaginatorAdapter extends AbstractCacheableCountPaginatorAdapter { - private VisitRepositoryInterface $visitRepository; - private ShortUrlIdentifier $identifier; - private VisitsParams $params; - private ?Specification $spec; - public function __construct( - VisitRepositoryInterface $visitRepository, - ShortUrlIdentifier $identifier, - VisitsParams $params, - ?Specification $spec + private VisitRepositoryInterface $visitRepository, + private ShortUrlIdentifier $identifier, + private VisitsParams $params, + private ?Specification $spec ) { - $this->visitRepository = $visitRepository; - $this->params = $params; - $this->identifier = $identifier; - $this->spec = $spec; } public function getSlice($offset, $length): array // phpcs:ignore diff --git a/module/Core/src/Service/ShortUrl/DeleteShortUrlService.php b/module/Core/src/Service/ShortUrl/DeleteShortUrlService.php index 07af448d..53d0db61 100644 --- a/module/Core/src/Service/ShortUrl/DeleteShortUrlService.php +++ b/module/Core/src/Service/ShortUrl/DeleteShortUrlService.php @@ -13,18 +13,11 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class DeleteShortUrlService implements DeleteShortUrlServiceInterface { - private EntityManagerInterface $em; - private DeleteShortUrlsOptions $deleteShortUrlsOptions; - private ShortUrlResolverInterface $urlResolver; - public function __construct( - EntityManagerInterface $em, - DeleteShortUrlsOptions $deleteShortUrlsOptions, - ShortUrlResolverInterface $urlResolver + private EntityManagerInterface $em, + private DeleteShortUrlsOptions $deleteShortUrlsOptions, + private ShortUrlResolverInterface $urlResolver ) { - $this->em = $em; - $this->deleteShortUrlsOptions = $deleteShortUrlsOptions; - $this->urlResolver = $urlResolver; } /** diff --git a/module/Core/src/Service/ShortUrl/ShortCodeHelper.php b/module/Core/src/Service/ShortUrl/ShortCodeHelper.php index 83c3397e..5bb992c5 100644 --- a/module/Core/src/Service/ShortUrl/ShortCodeHelper.php +++ b/module/Core/src/Service/ShortUrl/ShortCodeHelper.php @@ -11,11 +11,8 @@ use Shlinkio\Shlink\Core\Repository\ShortUrlRepository; class ShortCodeHelper implements ShortCodeHelperInterface // TODO Rename to ShortCodeUniquenessHelper { - private EntityManagerInterface $em; - - public function __construct(EntityManagerInterface $em) + public function __construct(private EntityManagerInterface $em) { - $this->em = $em; } public function ensureShortCodeUniqueness(ShortUrl $shortUrlToBeCreated, bool $hasCustomSlug): bool diff --git a/module/Core/src/Service/ShortUrl/ShortUrlResolver.php b/module/Core/src/Service/ShortUrl/ShortUrlResolver.php index 1394e1ab..09cd2005 100644 --- a/module/Core/src/Service/ShortUrl/ShortUrlResolver.php +++ b/module/Core/src/Service/ShortUrl/ShortUrlResolver.php @@ -13,11 +13,8 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class ShortUrlResolver implements ShortUrlResolverInterface { - private EntityManagerInterface $em; - - public function __construct(EntityManagerInterface $em) + public function __construct(private EntityManagerInterface $em) { - $this->em = $em; } /** diff --git a/module/Core/src/Service/ShortUrlService.php b/module/Core/src/Service/ShortUrlService.php index dcb1d8cc..f8a144cc 100644 --- a/module/Core/src/Service/ShortUrlService.php +++ b/module/Core/src/Service/ShortUrlService.php @@ -21,21 +21,12 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class ShortUrlService implements ShortUrlServiceInterface { - private ORM\EntityManagerInterface $em; - private ShortUrlResolverInterface $urlResolver; - private ShortUrlTitleResolutionHelperInterface $titleResolutionHelper; - private ShortUrlRelationResolverInterface $relationResolver; - public function __construct( - ORM\EntityManagerInterface $em, - ShortUrlResolverInterface $urlResolver, - ShortUrlTitleResolutionHelperInterface $titleResolutionHelper, - ShortUrlRelationResolverInterface $relationResolver + private ORM\EntityManagerInterface $em, + private ShortUrlResolverInterface $urlResolver, + private ShortUrlTitleResolutionHelperInterface $titleResolutionHelper, + private ShortUrlRelationResolverInterface $relationResolver ) { - $this->em = $em; - $this->urlResolver = $urlResolver; - $this->titleResolutionHelper = $titleResolutionHelper; - $this->relationResolver = $relationResolver; } /** diff --git a/module/Core/src/Service/UrlShortener.php b/module/Core/src/Service/UrlShortener.php index 78064259..ff2b5f62 100644 --- a/module/Core/src/Service/UrlShortener.php +++ b/module/Core/src/Service/UrlShortener.php @@ -16,21 +16,12 @@ use Shlinkio\Shlink\Core\ShortUrl\Resolver\ShortUrlRelationResolverInterface; class UrlShortener implements UrlShortenerInterface { - private EntityManagerInterface $em; - private ShortUrlTitleResolutionHelperInterface $titleResolutionHelper; - private ShortUrlRelationResolverInterface $relationResolver; - private ShortCodeHelperInterface $shortCodeHelper; - public function __construct( - ShortUrlTitleResolutionHelperInterface $titleResolutionHelper, - EntityManagerInterface $em, - ShortUrlRelationResolverInterface $relationResolver, - ShortCodeHelperInterface $shortCodeHelper + private ShortUrlTitleResolutionHelperInterface $titleResolutionHelper, + private EntityManagerInterface $em, + private ShortUrlRelationResolverInterface $relationResolver, + private ShortCodeHelperInterface $shortCodeHelper ) { - $this->titleResolutionHelper = $titleResolutionHelper; - $this->em = $em; - $this->relationResolver = $relationResolver; - $this->shortCodeHelper = $shortCodeHelper; } /** diff --git a/module/Core/src/ShortUrl/Helper/ShortUrlStringifier.php b/module/Core/src/ShortUrl/Helper/ShortUrlStringifier.php index 4d34e26b..1ec36677 100644 --- a/module/Core/src/ShortUrl/Helper/ShortUrlStringifier.php +++ b/module/Core/src/ShortUrl/Helper/ShortUrlStringifier.php @@ -11,13 +11,8 @@ use function sprintf; class ShortUrlStringifier implements ShortUrlStringifierInterface { - private array $domainConfig; - private string $basePath; - - public function __construct(array $domainConfig, string $basePath = '') + public function __construct(private array $domainConfig, private string $basePath = '') { - $this->domainConfig = $domainConfig; - $this->basePath = $basePath; } public function stringify(ShortUrl $shortUrl): string diff --git a/module/Core/src/ShortUrl/Helper/ShortUrlTitleResolutionHelper.php b/module/Core/src/ShortUrl/Helper/ShortUrlTitleResolutionHelper.php index 4615e45f..00eecc61 100644 --- a/module/Core/src/ShortUrl/Helper/ShortUrlTitleResolutionHelper.php +++ b/module/Core/src/ShortUrl/Helper/ShortUrlTitleResolutionHelper.php @@ -8,11 +8,8 @@ use Shlinkio\Shlink\Core\Util\UrlValidatorInterface; class ShortUrlTitleResolutionHelper implements ShortUrlTitleResolutionHelperInterface { - private UrlValidatorInterface $urlValidator; - - public function __construct(UrlValidatorInterface $urlValidator) + public function __construct(private UrlValidatorInterface $urlValidator) { - $this->urlValidator = $urlValidator; } public function processTitleAndValidateUrl(TitleResolutionModelInterface $data): TitleResolutionModelInterface diff --git a/module/Core/src/ShortUrl/Resolver/PersistenceShortUrlRelationResolver.php b/module/Core/src/ShortUrl/Resolver/PersistenceShortUrlRelationResolver.php index 8601a045..a9456712 100644 --- a/module/Core/src/ShortUrl/Resolver/PersistenceShortUrlRelationResolver.php +++ b/module/Core/src/ShortUrl/Resolver/PersistenceShortUrlRelationResolver.php @@ -16,16 +16,13 @@ use function Functional\unique; class PersistenceShortUrlRelationResolver implements ShortUrlRelationResolverInterface { - private EntityManagerInterface $em; - /** @var array */ private array $memoizedNewDomains = []; /** @var array */ private array $memoizedNewTags = []; - public function __construct(EntityManagerInterface $em) + public function __construct(private EntityManagerInterface $em) { - $this->em = $em; $this->em->getEventManager()->addEventListener(Events::postFlush, $this); } diff --git a/module/Core/src/ShortUrl/Spec/BelongsToApiKey.php b/module/Core/src/ShortUrl/Spec/BelongsToApiKey.php index 4aa3579f..84852275 100644 --- a/module/Core/src/ShortUrl/Spec/BelongsToApiKey.php +++ b/module/Core/src/ShortUrl/Spec/BelongsToApiKey.php @@ -11,13 +11,8 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class BelongsToApiKey extends BaseSpecification { - private ApiKey $apiKey; - private ?string $dqlAlias; - - public function __construct(ApiKey $apiKey, ?string $dqlAlias = null) + public function __construct(private ApiKey $apiKey, private ?string $dqlAlias = null) { - $this->apiKey = $apiKey; - $this->dqlAlias = $dqlAlias; parent::__construct(); } diff --git a/module/Core/src/ShortUrl/Spec/BelongsToApiKeyInlined.php b/module/Core/src/ShortUrl/Spec/BelongsToApiKeyInlined.php index 579407cd..6b103058 100644 --- a/module/Core/src/ShortUrl/Spec/BelongsToApiKeyInlined.php +++ b/module/Core/src/ShortUrl/Spec/BelongsToApiKeyInlined.php @@ -10,11 +10,8 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class BelongsToApiKeyInlined implements Filter { - private ApiKey $apiKey; - - public function __construct(ApiKey $apiKey) + public function __construct(private ApiKey $apiKey) { - $this->apiKey = $apiKey; } public function getFilter(QueryBuilder $qb, string $dqlAlias): string diff --git a/module/Core/src/ShortUrl/Spec/BelongsToDomain.php b/module/Core/src/ShortUrl/Spec/BelongsToDomain.php index 7745ff27..33eacec8 100644 --- a/module/Core/src/ShortUrl/Spec/BelongsToDomain.php +++ b/module/Core/src/ShortUrl/Spec/BelongsToDomain.php @@ -10,13 +10,8 @@ use Happyr\DoctrineSpecification\Specification\BaseSpecification; class BelongsToDomain extends BaseSpecification { - private string $domainId; - private ?string $dqlAlias; - - public function __construct(string $domainId, ?string $dqlAlias = null) + public function __construct(private string $domainId, private ?string $dqlAlias = null) { - $this->domainId = $domainId; - $this->dqlAlias = $dqlAlias; parent::__construct(); } diff --git a/module/Core/src/ShortUrl/Spec/BelongsToDomainInlined.php b/module/Core/src/ShortUrl/Spec/BelongsToDomainInlined.php index cb69a359..414b3f74 100644 --- a/module/Core/src/ShortUrl/Spec/BelongsToDomainInlined.php +++ b/module/Core/src/ShortUrl/Spec/BelongsToDomainInlined.php @@ -9,11 +9,8 @@ use Happyr\DoctrineSpecification\Filter\Filter; class BelongsToDomainInlined implements Filter { - private string $domainId; - - public function __construct(string $domainId) + public function __construct(private string $domainId) { - $this->domainId = $domainId; } public function getFilter(QueryBuilder $qb, string $dqlAlias): string diff --git a/module/Core/src/ShortUrl/Transformer/ShortUrlDataTransformer.php b/module/Core/src/ShortUrl/Transformer/ShortUrlDataTransformer.php index 52b98c36..61049626 100644 --- a/module/Core/src/ShortUrl/Transformer/ShortUrlDataTransformer.php +++ b/module/Core/src/ShortUrl/Transformer/ShortUrlDataTransformer.php @@ -13,11 +13,8 @@ use function Functional\invoke_if; class ShortUrlDataTransformer implements DataTransformerInterface { - private ShortUrlStringifierInterface $stringifier; - - public function __construct(ShortUrlStringifierInterface $stringifier) + public function __construct(private ShortUrlStringifierInterface $stringifier) { - $this->stringifier = $stringifier; } /** diff --git a/module/Core/src/Spec/InDateRange.php b/module/Core/src/Spec/InDateRange.php index 953ed9f2..7ddcf0a4 100644 --- a/module/Core/src/Spec/InDateRange.php +++ b/module/Core/src/Spec/InDateRange.php @@ -11,14 +11,9 @@ use Shlinkio\Shlink\Common\Util\DateRange; class InDateRange extends BaseSpecification { - private ?DateRange $dateRange; - private string $field; - - public function __construct(?DateRange $dateRange, string $field = 'date') + public function __construct(private ?DateRange $dateRange, private string $field = 'date') { parent::__construct(); - $this->dateRange = $dateRange; - $this->field = $field; } protected function getSpec(): Specification diff --git a/module/Core/src/Tag/Model/TagInfo.php b/module/Core/src/Tag/Model/TagInfo.php index dbc51316..1a436cd4 100644 --- a/module/Core/src/Tag/Model/TagInfo.php +++ b/module/Core/src/Tag/Model/TagInfo.php @@ -9,15 +9,8 @@ use Shlinkio\Shlink\Core\Entity\Tag; final class TagInfo implements JsonSerializable { - private Tag $tag; - private int $shortUrlsCount; - private int $visitsCount; - - public function __construct(Tag $tag, int $shortUrlsCount, int $visitsCount) + public function __construct(private Tag $tag, private int $shortUrlsCount, private int $visitsCount) { - $this->tag = $tag; - $this->shortUrlsCount = $shortUrlsCount; - $this->visitsCount = $visitsCount; } public function tag(): Tag diff --git a/module/Core/src/Tag/Spec/CountTagsWithName.php b/module/Core/src/Tag/Spec/CountTagsWithName.php index 8dd3e44d..021507d1 100644 --- a/module/Core/src/Tag/Spec/CountTagsWithName.php +++ b/module/Core/src/Tag/Spec/CountTagsWithName.php @@ -10,12 +10,9 @@ use Happyr\DoctrineSpecification\Specification\Specification; class CountTagsWithName extends BaseSpecification { - private string $tagName; - - public function __construct(string $tagName) + public function __construct(private string $tagName) { parent::__construct(); - $this->tagName = $tagName; } protected function getSpec(): Specification diff --git a/module/Core/src/Tag/TagService.php b/module/Core/src/Tag/TagService.php index 4619bd9d..61ed211d 100644 --- a/module/Core/src/Tag/TagService.php +++ b/module/Core/src/Tag/TagService.php @@ -23,11 +23,8 @@ class TagService implements TagServiceInterface { use TagManagerTrait; - private ORM\EntityManagerInterface $em; - - public function __construct(ORM\EntityManagerInterface $em) + public function __construct(private ORM\EntityManagerInterface $em) { - $this->em = $em; } /** diff --git a/module/Core/src/Util/CocurSymfonySluggerBridge.php b/module/Core/src/Util/CocurSymfonySluggerBridge.php index 9415e47c..a612068c 100644 --- a/module/Core/src/Util/CocurSymfonySluggerBridge.php +++ b/module/Core/src/Util/CocurSymfonySluggerBridge.php @@ -12,11 +12,8 @@ use function Symfony\Component\String\s; class CocurSymfonySluggerBridge implements SluggerInterface { - private SlugifyInterface $slugger; - - public function __construct(SlugifyInterface $slugger) + public function __construct(private SlugifyInterface $slugger) { - $this->slugger = $slugger; } public function slug(string $string, string $separator = '-', ?string $locale = null): AbstractUnicodeString diff --git a/module/Core/src/Util/DoctrineBatchHelper.php b/module/Core/src/Util/DoctrineBatchHelper.php index 207d2093..5591ddb2 100644 --- a/module/Core/src/Util/DoctrineBatchHelper.php +++ b/module/Core/src/Util/DoctrineBatchHelper.php @@ -12,11 +12,8 @@ use Throwable; */ class DoctrineBatchHelper implements DoctrineBatchHelperInterface { - private EntityManagerInterface $em; - - public function __construct(EntityManagerInterface $em) + public function __construct(private EntityManagerInterface $em) { - $this->em = $em; } /** diff --git a/module/Core/src/Util/RedirectResponseHelper.php b/module/Core/src/Util/RedirectResponseHelper.php index 58f6e145..5f9edf99 100644 --- a/module/Core/src/Util/RedirectResponseHelper.php +++ b/module/Core/src/Util/RedirectResponseHelper.php @@ -13,11 +13,8 @@ use function sprintf; class RedirectResponseHelper implements RedirectResponseHelperInterface { - private UrlShortenerOptions $options; - - public function __construct(UrlShortenerOptions $options) + public function __construct(private UrlShortenerOptions $options) { - $this->options = $options; } public function buildRedirectResponse(string $location): ResponseInterface diff --git a/module/Core/src/Util/UrlValidator.php b/module/Core/src/Util/UrlValidator.php index 23de39ef..0756f55e 100644 --- a/module/Core/src/Util/UrlValidator.php +++ b/module/Core/src/Util/UrlValidator.php @@ -23,13 +23,8 @@ class UrlValidator implements UrlValidatorInterface, RequestMethodInterface private const CHROME_USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) ' . 'Chrome/51.0.2704.103 Safari/537.36'; - private ClientInterface $httpClient; - private UrlShortenerOptions $options; - - public function __construct(ClientInterface $httpClient, UrlShortenerOptions $options) + public function __construct(private ClientInterface $httpClient, private UrlShortenerOptions $options) { - $this->httpClient = $httpClient; - $this->options = $options; } /** diff --git a/module/Core/src/Visit/Model/VisitsStats.php b/module/Core/src/Visit/Model/VisitsStats.php index 982f03c4..475a25b5 100644 --- a/module/Core/src/Visit/Model/VisitsStats.php +++ b/module/Core/src/Visit/Model/VisitsStats.php @@ -8,13 +8,8 @@ use JsonSerializable; final class VisitsStats implements JsonSerializable { - private int $visitsCount; - private int $orphanVisitsCount; - - public function __construct(int $visitsCount, int $orphanVisitsCount) + public function __construct(private int $visitsCount, private int $orphanVisitsCount) { - $this->visitsCount = $visitsCount; - $this->orphanVisitsCount = $orphanVisitsCount; } public function jsonSerialize(): array diff --git a/module/Core/src/Visit/Persistence/VisitsCountFiltering.php b/module/Core/src/Visit/Persistence/VisitsCountFiltering.php index bc9ac5de..9f48275f 100644 --- a/module/Core/src/Visit/Persistence/VisitsCountFiltering.php +++ b/module/Core/src/Visit/Persistence/VisitsCountFiltering.php @@ -9,15 +9,11 @@ use Shlinkio\Shlink\Common\Util\DateRange; class VisitsCountFiltering { - private ?DateRange $dateRange; - private bool $excludeBots; - private ?Specification $spec; - - public function __construct(?DateRange $dateRange = null, bool $excludeBots = false, ?Specification $spec = null) - { - $this->dateRange = $dateRange; - $this->excludeBots = $excludeBots; - $this->spec = $spec; + public function __construct( + private ?DateRange $dateRange = null, + private bool $excludeBots = false, + private ?Specification $spec = null + ) { } public function dateRange(): ?DateRange diff --git a/module/Core/src/Visit/Persistence/VisitsListFiltering.php b/module/Core/src/Visit/Persistence/VisitsListFiltering.php index 4f67967d..173e308e 100644 --- a/module/Core/src/Visit/Persistence/VisitsListFiltering.php +++ b/module/Core/src/Visit/Persistence/VisitsListFiltering.php @@ -9,19 +9,14 @@ use Shlinkio\Shlink\Common\Util\DateRange; final class VisitsListFiltering extends VisitsCountFiltering { - private ?int $limit; - private ?int $offset; - public function __construct( ?DateRange $dateRange = null, bool $excludeBots = false, ?Specification $spec = null, - ?int $limit = null, - ?int $offset = null + private ?int $limit = null, + private ?int $offset = null ) { parent::__construct($dateRange, $excludeBots, $spec); - $this->limit = $limit; - $this->offset = $offset; } public function limit(): ?int diff --git a/module/Core/src/Visit/Spec/CountOfOrphanVisits.php b/module/Core/src/Visit/Spec/CountOfOrphanVisits.php index b2cc9efd..d8e6b2d2 100644 --- a/module/Core/src/Visit/Spec/CountOfOrphanVisits.php +++ b/module/Core/src/Visit/Spec/CountOfOrphanVisits.php @@ -12,12 +12,9 @@ use Shlinkio\Shlink\Core\Visit\Persistence\VisitsCountFiltering; class CountOfOrphanVisits extends BaseSpecification { - private VisitsCountFiltering $filtering; - - public function __construct(VisitsCountFiltering $filtering) + public function __construct(private VisitsCountFiltering $filtering) { parent::__construct(); - $this->filtering = $filtering; } protected function getSpec(): Specification diff --git a/module/Core/src/Visit/Spec/CountOfShortUrlVisits.php b/module/Core/src/Visit/Spec/CountOfShortUrlVisits.php index ea4a4800..49d8db93 100644 --- a/module/Core/src/Visit/Spec/CountOfShortUrlVisits.php +++ b/module/Core/src/Visit/Spec/CountOfShortUrlVisits.php @@ -12,12 +12,9 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class CountOfShortUrlVisits extends BaseSpecification { - private ?ApiKey $apiKey; - - public function __construct(?ApiKey $apiKey) + public function __construct(private ?ApiKey $apiKey) { parent::__construct(); - $this->apiKey = $apiKey; } protected function getSpec(): Specification diff --git a/module/Core/src/Visit/VisitLocator.php b/module/Core/src/Visit/VisitLocator.php index d7f0e426..e9d0a8f9 100644 --- a/module/Core/src/Visit/VisitLocator.php +++ b/module/Core/src/Visit/VisitLocator.php @@ -13,13 +13,10 @@ use Shlinkio\Shlink\IpGeolocation\Model\Location; class VisitLocator implements VisitLocatorInterface { - private EntityManagerInterface $em; private VisitRepositoryInterface $repo; - public function __construct(EntityManagerInterface $em) + public function __construct(private EntityManagerInterface $em) { - $this->em = $em; - /** @var VisitRepositoryInterface $repo */ $repo = $em->getRepository(Visit::class); $this->repo = $repo; diff --git a/module/Core/src/Visit/VisitsStatsHelper.php b/module/Core/src/Visit/VisitsStatsHelper.php index dfa00a4c..06f990f6 100644 --- a/module/Core/src/Visit/VisitsStatsHelper.php +++ b/module/Core/src/Visit/VisitsStatsHelper.php @@ -27,11 +27,8 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class VisitsStatsHelper implements VisitsStatsHelperInterface { - private EntityManagerInterface $em; - - public function __construct(EntityManagerInterface $em) + public function __construct(private EntityManagerInterface $em) { - $this->em = $em; } public function getVisitsStats(?ApiKey $apiKey = null): VisitsStats diff --git a/module/Core/src/Visit/VisitsTracker.php b/module/Core/src/Visit/VisitsTracker.php index f77cd624..523454fc 100644 --- a/module/Core/src/Visit/VisitsTracker.php +++ b/module/Core/src/Visit/VisitsTracker.php @@ -14,18 +14,11 @@ use Shlinkio\Shlink\Core\Options\TrackingOptions; class VisitsTracker implements VisitsTrackerInterface { - private ORM\EntityManagerInterface $em; - private EventDispatcherInterface $eventDispatcher; - private TrackingOptions $options; - public function __construct( - ORM\EntityManagerInterface $em, - EventDispatcherInterface $eventDispatcher, - TrackingOptions $options + private ORM\EntityManagerInterface $em, + private EventDispatcherInterface $eventDispatcher, + private TrackingOptions $options ) { - $this->em = $em; - $this->eventDispatcher = $eventDispatcher; - $this->options = $options; } public function track(ShortUrl $shortUrl, Visitor $visitor): void diff --git a/module/Core/test-db/Domain/Repository/DomainRepositoryTest.php b/module/Core/test-db/Domain/Repository/DomainRepositoryTest.php index aaa63d9f..0f5aa259 100644 --- a/module/Core/test-db/Domain/Repository/DomainRepositoryTest.php +++ b/module/Core/test-db/Domain/Repository/DomainRepositoryTest.php @@ -94,11 +94,8 @@ class DomainRepositoryTest extends DatabaseTestCase return ShortUrl::fromMeta( ShortUrlMeta::fromRawData(['domain' => $domain->getAuthority(), 'apiKey' => $apiKey, 'longUrl' => 'foo']), new class ($domain) implements ShortUrlRelationResolverInterface { - private Domain $domain; - - public function __construct(Domain $domain) + public function __construct(private Domain $domain) { - $this->domain = $domain; } public function resolveDomain(?string $domain): ?Domain diff --git a/module/Core/test/Visit/VisitLocatorTest.php b/module/Core/test/Visit/VisitLocatorTest.php index c99d051b..11e7062f 100644 --- a/module/Core/test/Visit/VisitLocatorTest.php +++ b/module/Core/test/Visit/VisitLocatorTest.php @@ -122,11 +122,8 @@ class VisitLocatorTest extends TestCase $this->visitService->{$serviceMethodName}( new class ($isNonLocatableAddress) implements VisitGeolocationHelperInterface { - private bool $isNonLocatableAddress; - - public function __construct(bool $isNonLocatableAddress) + public function __construct(private bool $isNonLocatableAddress) { - $this->isNonLocatableAddress = $isNonLocatableAddress; } public function geolocateVisit(Visit $visit): Location diff --git a/module/Rest/src/Action/Domain/ListDomainsAction.php b/module/Rest/src/Action/Domain/ListDomainsAction.php index 35ce04f3..c8f9a475 100644 --- a/module/Rest/src/Action/Domain/ListDomainsAction.php +++ b/module/Rest/src/Action/Domain/ListDomainsAction.php @@ -16,11 +16,8 @@ class ListDomainsAction extends AbstractRestAction protected const ROUTE_PATH = '/domains'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; - private DomainServiceInterface $domainService; - - public function __construct(DomainServiceInterface $domainService) + public function __construct(private DomainServiceInterface $domainService) { - $this->domainService = $domainService; } public function handle(ServerRequestInterface $request): ResponseInterface diff --git a/module/Rest/src/Action/HealthAction.php b/module/Rest/src/Action/HealthAction.php index ef89da64..5f9d052c 100644 --- a/module/Rest/src/Action/HealthAction.php +++ b/module/Rest/src/Action/HealthAction.php @@ -20,13 +20,8 @@ class HealthAction extends AbstractRestAction protected const ROUTE_PATH = '/health'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; - private EntityManagerInterface $em; - private AppOptions $options; - - public function __construct(EntityManagerInterface $em, AppOptions $options) + public function __construct(private EntityManagerInterface $em, private AppOptions $options) { - $this->em = $em; - $this->options = $options; } /** @@ -38,7 +33,7 @@ class HealthAction extends AbstractRestAction { try { $connected = $this->em->getConnection()->ping(); - } catch (Throwable $e) { + } catch (Throwable) { $connected = false; } diff --git a/module/Rest/src/Action/MercureInfoAction.php b/module/Rest/src/Action/MercureInfoAction.php index 75893ab9..d6710357 100644 --- a/module/Rest/src/Action/MercureInfoAction.php +++ b/module/Rest/src/Action/MercureInfoAction.php @@ -19,13 +19,8 @@ class MercureInfoAction extends AbstractRestAction protected const ROUTE_PATH = '/mercure-info'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; - private JwtProviderInterface $jwtProvider; - private array $mercureConfig; - - public function __construct(JwtProviderInterface $jwtProvider, array $mercureConfig) + public function __construct(private JwtProviderInterface $jwtProvider, private array $mercureConfig) { - $this->jwtProvider = $jwtProvider; - $this->mercureConfig = $mercureConfig; } public function handle(ServerRequestInterface $request): ResponseInterface diff --git a/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php b/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php index 587c4bc5..90616dc5 100644 --- a/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php @@ -15,13 +15,10 @@ use Shlinkio\Shlink\Rest\Action\AbstractRestAction; abstract class AbstractCreateShortUrlAction extends AbstractRestAction { - private UrlShortenerInterface $urlShortener; - private DataTransformerInterface $transformer; - - public function __construct(UrlShortenerInterface $urlShortener, DataTransformerInterface $transformer) - { - $this->urlShortener = $urlShortener; - $this->transformer = $transformer; + public function __construct( + private UrlShortenerInterface $urlShortener, + private DataTransformerInterface $transformer, + ) { } public function handle(Request $request): Response diff --git a/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php b/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php index 73eaa6ee..8059e5ab 100644 --- a/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php @@ -17,11 +17,8 @@ class DeleteShortUrlAction extends AbstractRestAction protected const ROUTE_PATH = '/short-urls/{shortCode}'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_DELETE]; - private DeleteShortUrlServiceInterface $deleteShortUrlService; - - public function __construct(DeleteShortUrlServiceInterface $deleteShortUrlService) + public function __construct(private DeleteShortUrlServiceInterface $deleteShortUrlService) { - $this->deleteShortUrlService = $deleteShortUrlService; } public function handle(ServerRequestInterface $request): ResponseInterface diff --git a/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php b/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php index 49187314..87c21aec 100644 --- a/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php @@ -19,13 +19,10 @@ class EditShortUrlAction extends AbstractRestAction protected const ROUTE_PATH = '/short-urls/{shortCode}'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_PATCH, self::METHOD_PUT]; - private ShortUrlServiceInterface $shortUrlService; - private DataTransformerInterface $transformer; - - public function __construct(ShortUrlServiceInterface $shortUrlService, DataTransformerInterface $transformer) - { - $this->shortUrlService = $shortUrlService; - $this->transformer = $transformer; + public function __construct( + private ShortUrlServiceInterface $shortUrlService, + private DataTransformerInterface $transformer, + ) { } public function handle(ServerRequestInterface $request): ResponseInterface diff --git a/module/Rest/src/Action/ShortUrl/EditShortUrlTagsAction.php b/module/Rest/src/Action/ShortUrl/EditShortUrlTagsAction.php index d114049c..d3211d1c 100644 --- a/module/Rest/src/Action/ShortUrl/EditShortUrlTagsAction.php +++ b/module/Rest/src/Action/ShortUrl/EditShortUrlTagsAction.php @@ -21,11 +21,8 @@ class EditShortUrlTagsAction extends AbstractRestAction protected const ROUTE_PATH = '/short-urls/{shortCode}/tags'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_PUT]; - private ShortUrlServiceInterface $shortUrlService; - - public function __construct(ShortUrlServiceInterface $shortUrlService) + public function __construct(private ShortUrlServiceInterface $shortUrlService) { - $this->shortUrlService = $shortUrlService; } public function handle(Request $request): Response diff --git a/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php b/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php index ee077790..075b56e1 100644 --- a/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php +++ b/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php @@ -21,13 +21,10 @@ class ListShortUrlsAction extends AbstractRestAction protected const ROUTE_PATH = '/short-urls'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; - private ShortUrlServiceInterface $shortUrlService; - private DataTransformerInterface $transformer; - - public function __construct(ShortUrlServiceInterface $shortUrlService, DataTransformerInterface $transformer) - { - $this->shortUrlService = $shortUrlService; - $this->transformer = $transformer; + public function __construct( + private ShortUrlServiceInterface $shortUrlService, + private DataTransformerInterface $transformer + ) { } public function handle(Request $request): Response diff --git a/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php b/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php index c14423ce..aae1a895 100644 --- a/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php @@ -18,13 +18,10 @@ class ResolveShortUrlAction extends AbstractRestAction protected const ROUTE_PATH = '/short-urls/{shortCode}'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; - private ShortUrlResolverInterface $urlResolver; - private DataTransformerInterface $transformer; - - public function __construct(ShortUrlResolverInterface $urlResolver, DataTransformerInterface $transformer) - { - $this->urlResolver = $urlResolver; - $this->transformer = $transformer; + public function __construct( + private ShortUrlResolverInterface $urlResolver, + private DataTransformerInterface $transformer, + ) { } public function handle(Request $request): Response diff --git a/module/Rest/src/Action/Tag/CreateTagsAction.php b/module/Rest/src/Action/Tag/CreateTagsAction.php index 8aaf907b..e3d0bb9f 100644 --- a/module/Rest/src/Action/Tag/CreateTagsAction.php +++ b/module/Rest/src/Action/Tag/CreateTagsAction.php @@ -16,11 +16,8 @@ class CreateTagsAction extends AbstractRestAction protected const ROUTE_PATH = '/tags'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_POST]; - private TagServiceInterface $tagService; - - public function __construct(TagServiceInterface $tagService) + public function __construct(private TagServiceInterface $tagService) { - $this->tagService = $tagService; } /** diff --git a/module/Rest/src/Action/Tag/DeleteTagsAction.php b/module/Rest/src/Action/Tag/DeleteTagsAction.php index b1be8af5..48e7acd9 100644 --- a/module/Rest/src/Action/Tag/DeleteTagsAction.php +++ b/module/Rest/src/Action/Tag/DeleteTagsAction.php @@ -16,11 +16,8 @@ class DeleteTagsAction extends AbstractRestAction protected const ROUTE_PATH = '/tags'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_DELETE]; - private TagServiceInterface $tagService; - - public function __construct(TagServiceInterface $tagService) + public function __construct(private TagServiceInterface $tagService) { - $this->tagService = $tagService; } public function handle(ServerRequestInterface $request): ResponseInterface diff --git a/module/Rest/src/Action/Tag/ListTagsAction.php b/module/Rest/src/Action/Tag/ListTagsAction.php index 48cf923b..89371b71 100644 --- a/module/Rest/src/Action/Tag/ListTagsAction.php +++ b/module/Rest/src/Action/Tag/ListTagsAction.php @@ -19,11 +19,8 @@ class ListTagsAction extends AbstractRestAction protected const ROUTE_PATH = '/tags'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; - private TagServiceInterface $tagService; - - public function __construct(TagServiceInterface $tagService) + public function __construct(private TagServiceInterface $tagService) { - $this->tagService = $tagService; } public function handle(ServerRequestInterface $request): ResponseInterface diff --git a/module/Rest/src/Action/Tag/UpdateTagAction.php b/module/Rest/src/Action/Tag/UpdateTagAction.php index d83d8b9a..a4bce7c0 100644 --- a/module/Rest/src/Action/Tag/UpdateTagAction.php +++ b/module/Rest/src/Action/Tag/UpdateTagAction.php @@ -17,11 +17,8 @@ class UpdateTagAction extends AbstractRestAction protected const ROUTE_PATH = '/tags'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_PUT]; - private TagServiceInterface $tagService; - - public function __construct(TagServiceInterface $tagService) + public function __construct(private TagServiceInterface $tagService) { - $this->tagService = $tagService; } public function handle(ServerRequestInterface $request): ResponseInterface diff --git a/module/Rest/src/Action/Visit/GlobalVisitsAction.php b/module/Rest/src/Action/Visit/GlobalVisitsAction.php index 4810b100..1f2e1211 100644 --- a/module/Rest/src/Action/Visit/GlobalVisitsAction.php +++ b/module/Rest/src/Action/Visit/GlobalVisitsAction.php @@ -16,11 +16,8 @@ class GlobalVisitsAction extends AbstractRestAction protected const ROUTE_PATH = '/visits'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; - private VisitsStatsHelperInterface $statsHelper; - - public function __construct(VisitsStatsHelperInterface $statsHelper) + public function __construct(private VisitsStatsHelperInterface $statsHelper) { - $this->statsHelper = $statsHelper; } public function handle(ServerRequestInterface $request): ResponseInterface diff --git a/module/Rest/src/Action/Visit/OrphanVisitsAction.php b/module/Rest/src/Action/Visit/OrphanVisitsAction.php index 7a65b920..b05d7b31 100644 --- a/module/Rest/src/Action/Visit/OrphanVisitsAction.php +++ b/module/Rest/src/Action/Visit/OrphanVisitsAction.php @@ -20,15 +20,10 @@ class OrphanVisitsAction extends AbstractRestAction protected const ROUTE_PATH = '/visits/orphan'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; - private VisitsStatsHelperInterface $visitsHelper; - private DataTransformerInterface $orphanVisitTransformer; - public function __construct( - VisitsStatsHelperInterface $visitsHelper, - DataTransformerInterface $orphanVisitTransformer + private VisitsStatsHelperInterface $visitsHelper, + private DataTransformerInterface $orphanVisitTransformer ) { - $this->visitsHelper = $visitsHelper; - $this->orphanVisitTransformer = $orphanVisitTransformer; } public function handle(ServerRequestInterface $request): ResponseInterface diff --git a/module/Rest/src/Action/Visit/ShortUrlVisitsAction.php b/module/Rest/src/Action/Visit/ShortUrlVisitsAction.php index 8175d1c7..5496ba35 100644 --- a/module/Rest/src/Action/Visit/ShortUrlVisitsAction.php +++ b/module/Rest/src/Action/Visit/ShortUrlVisitsAction.php @@ -21,11 +21,8 @@ class ShortUrlVisitsAction extends AbstractRestAction protected const ROUTE_PATH = '/short-urls/{shortCode}/visits'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; - private VisitsStatsHelperInterface $visitsHelper; - - public function __construct(VisitsStatsHelperInterface $visitsHelper) + public function __construct(private VisitsStatsHelperInterface $visitsHelper) { - $this->visitsHelper = $visitsHelper; } public function handle(Request $request): Response diff --git a/module/Rest/src/Action/Visit/TagVisitsAction.php b/module/Rest/src/Action/Visit/TagVisitsAction.php index 8d981c82..b577ce06 100644 --- a/module/Rest/src/Action/Visit/TagVisitsAction.php +++ b/module/Rest/src/Action/Visit/TagVisitsAction.php @@ -20,11 +20,8 @@ class TagVisitsAction extends AbstractRestAction protected const ROUTE_PATH = '/tags/{tag}/visits'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; - private VisitsStatsHelperInterface $visitsHelper; - - public function __construct(VisitsStatsHelperInterface $visitsHelper) + public function __construct(private VisitsStatsHelperInterface $visitsHelper) { - $this->visitsHelper = $visitsHelper; } public function handle(Request $request): Response diff --git a/module/Rest/src/ApiKey/Model/ApiKeyMeta.php b/module/Rest/src/ApiKey/Model/ApiKeyMeta.php index aa3c117a..39b5dca1 100644 --- a/module/Rest/src/ApiKey/Model/ApiKeyMeta.php +++ b/module/Rest/src/ApiKey/Model/ApiKeyMeta.php @@ -8,16 +8,12 @@ use Cake\Chronos\Chronos; final class ApiKeyMeta { - private ?string $name = null; - private ?Chronos $expirationDate = null; - /** @var RoleDefinition[] */ - private array $roleDefinitions; - - private function __construct(?string $name, ?Chronos $expirationDate, array $roleDefinitions) - { - $this->name = $name; - $this->expirationDate = $expirationDate; - $this->roleDefinitions = $roleDefinitions; + private function __construct( + private ?string $name, + private ?Chronos $expirationDate, + /** @var RoleDefinition[] */ + private array $roleDefinitions, + ) { } public static function withName(string $name): self diff --git a/module/Rest/src/ApiKey/Model/RoleDefinition.php b/module/Rest/src/ApiKey/Model/RoleDefinition.php index 569044dc..fdd4d5cb 100644 --- a/module/Rest/src/ApiKey/Model/RoleDefinition.php +++ b/module/Rest/src/ApiKey/Model/RoleDefinition.php @@ -9,13 +9,8 @@ use Shlinkio\Shlink\Rest\ApiKey\Role; final class RoleDefinition { - private string $roleName; - private array $meta; - - private function __construct(string $roleName, array $meta) + private function __construct(private string $roleName, private array $meta) { - $this->roleName = $roleName; - $this->meta = $meta; } public static function forAuthoredShortUrls(): self diff --git a/module/Rest/src/ApiKey/Spec/WithApiKeySpecsEnsuringJoin.php b/module/Rest/src/ApiKey/Spec/WithApiKeySpecsEnsuringJoin.php index a1f9b361..ddfabe81 100644 --- a/module/Rest/src/ApiKey/Spec/WithApiKeySpecsEnsuringJoin.php +++ b/module/Rest/src/ApiKey/Spec/WithApiKeySpecsEnsuringJoin.php @@ -11,14 +11,9 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; class WithApiKeySpecsEnsuringJoin extends BaseSpecification { - private ?ApiKey $apiKey; - private string $fieldToJoin; - - public function __construct(?ApiKey $apiKey, string $fieldToJoin = 'shortUrls') + public function __construct(private ?ApiKey $apiKey, private string $fieldToJoin = 'shortUrls') { parent::__construct(); - $this->apiKey = $apiKey; - $this->fieldToJoin = $fieldToJoin; } protected function getSpec(): Specification diff --git a/module/Rest/src/Entity/ApiKeyRole.php b/module/Rest/src/Entity/ApiKeyRole.php index 99dbb627..1155c37b 100644 --- a/module/Rest/src/Entity/ApiKeyRole.php +++ b/module/Rest/src/Entity/ApiKeyRole.php @@ -8,15 +8,8 @@ use Shlinkio\Shlink\Common\Entity\AbstractEntity; class ApiKeyRole extends AbstractEntity { - private string $roleName; - private array $meta; - private ApiKey $apiKey; - - public function __construct(string $roleName, array $meta, ApiKey $apiKey) + public function __construct(private string $roleName, private array $meta, private ApiKey $apiKey) { - $this->roleName = $roleName; - $this->meta = $meta; - $this->apiKey = $apiKey; } public function name(): string diff --git a/module/Rest/src/Middleware/AuthenticationMiddleware.php b/module/Rest/src/Middleware/AuthenticationMiddleware.php index cb8f8b7a..705bc9c5 100644 --- a/module/Rest/src/Middleware/AuthenticationMiddleware.php +++ b/module/Rest/src/Middleware/AuthenticationMiddleware.php @@ -23,18 +23,11 @@ class AuthenticationMiddleware implements MiddlewareInterface, StatusCodeInterfa { public const API_KEY_HEADER = 'X-Api-Key'; - private ApiKeyServiceInterface $apiKeyService; - private array $routesWithoutApiKey; - private array $routesWithQueryApiKey; - public function __construct( - ApiKeyServiceInterface $apiKeyService, - array $routesWithoutApiKey, - array $routesWithQueryApiKey + private ApiKeyServiceInterface $apiKeyService, + private array $routesWithoutApiKey, + private array $routesWithQueryApiKey ) { - $this->apiKeyService = $apiKeyService; - $this->routesWithoutApiKey = $routesWithoutApiKey; - $this->routesWithQueryApiKey = $routesWithQueryApiKey; } public function process(Request $request, RequestHandlerInterface $handler): Response diff --git a/module/Rest/src/Middleware/CrossDomainMiddleware.php b/module/Rest/src/Middleware/CrossDomainMiddleware.php index b265fe13..b0d63dc7 100644 --- a/module/Rest/src/Middleware/CrossDomainMiddleware.php +++ b/module/Rest/src/Middleware/CrossDomainMiddleware.php @@ -16,11 +16,8 @@ use function implode; class CrossDomainMiddleware implements MiddlewareInterface, RequestMethodInterface { - private array $config; - - public function __construct(array $config) + public function __construct(private array $config) { - $this->config = $config; } public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface diff --git a/module/Rest/src/Middleware/ShortUrl/DefaultShortCodesLengthMiddleware.php b/module/Rest/src/Middleware/ShortUrl/DefaultShortCodesLengthMiddleware.php index c1991de2..cffc56b0 100644 --- a/module/Rest/src/Middleware/ShortUrl/DefaultShortCodesLengthMiddleware.php +++ b/module/Rest/src/Middleware/ShortUrl/DefaultShortCodesLengthMiddleware.php @@ -12,11 +12,8 @@ use Shlinkio\Shlink\Core\Validation\ShortUrlInputFilter; class DefaultShortCodesLengthMiddleware implements MiddlewareInterface { - private int $defaultShortCodesLength; - - public function __construct(int $defaultShortCodesLength) + public function __construct(private int $defaultShortCodesLength) { - $this->defaultShortCodesLength = $defaultShortCodesLength; } public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface diff --git a/module/Rest/src/Middleware/ShortUrl/DropDefaultDomainFromRequestMiddleware.php b/module/Rest/src/Middleware/ShortUrl/DropDefaultDomainFromRequestMiddleware.php index 3d76a975..59515242 100644 --- a/module/Rest/src/Middleware/ShortUrl/DropDefaultDomainFromRequestMiddleware.php +++ b/module/Rest/src/Middleware/ShortUrl/DropDefaultDomainFromRequestMiddleware.php @@ -11,11 +11,8 @@ use Psr\Http\Server\RequestHandlerInterface; class DropDefaultDomainFromRequestMiddleware implements MiddlewareInterface { - private string $defaultDomain; - - public function __construct(string $defaultDomain) + public function __construct(private string $defaultDomain) { - $this->defaultDomain = $defaultDomain; } public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface diff --git a/module/Rest/src/Middleware/ShortUrl/OverrideDomainMiddleware.php b/module/Rest/src/Middleware/ShortUrl/OverrideDomainMiddleware.php index c875a9ab..6943f986 100644 --- a/module/Rest/src/Middleware/ShortUrl/OverrideDomainMiddleware.php +++ b/module/Rest/src/Middleware/ShortUrl/OverrideDomainMiddleware.php @@ -16,11 +16,8 @@ use Shlinkio\Shlink\Rest\Middleware\AuthenticationMiddleware; class OverrideDomainMiddleware implements MiddlewareInterface { - private DomainServiceInterface $domainService; - - public function __construct(DomainServiceInterface $domainService) + public function __construct(private DomainServiceInterface $domainService) { - $this->domainService = $domainService; } public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface diff --git a/module/Rest/src/Service/ApiKeyCheckResult.php b/module/Rest/src/Service/ApiKeyCheckResult.php index 8ec3f65e..2caee4e1 100644 --- a/module/Rest/src/Service/ApiKeyCheckResult.php +++ b/module/Rest/src/Service/ApiKeyCheckResult.php @@ -8,11 +8,8 @@ use Shlinkio\Shlink\Rest\Entity\ApiKey; final class ApiKeyCheckResult { - private ?ApiKey $apiKey; - - public function __construct(?ApiKey $apiKey = null) + public function __construct(private ?ApiKey $apiKey = null) { - $this->apiKey = $apiKey; } public function isValid(): bool diff --git a/module/Rest/src/Service/ApiKeyService.php b/module/Rest/src/Service/ApiKeyService.php index e81c446f..0aad928f 100644 --- a/module/Rest/src/Service/ApiKeyService.php +++ b/module/Rest/src/Service/ApiKeyService.php @@ -15,11 +15,8 @@ use function sprintf; class ApiKeyService implements ApiKeyServiceInterface { - private EntityManagerInterface $em; - - public function __construct(EntityManagerInterface $em) + public function __construct(private EntityManagerInterface $em) { - $this->em = $em; } public function create( @@ -40,20 +37,14 @@ class ApiKeyService implements ApiKeyServiceInterface private function buildApiKeyWithParams(?Chronos $expirationDate, ?string $name): ApiKey { - // TODO Use match expression when migrating to PHP8 - if ($expirationDate === null && $name === null) { - return ApiKey::create(); - } - - if ($expirationDate !== null && $name !== null) { - return ApiKey::fromMeta(ApiKeyMeta::withNameAndExpirationDate($name, $expirationDate)); - } - - if ($name === null) { - return ApiKey::fromMeta(ApiKeyMeta::withExpirationDate($expirationDate)); - } - - return ApiKey::fromMeta(ApiKeyMeta::withName($name)); + return match (true) { + $expirationDate === null && $name === null => ApiKey::create(), + $expirationDate !== null && $name !== null => ApiKey::fromMeta( + ApiKeyMeta::withNameAndExpirationDate($name, $expirationDate), + ), + $name === null => ApiKey::fromMeta(ApiKeyMeta::withExpirationDate($expirationDate)), + default => ApiKey::fromMeta(ApiKeyMeta::withName($name)), + }; } public function check(string $key): ApiKeyCheckResult