diff --git a/.travis.yml b/.travis.yml index a4b5d1de..5d6176ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,14 +5,8 @@ branches: - /.*/ php: - - '7.2' - - '7.3' - '7.4' -matrix: - allow_failures: - - php: '7.4' - services: - mysql - postgresql @@ -39,7 +33,7 @@ before_script: script: - composer ci - - if [[ ! -z "$DOCKERFILE_CHANGED" && "${TRAVIS_PHP_VERSION}" == "7.2" ]]; then docker build -t shlink-docker-image:temp . ; fi + - if [[ ! -z "$DOCKERFILE_CHANGED" && "${TRAVIS_PHP_VERSION}" == "7.4" ]]; then docker build -t shlink-docker-image:temp . ; fi after_success: - rm -f build/clover.xml @@ -61,4 +55,4 @@ deploy: skip_cleanup: true on: tags: true - php: '7.2' + php: '7.4' diff --git a/Dockerfile b/Dockerfile index f24dd289..0734d370 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM php:7.3.11-alpine3.10 +FROM php:7.4.1-alpine3.10 LABEL maintainer="Alejandro Celaya " ARG SHLINK_VERSION=1.20.2 diff --git a/README.md b/README.md index 5f86aeb2..9d0911c6 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ A PHP-based self-hosted URL shortener that can be used to serve shortened URLs u First, make sure the host where you are going to run shlink fulfills these requirements: -* PHP 7.2 or greater with JSON, APCu, intl, curl, PDO and gd extensions enabled. +* PHP 7.4 or greater with JSON, APCu, intl, curl, PDO and gd extensions enabled. * MySQL, MariaDB, PostgreSQL or SQLite. * The web server of your choice with PHP integration (Apache or Nginx recommended). diff --git a/composer.json b/composer.json index 7782f61d..1dddb7f8 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ } ], "require": { - "php": "^7.2", + "php": "^7.4", "ext-json": "*", "ext-pdo": "*", "akrabat/ip-address-middleware": "^1.0", @@ -30,7 +30,7 @@ "mikehaertl/phpwkhtmltopdf": "^2.2", "monolog/monolog": "^2.0", "nikolaposa/monolog-factory": "^3.0", - "ocramius/proxy-manager": "~2.2.2", + "ocramius/proxy-manager": "^2.5.1", "phly/phly-event-dispatcher": "^1.0", "predis/predis": "^1.1", "pugx/shortid-php": "^0.5", @@ -60,7 +60,7 @@ "devster/ubench": "^2.0", "eaglewu/swoole-ide-helper": "dev-master", "infection/infection": "^0.15.0", - "phpstan/phpstan-shim": "^0.11.16", + "phpstan/phpstan": "^0.12.3", "phpunit/phpunit": "^8.3", "roave/security-advisories": "dev-master", "shlinkio/php-coding-standard": "~2.0.0", diff --git a/config/test/bootstrap_api_tests.php b/config/test/bootstrap_api_tests.php index 3605427c..4cf01807 100644 --- a/config/test/bootstrap_api_tests.php +++ b/config/test/bootstrap_api_tests.php @@ -15,6 +15,4 @@ $em = $container->get(EntityManager::class); $testHelper->createTestDb(); ApiTest\ApiTestCase::setApiClient($container->get('shlink_test_api_client')); -ApiTest\ApiTestCase::setSeedFixturesCallback(function () use ($testHelper, $em, $config) { - $testHelper->seedFixtures($em, $config['data_fixtures'] ?? []); -}); +ApiTest\ApiTestCase::setSeedFixturesCallback(fn () => $testHelper->seedFixtures($em, $config['data_fixtures'] ?? [])); diff --git a/config/test/test_config.global.php b/config/test/test_config.global.php index a0a9aeb7..0aeaea6d 100644 --- a/config/test/test_config.global.php +++ b/config/test/test_config.global.php @@ -19,9 +19,7 @@ $swooleTestingPort = 9999; $buildDbConnection = function (): array { $driver = env('DB_DRIVER', 'sqlite'); $isCi = env('TRAVIS', false); - $getMysqlHost = function (string $driver) { - return sprintf('shlink_db%s', $driver === 'mysql' ? '' : '_maria'); - }; + $getMysqlHost = fn (string $driver) => sprintf('shlink_db%s', $driver === 'mysql' ? '' : '_maria'); $driverConfigMap = [ 'sqlite' => [ diff --git a/data/infra/examples/nginx-vhost.conf b/data/infra/examples/nginx-vhost.conf index b501a70c..d5bb0a2c 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.2-fpm.sock; + fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; fastcgi_index index.php; include fastcgi.conf; } diff --git a/data/infra/php.Dockerfile b/data/infra/php.Dockerfile index 0cb74aaa..e92cc815 100644 --- a/data/infra/php.Dockerfile +++ b/data/infra/php.Dockerfile @@ -1,18 +1,20 @@ -FROM php:7.3.11-fpm-alpine3.10 +FROM php:7.4.1-fpm-alpine3.10 MAINTAINER Alejandro Celaya ENV APCU_VERSION 5.1.18 ENV APCU_BC_VERSION 1.0.5 -ENV XDEBUG_VERSION 2.8.0 +ENV XDEBUG_VERSION 2.9.0 RUN apk update # Install common php extensions RUN docker-php-ext-install pdo_mysql RUN docker-php-ext-install iconv -RUN docker-php-ext-install mbstring RUN docker-php-ext-install calendar +RUN apk add --no-cache oniguruma-dev +RUN docker-php-ext-install mbstring + RUN apk add --no-cache sqlite-libs RUN apk add --no-cache sqlite-dev RUN docker-php-ext-install pdo_sqlite diff --git a/data/infra/swoole.Dockerfile b/data/infra/swoole.Dockerfile index ea7dc230..46f45e6d 100644 --- a/data/infra/swoole.Dockerfile +++ b/data/infra/swoole.Dockerfile @@ -1,4 +1,4 @@ -FROM php:7.3.11-alpine3.10 +FROM php:7.4.1-alpine3.10 MAINTAINER Alejandro Celaya ENV APCU_VERSION 5.1.18 @@ -11,9 +11,11 @@ RUN apk update # Install common php extensions RUN docker-php-ext-install pdo_mysql RUN docker-php-ext-install iconv -RUN docker-php-ext-install mbstring RUN docker-php-ext-install calendar +RUN apk add --no-cache oniguruma-dev +RUN docker-php-ext-install mbstring + RUN apk add --no-cache sqlite-libs RUN apk add --no-cache sqlite-dev RUN docker-php-ext-install pdo_sqlite diff --git a/module/CLI/src/Command/Api/DisableKeyCommand.php b/module/CLI/src/Command/Api/DisableKeyCommand.php index f3eb7f6b..1a8024ec 100644 --- a/module/CLI/src/Command/Api/DisableKeyCommand.php +++ b/module/CLI/src/Command/Api/DisableKeyCommand.php @@ -19,8 +19,7 @@ class DisableKeyCommand extends Command { public const NAME = 'api-key:disable'; - /** @var ApiKeyServiceInterface */ - private $apiKeyService; + private ApiKeyServiceInterface $apiKeyService; public function __construct(ApiKeyServiceInterface $apiKeyService) { diff --git a/module/CLI/src/Command/Api/GenerateKeyCommand.php b/module/CLI/src/Command/Api/GenerateKeyCommand.php index bbe86a51..cadc1fc1 100644 --- a/module/CLI/src/Command/Api/GenerateKeyCommand.php +++ b/module/CLI/src/Command/Api/GenerateKeyCommand.php @@ -19,8 +19,7 @@ class GenerateKeyCommand extends Command { public const NAME = 'api-key:generate'; - /** @var ApiKeyServiceInterface */ - private $apiKeyService; + private ApiKeyServiceInterface $apiKeyService; public function __construct(ApiKeyServiceInterface $apiKeyService) { diff --git a/module/CLI/src/Command/Api/ListKeysCommand.php b/module/CLI/src/Command/Api/ListKeysCommand.php index c9df3a07..2d8b8cd6 100644 --- a/module/CLI/src/Command/Api/ListKeysCommand.php +++ b/module/CLI/src/Command/Api/ListKeysCommand.php @@ -25,8 +25,7 @@ class ListKeysCommand extends Command public const NAME = 'api-key:list'; - /** @var ApiKeyServiceInterface */ - private $apiKeyService; + private ApiKeyServiceInterface $apiKeyService; public function __construct(ApiKeyServiceInterface $apiKeyService) { diff --git a/module/CLI/src/Command/Db/AbstractDatabaseCommand.php b/module/CLI/src/Command/Db/AbstractDatabaseCommand.php index bf99de9b..4b45fa56 100644 --- a/module/CLI/src/Command/Db/AbstractDatabaseCommand.php +++ b/module/CLI/src/Command/Db/AbstractDatabaseCommand.php @@ -15,10 +15,8 @@ use function array_unshift; abstract class AbstractDatabaseCommand extends AbstractLockedCommand { - /** @var ProcessHelper */ - private $processHelper; - /** @var string */ - private $phpBinary; + private ProcessHelper $processHelper; + private string $phpBinary; public function __construct(LockFactory $locker, ProcessHelper $processHelper, PhpExecutableFinder $phpFinder) { diff --git a/module/CLI/src/Command/Db/CreateDatabaseCommand.php b/module/CLI/src/Command/Db/CreateDatabaseCommand.php index 54cd27ea..30043f72 100644 --- a/module/CLI/src/Command/Db/CreateDatabaseCommand.php +++ b/module/CLI/src/Command/Db/CreateDatabaseCommand.php @@ -21,10 +21,8 @@ class CreateDatabaseCommand extends AbstractDatabaseCommand public const DOCTRINE_SCRIPT = 'vendor/doctrine/orm/bin/doctrine.php'; public const DOCTRINE_CREATE_SCHEMA_COMMAND = 'orm:schema-tool:create'; - /** @var Connection */ - private $regularConn; - /** @var Connection */ - private $noDbNameConn; + private Connection $regularConn; + private Connection $noDbNameConn; public function __construct( LockFactory $locker, diff --git a/module/CLI/src/Command/ShortUrl/DeleteShortUrlCommand.php b/module/CLI/src/Command/ShortUrl/DeleteShortUrlCommand.php index c2e81d0d..6626791b 100644 --- a/module/CLI/src/Command/ShortUrl/DeleteShortUrlCommand.php +++ b/module/CLI/src/Command/ShortUrl/DeleteShortUrlCommand.php @@ -21,8 +21,7 @@ class DeleteShortUrlCommand extends Command public const NAME = 'short-url:delete'; private const ALIASES = ['short-code:delete']; - /** @var DeleteShortUrlServiceInterface */ - private $deleteShortUrlService; + private DeleteShortUrlServiceInterface $deleteShortUrlService; public function __construct(DeleteShortUrlServiceInterface $deleteShortUrlService) { diff --git a/module/CLI/src/Command/ShortUrl/GenerateShortUrlCommand.php b/module/CLI/src/Command/ShortUrl/GenerateShortUrlCommand.php index faefbf4b..94748795 100644 --- a/module/CLI/src/Command/ShortUrl/GenerateShortUrlCommand.php +++ b/module/CLI/src/Command/ShortUrl/GenerateShortUrlCommand.php @@ -28,10 +28,8 @@ class GenerateShortUrlCommand extends Command public const NAME = 'short-url:generate'; private const ALIASES = ['shortcode:generate', 'short-code:generate']; - /** @var UrlShortenerInterface */ - private $urlShortener; - /** @var array */ - private $domainConfig; + private UrlShortenerInterface $urlShortener; + private array $domainConfig; public function __construct(UrlShortenerInterface $urlShortener, array $domainConfig) { diff --git a/module/CLI/src/Command/ShortUrl/GetVisitsCommand.php b/module/CLI/src/Command/ShortUrl/GetVisitsCommand.php index 7a51ac0b..94462a57 100644 --- a/module/CLI/src/Command/ShortUrl/GetVisitsCommand.php +++ b/module/CLI/src/Command/ShortUrl/GetVisitsCommand.php @@ -24,8 +24,7 @@ class GetVisitsCommand extends AbstractWithDateRangeCommand public const NAME = 'short-url:visits'; private const ALIASES = ['shortcode:visits', 'short-code:visits']; - /** @var VisitsTrackerInterface */ - private $visitsTracker; + private VisitsTrackerInterface $visitsTracker; public function __construct(VisitsTrackerInterface $visitsTracker) { diff --git a/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php b/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php index 01080189..9eb0cc13 100644 --- a/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php +++ b/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php @@ -42,10 +42,8 @@ class ListShortUrlsCommand extends AbstractWithDateRangeCommand 'tags', ]; - /** @var ShortUrlServiceInterface */ - private $shortUrlService; - /** @var ShortUrlDataTransformer */ - private $transformer; + private ShortUrlServiceInterface $shortUrlService; + private ShortUrlDataTransformer $transformer; public function __construct(ShortUrlServiceInterface $shortUrlService, array $domainConfig) { diff --git a/module/CLI/src/Command/ShortUrl/ResolveUrlCommand.php b/module/CLI/src/Command/ShortUrl/ResolveUrlCommand.php index e8db28e2..c75ac9d6 100644 --- a/module/CLI/src/Command/ShortUrl/ResolveUrlCommand.php +++ b/module/CLI/src/Command/ShortUrl/ResolveUrlCommand.php @@ -21,8 +21,7 @@ class ResolveUrlCommand extends Command public const NAME = 'short-url:parse'; private const ALIASES = ['shortcode:parse', 'short-code:parse']; - /** @var UrlShortenerInterface */ - private $urlShortener; + private UrlShortenerInterface $urlShortener; public function __construct(UrlShortenerInterface $urlShortener) { diff --git a/module/CLI/src/Command/Tag/CreateTagCommand.php b/module/CLI/src/Command/Tag/CreateTagCommand.php index 9971d96a..18aba957 100644 --- a/module/CLI/src/Command/Tag/CreateTagCommand.php +++ b/module/CLI/src/Command/Tag/CreateTagCommand.php @@ -16,8 +16,7 @@ class CreateTagCommand extends Command { public const NAME = 'tag:create'; - /** @var TagServiceInterface */ - private $tagService; + private TagServiceInterface $tagService; public function __construct(TagServiceInterface $tagService) { diff --git a/module/CLI/src/Command/Tag/DeleteTagsCommand.php b/module/CLI/src/Command/Tag/DeleteTagsCommand.php index 2677f11c..a3dd81e1 100644 --- a/module/CLI/src/Command/Tag/DeleteTagsCommand.php +++ b/module/CLI/src/Command/Tag/DeleteTagsCommand.php @@ -16,8 +16,7 @@ class DeleteTagsCommand extends Command { public const NAME = 'tag:delete'; - /** @var TagServiceInterface */ - private $tagService; + private TagServiceInterface $tagService; public function __construct(TagServiceInterface $tagService) { diff --git a/module/CLI/src/Command/Tag/ListTagsCommand.php b/module/CLI/src/Command/Tag/ListTagsCommand.php index db3df1c3..0b8f0aa3 100644 --- a/module/CLI/src/Command/Tag/ListTagsCommand.php +++ b/module/CLI/src/Command/Tag/ListTagsCommand.php @@ -18,8 +18,7 @@ class ListTagsCommand extends Command { public const NAME = 'tag:list'; - /** @var TagServiceInterface */ - private $tagService; + private TagServiceInterface $tagService; public function __construct(TagServiceInterface $tagService) { @@ -47,8 +46,6 @@ class ListTagsCommand extends Command return [['No tags yet']]; } - return map($tags, function (Tag $tag) { - return [(string) $tag]; - }); + return map($tags, fn (Tag $tag) => [(string) $tag]); } } diff --git a/module/CLI/src/Command/Tag/RenameTagCommand.php b/module/CLI/src/Command/Tag/RenameTagCommand.php index d1607f34..f30bc757 100644 --- a/module/CLI/src/Command/Tag/RenameTagCommand.php +++ b/module/CLI/src/Command/Tag/RenameTagCommand.php @@ -18,8 +18,7 @@ class RenameTagCommand extends Command { public const NAME = 'tag:rename'; - /** @var TagServiceInterface */ - private $tagService; + private TagServiceInterface $tagService; public function __construct(TagServiceInterface $tagService) { diff --git a/module/CLI/src/Command/Util/AbstractLockedCommand.php b/module/CLI/src/Command/Util/AbstractLockedCommand.php index 59ea74fa..eab43436 100644 --- a/module/CLI/src/Command/Util/AbstractLockedCommand.php +++ b/module/CLI/src/Command/Util/AbstractLockedCommand.php @@ -14,8 +14,7 @@ use function sprintf; abstract class AbstractLockedCommand extends Command { - /** @var LockFactory */ - private $locker; + private LockFactory $locker; public function __construct(LockFactory $locker) { diff --git a/module/CLI/src/Command/Util/LockedCommandConfig.php b/module/CLI/src/Command/Util/LockedCommandConfig.php index be7c2deb..8a217f85 100644 --- a/module/CLI/src/Command/Util/LockedCommandConfig.php +++ b/module/CLI/src/Command/Util/LockedCommandConfig.php @@ -8,12 +8,9 @@ final class LockedCommandConfig { private const DEFAULT_TTL = 90.0; // 1.5 minutes - /** @var string */ - private $lockName; - /** @var bool */ - private $isBlocking; - /** @var float */ - private $ttl; + private string $lockName; + private bool $isBlocking; + private float $ttl; public function __construct(string $lockName, bool $isBlocking = false, float $ttl = self::DEFAULT_TTL) { diff --git a/module/CLI/src/Command/Visit/LocateVisitsCommand.php b/module/CLI/src/Command/Visit/LocateVisitsCommand.php index 710c4a3a..0bbd0c90 100644 --- a/module/CLI/src/Command/Visit/LocateVisitsCommand.php +++ b/module/CLI/src/Command/Visit/LocateVisitsCommand.php @@ -32,17 +32,12 @@ class LocateVisitsCommand extends AbstractLockedCommand public const NAME = 'visit:locate'; public const ALIASES = ['visit:process']; - /** @var VisitServiceInterface */ - private $visitService; - /** @var IpLocationResolverInterface */ - private $ipLocationResolver; - /** @var GeolocationDbUpdaterInterface */ - private $dbUpdater; + private VisitServiceInterface $visitService; + private IpLocationResolverInterface $ipLocationResolver; + private GeolocationDbUpdaterInterface $dbUpdater; - /** @var SymfonyStyle */ - private $io; - /** @var ProgressBar */ - private $progressBar; + private SymfonyStyle $io; + private ?ProgressBar $progressBar = null; public function __construct( VisitServiceInterface $visitService, diff --git a/module/CLI/src/Exception/GeolocationDbUpdateFailedException.php b/module/CLI/src/Exception/GeolocationDbUpdateFailedException.php index 38bb4c5f..42707d9b 100644 --- a/module/CLI/src/Exception/GeolocationDbUpdateFailedException.php +++ b/module/CLI/src/Exception/GeolocationDbUpdateFailedException.php @@ -9,8 +9,7 @@ use Throwable; class GeolocationDbUpdateFailedException extends RuntimeException implements ExceptionInterface { - /** @var bool */ - private $olderDbExists; + private bool $olderDbExists; public static function create(bool $olderDbExists, ?Throwable $prev = null): self { diff --git a/module/CLI/src/Util/GeolocationDbUpdater.php b/module/CLI/src/Util/GeolocationDbUpdater.php index 25b49c37..b74ebdac 100644 --- a/module/CLI/src/Util/GeolocationDbUpdater.php +++ b/module/CLI/src/Util/GeolocationDbUpdater.php @@ -15,12 +15,9 @@ class GeolocationDbUpdater implements GeolocationDbUpdaterInterface { private const LOCK_NAME = 'geolocation-db-update'; - /** @var DbUpdaterInterface */ - private $dbUpdater; - /** @var Reader */ - private $geoLiteDbReader; - /** @var LockFactory */ - private $locker; + private DbUpdaterInterface $dbUpdater; + private Reader $geoLiteDbReader; + private LockFactory $locker; public function __construct(DbUpdaterInterface $dbUpdater, Reader $geoLiteDbReader, LockFactory $locker) { diff --git a/module/CLI/src/Util/ShlinkTable.php b/module/CLI/src/Util/ShlinkTable.php index a577ce8d..ac8733ad 100644 --- a/module/CLI/src/Util/ShlinkTable.php +++ b/module/CLI/src/Util/ShlinkTable.php @@ -12,8 +12,7 @@ final class ShlinkTable private const DEFAULT_STYLE_NAME = 'default'; private const TABLE_TITLE_STYLE = ' %s '; - /** @var Table|null */ - private $baseTable; + private ?Table $baseTable; public function __construct(Table $baseTable) { diff --git a/module/CLI/test/Command/Api/DisableKeyCommandTest.php b/module/CLI/test/Command/Api/DisableKeyCommandTest.php index 37629091..8b5ef6c4 100644 --- a/module/CLI/test/Command/Api/DisableKeyCommandTest.php +++ b/module/CLI/test/Command/Api/DisableKeyCommandTest.php @@ -8,20 +8,18 @@ use PHPUnit\Framework\TestCase; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\Api\DisableKeyCommand; use Shlinkio\Shlink\Common\Exception\InvalidArgumentException; -use Shlinkio\Shlink\Rest\Service\ApiKeyService; +use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; class DisableKeyCommandTest extends TestCase { - /** @var CommandTester */ - private $commandTester; - /** @var ObjectProphecy */ - private $apiKeyService; + private CommandTester $commandTester; + private ObjectProphecy $apiKeyService; public function setUp(): void { - $this->apiKeyService = $this->prophesize(ApiKeyService::class); + $this->apiKeyService = $this->prophesize(ApiKeyServiceInterface::class); $command = new DisableKeyCommand($this->apiKeyService->reveal()); $app = new Application(); $app->add($command); diff --git a/module/CLI/test/Command/Api/GenerateKeyCommandTest.php b/module/CLI/test/Command/Api/GenerateKeyCommandTest.php index 1556aa85..fe5bc137 100644 --- a/module/CLI/test/Command/Api/GenerateKeyCommandTest.php +++ b/module/CLI/test/Command/Api/GenerateKeyCommandTest.php @@ -10,20 +10,18 @@ use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\Api\GenerateKeyCommand; use Shlinkio\Shlink\Rest\Entity\ApiKey; -use Shlinkio\Shlink\Rest\Service\ApiKeyService; +use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; class GenerateKeyCommandTest extends TestCase { - /** @var CommandTester */ - private $commandTester; - /** @var ObjectProphecy */ - private $apiKeyService; + private CommandTester $commandTester; + private ObjectProphecy $apiKeyService; public function setUp(): void { - $this->apiKeyService = $this->prophesize(ApiKeyService::class); + $this->apiKeyService = $this->prophesize(ApiKeyServiceInterface::class); $command = new GenerateKeyCommand($this->apiKeyService->reveal()); $app = new Application(); $app->add($command); diff --git a/module/CLI/test/Command/Api/ListKeysCommandTest.php b/module/CLI/test/Command/Api/ListKeysCommandTest.php index 027b22c2..9e30605a 100644 --- a/module/CLI/test/Command/Api/ListKeysCommandTest.php +++ b/module/CLI/test/Command/Api/ListKeysCommandTest.php @@ -8,20 +8,18 @@ use PHPUnit\Framework\TestCase; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\Api\ListKeysCommand; use Shlinkio\Shlink\Rest\Entity\ApiKey; -use Shlinkio\Shlink\Rest\Service\ApiKeyService; +use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; class ListKeysCommandTest extends TestCase { - /** @var CommandTester */ - private $commandTester; - /** @var ObjectProphecy */ - private $apiKeyService; + private CommandTester $commandTester; + private ObjectProphecy $apiKeyService; public function setUp(): void { - $this->apiKeyService = $this->prophesize(ApiKeyService::class); + $this->apiKeyService = $this->prophesize(ApiKeyServiceInterface::class); $command = new ListKeysCommand($this->apiKeyService->reveal()); $app = new Application(); $app->add($command); diff --git a/module/CLI/test/Command/Config/GenerateCharsetCommandTest.php b/module/CLI/test/Command/Config/GenerateCharsetCommandTest.php index 8475cecc..e5430e4a 100644 --- a/module/CLI/test/Command/Config/GenerateCharsetCommandTest.php +++ b/module/CLI/test/Command/Config/GenerateCharsetCommandTest.php @@ -15,8 +15,7 @@ use function str_split; class GenerateCharsetCommandTest extends TestCase { - /** @var CommandTester */ - private $commandTester; + private CommandTester $commandTester; public function setUp(): void { diff --git a/module/CLI/test/Command/Db/CreateDatabaseCommandTest.php b/module/CLI/test/Command/Db/CreateDatabaseCommandTest.php index 7945ea05..700b96bb 100644 --- a/module/CLI/test/Command/Db/CreateDatabaseCommandTest.php +++ b/module/CLI/test/Command/Db/CreateDatabaseCommandTest.php @@ -21,18 +21,12 @@ use Symfony\Component\Process\PhpExecutableFinder; class CreateDatabaseCommandTest extends TestCase { - /** @var CommandTester */ - private $commandTester; - /** @var ObjectProphecy */ - private $processHelper; - /** @var ObjectProphecy */ - private $regularConn; - /** @var ObjectProphecy */ - private $noDbNameConn; - /** @var ObjectProphecy */ - private $schemaManager; - /** @var ObjectProphecy */ - private $databasePlatform; + private CommandTester $commandTester; + private ObjectProphecy $processHelper; + private ObjectProphecy $regularConn; + private ObjectProphecy $noDbNameConn; + private ObjectProphecy $schemaManager; + private ObjectProphecy $databasePlatform; public function setUp(): void { diff --git a/module/CLI/test/Command/Db/MigrateDatabaseCommandTest.php b/module/CLI/test/Command/Db/MigrateDatabaseCommandTest.php index be36a980..70dce5cc 100644 --- a/module/CLI/test/Command/Db/MigrateDatabaseCommandTest.php +++ b/module/CLI/test/Command/Db/MigrateDatabaseCommandTest.php @@ -18,10 +18,8 @@ use Symfony\Component\Process\PhpExecutableFinder; class MigrateDatabaseCommandTest extends TestCase { - /** @var CommandTester */ - private $commandTester; - /** @var ObjectProphecy */ - private $processHelper; + private CommandTester $commandTester; + private ObjectProphecy $processHelper; public function setUp(): void { diff --git a/module/CLI/test/Command/ShortUrl/DeleteShortUrlCommandTest.php b/module/CLI/test/Command/ShortUrl/DeleteShortUrlCommandTest.php index 85521835..989277b8 100644 --- a/module/CLI/test/Command/ShortUrl/DeleteShortUrlCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/DeleteShortUrlCommandTest.php @@ -20,10 +20,8 @@ use const PHP_EOL; class DeleteShortUrlCommandTest extends TestCase { - /** @var CommandTester */ - private $commandTester; - /** @var ObjectProphecy */ - private $service; + private CommandTester $commandTester; + private ObjectProphecy $service; public function setUp(): void { diff --git a/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php b/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php index 077e0c60..e4029231 100644 --- a/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/GeneratePreviewCommandTest.php @@ -22,12 +22,9 @@ use function substr_count; class GeneratePreviewCommandTest extends TestCase { - /** @var CommandTester */ - private $commandTester; - /** @var ObjectProphecy */ - private $previewGenerator; - /** @var ObjectProphecy */ - private $shortUrlService; + private CommandTester $commandTester; + private ObjectProphecy $previewGenerator; + private ObjectProphecy $shortUrlService; public function setUp(): void { diff --git a/module/CLI/test/Command/ShortUrl/GenerateShortUrlCommandTest.php b/module/CLI/test/Command/ShortUrl/GenerateShortUrlCommandTest.php index abae0fe6..4f55e7c8 100644 --- a/module/CLI/test/Command/ShortUrl/GenerateShortUrlCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/GenerateShortUrlCommandTest.php @@ -25,10 +25,8 @@ class GenerateShortUrlCommandTest extends TestCase 'hostname' => 'foo.com', ]; - /** @var CommandTester */ - private $commandTester; - /** @var ObjectProphecy */ - private $urlShortener; + private CommandTester $commandTester; + private ObjectProphecy $urlShortener; public function setUp(): void { diff --git a/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php b/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php index e2ea29d1..1fd0c229 100644 --- a/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php @@ -26,10 +26,8 @@ use function sprintf; class GetVisitsCommandTest extends TestCase { - /** @var CommandTester */ - private $commandTester; - /** @var ObjectProphecy */ - private $visitsTracker; + private CommandTester $commandTester; + private ObjectProphecy $visitsTracker; public function setUp(): void { diff --git a/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php b/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php index 0bf3bfab..a704111d 100644 --- a/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php @@ -21,10 +21,8 @@ use function explode; class ListShortUrlsCommandTest extends TestCase { - /** @var CommandTester */ - private $commandTester; - /** @var ObjectProphecy */ - private $shortUrlService; + private CommandTester $commandTester; + private ObjectProphecy $shortUrlService; public function setUp(): void { @@ -44,9 +42,9 @@ class ListShortUrlsCommandTest extends TestCase $data[] = new ShortUrl('url_' . $i); } - $this->shortUrlService->listShortUrls(Argument::cetera())->will(function () use (&$data) { - return new Paginator(new ArrayAdapter($data)); - })->shouldBeCalledTimes(3); + $this->shortUrlService->listShortUrls(Argument::cetera()) + ->will(fn () => new Paginator(new ArrayAdapter($data))) + ->shouldBeCalledTimes(3); $this->commandTester->setInputs(['y', 'y', 'n']); $this->commandTester->execute([]); diff --git a/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php b/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php index 11b549e5..1fe8b238 100644 --- a/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php @@ -19,10 +19,8 @@ use const PHP_EOL; class ResolveUrlCommandTest extends TestCase { - /** @var CommandTester */ - private $commandTester; - /** @var ObjectProphecy */ - private $urlShortener; + private CommandTester $commandTester; + private ObjectProphecy $urlShortener; public function setUp(): void { diff --git a/module/CLI/test/Command/Tag/CreateTagCommandTest.php b/module/CLI/test/Command/Tag/CreateTagCommandTest.php index 402c63a6..bed087a5 100644 --- a/module/CLI/test/Command/Tag/CreateTagCommandTest.php +++ b/module/CLI/test/Command/Tag/CreateTagCommandTest.php @@ -14,10 +14,8 @@ use Symfony\Component\Console\Tester\CommandTester; class CreateTagCommandTest extends TestCase { - /** @var CommandTester */ - private $commandTester; - /** @var ObjectProphecy */ - private $tagService; + private CommandTester $commandTester; + private ObjectProphecy $tagService; public function setUp(): void { @@ -31,7 +29,7 @@ class CreateTagCommandTest extends TestCase } /** @test */ - public function errorIsReturnedWhenNoTagsAreProvided() + public function errorIsReturnedWhenNoTagsAreProvided(): void { $this->commandTester->execute([]); @@ -40,7 +38,7 @@ class CreateTagCommandTest extends TestCase } /** @test */ - public function serviceIsInvokedOnSuccess() + public function serviceIsInvokedOnSuccess(): void { $tagNames = ['foo', 'bar']; $createTags = $this->tagService->createTags($tagNames)->willReturn(new ArrayCollection()); diff --git a/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php b/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php index 79701ddb..f526f37f 100644 --- a/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php +++ b/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php @@ -13,12 +13,8 @@ use Symfony\Component\Console\Tester\CommandTester; class DeleteTagsCommandTest extends TestCase { - /** @var DeleteTagsCommand */ - private $command; - /** @var CommandTester */ - private $commandTester; - /** @var ObjectProphecy */ - private $tagService; + private CommandTester $commandTester; + private ObjectProphecy $tagService; public function setUp(): void { @@ -32,7 +28,7 @@ class DeleteTagsCommandTest extends TestCase } /** @test */ - public function errorIsReturnedWhenNoTagsAreProvided() + public function errorIsReturnedWhenNoTagsAreProvided(): void { $this->commandTester->execute([]); @@ -41,7 +37,7 @@ class DeleteTagsCommandTest extends TestCase } /** @test */ - public function serviceIsInvokedOnSuccess() + public function serviceIsInvokedOnSuccess(): void { $tagNames = ['foo', 'bar']; $deleteTags = $this->tagService->deleteTags($tagNames)->will(function () { diff --git a/module/CLI/test/Command/Tag/ListTagsCommandTest.php b/module/CLI/test/Command/Tag/ListTagsCommandTest.php index eec94372..f171127c 100644 --- a/module/CLI/test/Command/Tag/ListTagsCommandTest.php +++ b/module/CLI/test/Command/Tag/ListTagsCommandTest.php @@ -14,12 +14,8 @@ use Symfony\Component\Console\Tester\CommandTester; class ListTagsCommandTest extends TestCase { - /** @var ListTagsCommand */ - private $command; - /** @var CommandTester */ - private $commandTester; - /** @var ObjectProphecy */ - private $tagService; + private CommandTester $commandTester; + private ObjectProphecy $tagService; public function setUp(): void { @@ -33,7 +29,7 @@ class ListTagsCommandTest extends TestCase } /** @test */ - public function noTagsPrintsEmptyMessage() + public function noTagsPrintsEmptyMessage(): void { $listTags = $this->tagService->listTags()->willReturn([]); @@ -45,7 +41,7 @@ class ListTagsCommandTest extends TestCase } /** @test */ - public function listOfTagsIsPrinted() + public function listOfTagsIsPrinted(): void { $listTags = $this->tagService->listTags()->willReturn([ new Tag('foo'), diff --git a/module/CLI/test/Command/Tag/RenameTagCommandTest.php b/module/CLI/test/Command/Tag/RenameTagCommandTest.php index c626e0c0..59f8d89c 100644 --- a/module/CLI/test/Command/Tag/RenameTagCommandTest.php +++ b/module/CLI/test/Command/Tag/RenameTagCommandTest.php @@ -15,12 +15,8 @@ use Symfony\Component\Console\Tester\CommandTester; class RenameTagCommandTest extends TestCase { - /** @var RenameTagCommand */ - private $command; - /** @var CommandTester */ - private $commandTester; - /** @var ObjectProphecy */ - private $tagService; + private CommandTester $commandTester; + private ObjectProphecy $tagService; public function setUp(): void { diff --git a/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php b/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php index e01bf85f..c1a09b08 100644 --- a/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php +++ b/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php @@ -29,18 +29,12 @@ use function sprintf; class LocateVisitsCommandTest extends TestCase { - /** @var CommandTester */ - private $commandTester; - /** @var ObjectProphecy */ - private $visitService; - /** @var ObjectProphecy */ - private $ipResolver; - /** @var ObjectProphecy */ - private $locker; - /** @var ObjectProphecy */ - private $lock; - /** @var ObjectProphecy */ - private $dbUpdater; + private CommandTester $commandTester; + private ObjectProphecy $visitService; + private ObjectProphecy $ipResolver; + private ObjectProphecy $locker; + private ObjectProphecy $lock; + private ObjectProphecy $dbUpdater; public function setUp(): void { diff --git a/module/CLI/test/Command/Visit/UpdateDbCommandTest.php b/module/CLI/test/Command/Visit/UpdateDbCommandTest.php index dc343efd..2d6fc478 100644 --- a/module/CLI/test/Command/Visit/UpdateDbCommandTest.php +++ b/module/CLI/test/Command/Visit/UpdateDbCommandTest.php @@ -16,10 +16,8 @@ use Symfony\Component\Console\Tester\CommandTester; class UpdateDbCommandTest extends TestCase { - /** @var CommandTester */ - private $commandTester; - /** @var ObjectProphecy */ - private $dbUpdater; + private CommandTester $commandTester; + private ObjectProphecy $dbUpdater; public function setUp(): void { diff --git a/module/CLI/test/ConfigProviderTest.php b/module/CLI/test/ConfigProviderTest.php index 48931551..96e2d2b4 100644 --- a/module/CLI/test/ConfigProviderTest.php +++ b/module/CLI/test/ConfigProviderTest.php @@ -9,8 +9,7 @@ use Shlinkio\Shlink\CLI\ConfigProvider; class ConfigProviderTest extends TestCase { - /** @var ConfigProvider */ - private $configProvider; + private ConfigProvider $configProvider; public function setUp(): void { diff --git a/module/CLI/test/Factory/ApplicationFactoryTest.php b/module/CLI/test/Factory/ApplicationFactoryTest.php index 7f8ca6ea..0dd9dc01 100644 --- a/module/CLI/test/Factory/ApplicationFactoryTest.php +++ b/module/CLI/test/Factory/ApplicationFactoryTest.php @@ -15,8 +15,7 @@ use Zend\ServiceManager\ServiceManager; class ApplicationFactoryTest extends TestCase { - /** @var ApplicationFactory */ - private $factory; + private ApplicationFactory $factory; public function setUp(): void { @@ -36,7 +35,6 @@ class ApplicationFactoryTest extends TestCase $sm->setService('foo', $this->createCommandMock('foo')->reveal()); $sm->setService('bar', $this->createCommandMock('bar')->reveal()); - /** @var Application $instance */ $instance = ($this->factory)($sm); $this->assertTrue($instance->has('foo')); diff --git a/module/CLI/test/Util/GeolocationDbUpdaterTest.php b/module/CLI/test/Util/GeolocationDbUpdaterTest.php index f2b0f98c..640c0e7c 100644 --- a/module/CLI/test/Util/GeolocationDbUpdaterTest.php +++ b/module/CLI/test/Util/GeolocationDbUpdaterTest.php @@ -22,16 +22,11 @@ use function range; class GeolocationDbUpdaterTest extends TestCase { - /** @var GeolocationDbUpdater */ - private $geolocationDbUpdater; - /** @var ObjectProphecy */ - private $dbUpdater; - /** @var ObjectProphecy */ - private $geoLiteDbReader; - /** @var ObjectProphecy */ - private $locker; - /** @var ObjectProphecy */ - private $lock; + private GeolocationDbUpdater $geolocationDbUpdater; + private ObjectProphecy $dbUpdater; + private ObjectProphecy $geoLiteDbReader; + private ObjectProphecy $locker; + private ObjectProphecy $lock; public function setUp(): void { @@ -55,9 +50,7 @@ class GeolocationDbUpdaterTest extends TestCase /** @test */ public function exceptionIsThrownWhenOlderDbDoesNotExistAndDownloadFails(): void { - $mustBeUpdated = function () { - $this->assertTrue(true); - }; + $mustBeUpdated = fn () => $this->assertTrue(true); $prev = new RuntimeException(''); $fileExists = $this->dbUpdater->databaseFileExists()->willReturn(false); @@ -153,8 +146,6 @@ class GeolocationDbUpdaterTest extends TestCase public function provideSmallDays(): iterable { - return map(range(0, 34), function (int $days) { - return [$days]; - }); + return map(range(0, 34), fn (int $days) => [$days]); } } diff --git a/module/CLI/test/Util/ShlinkTableTest.php b/module/CLI/test/Util/ShlinkTableTest.php index c67ebe47..2f679191 100644 --- a/module/CLI/test/Util/ShlinkTableTest.php +++ b/module/CLI/test/Util/ShlinkTableTest.php @@ -15,10 +15,8 @@ use Symfony\Component\Console\Output\OutputInterface; class ShlinkTableTest extends TestCase { - /** @var ShlinkTable */ - private $shlinkTable; - /** @var ObjectProphecy */ - private $baseTable; + private ShlinkTable $shlinkTable; + private ObjectProphecy $baseTable; public function setUp(): void { diff --git a/module/Core/src/Action/AbstractTrackingAction.php b/module/Core/src/Action/AbstractTrackingAction.php index ff8d91f2..d60b888e 100644 --- a/module/Core/src/Action/AbstractTrackingAction.php +++ b/module/Core/src/Action/AbstractTrackingAction.php @@ -25,14 +25,10 @@ use function http_build_query; abstract class AbstractTrackingAction implements MiddlewareInterface { - /** @var UrlShortenerInterface */ - private $urlShortener; - /** @var VisitsTrackerInterface */ - private $visitTracker; - /** @var AppOptions */ - private $appOptions; - /** @var LoggerInterface */ - private $logger; + private UrlShortenerInterface $urlShortener; + private VisitsTrackerInterface $visitTracker; + private AppOptions $appOptions; + private LoggerInterface $logger; public function __construct( UrlShortenerInterface $urlShortener, diff --git a/module/Core/src/Action/QrCodeAction.php b/module/Core/src/Action/QrCodeAction.php index 3cdee70e..083b1119 100644 --- a/module/Core/src/Action/QrCodeAction.php +++ b/module/Core/src/Action/QrCodeAction.php @@ -23,12 +23,9 @@ class QrCodeAction implements MiddlewareInterface private const MIN_SIZE = 50; private const MAX_SIZE = 1000; - /** @var RouterInterface */ - private $router; - /** @var UrlShortenerInterface */ - private $urlShortener; - /** @var LoggerInterface */ - private $logger; + private RouterInterface $router; + private UrlShortenerInterface $urlShortener; + private LoggerInterface $logger; public function __construct( RouterInterface $router, diff --git a/module/Core/src/Config/SimplifiedConfigParser.php b/module/Core/src/Config/SimplifiedConfigParser.php index 5ee912b0..e9c2ae7b 100644 --- a/module/Core/src/Config/SimplifiedConfigParser.php +++ b/module/Core/src/Config/SimplifiedConfigParser.php @@ -75,9 +75,10 @@ class SimplifiedConfigParser // This mainly allows deprecating keys and defining new ones that will replace the older and always take // preference, while the old one keeps working for backwards compatibility if the new one is not provided. $simplifiedConfigOrder = array_flip(array_keys(self::SIMPLIFIED_CONFIG_MAPPING)); - uksort($configForExistingKeys, function (string $a, string $b) use ($simplifiedConfigOrder): int { - return $simplifiedConfigOrder[$a] - $simplifiedConfigOrder[$b]; - }); + uksort( + $configForExistingKeys, + fn (string $a, string $b): int => $simplifiedConfigOrder[$a] - $simplifiedConfigOrder[$b] + ); return $configForExistingKeys; } diff --git a/module/Core/src/Domain/Resolver/PersistenceDomainResolver.php b/module/Core/src/Domain/Resolver/PersistenceDomainResolver.php index 6532a1c3..ca679d96 100644 --- a/module/Core/src/Domain/Resolver/PersistenceDomainResolver.php +++ b/module/Core/src/Domain/Resolver/PersistenceDomainResolver.php @@ -9,8 +9,7 @@ use Shlinkio\Shlink\Core\Entity\Domain; class PersistenceDomainResolver implements DomainResolverInterface { - /** @var EntityManagerInterface */ - private $em; + private EntityManagerInterface $em; public function __construct(EntityManagerInterface $em) { diff --git a/module/Core/src/Entity/Domain.php b/module/Core/src/Entity/Domain.php index 8be40c00..924b50e5 100644 --- a/module/Core/src/Entity/Domain.php +++ b/module/Core/src/Entity/Domain.php @@ -8,8 +8,7 @@ use Shlinkio\Shlink\Common\Entity\AbstractEntity; class Domain extends AbstractEntity { - /** @var string */ - private $authority; + private string $authority; public function __construct(string $authority) { diff --git a/module/Core/src/Entity/ShortUrl.php b/module/Core/src/Entity/ShortUrl.php index 6cf6378a..64d6d4b5 100644 --- a/module/Core/src/Entity/ShortUrl.php +++ b/module/Core/src/Entity/ShortUrl.php @@ -22,26 +22,18 @@ use function Shlinkio\Shlink\Core\generateRandomShortCode; class ShortUrl extends AbstractEntity { - /** @var string */ - private $longUrl; - /** @var string */ - private $shortCode; - /** @var Chronos */ - private $dateCreated; + private string $longUrl; + private string $shortCode; + private Chronos $dateCreated; /** @var Collection|Visit[] */ - private $visits; + private Collection $visits; /** @var Collection|Tag[] */ - private $tags; - /** @var Chronos|null */ - private $validSince; - /** @var Chronos|null */ - private $validUntil; - /** @var integer|null */ - private $maxVisits; - /** @var Domain|null */ - private $domain; - /** @var bool */ - private $customSlugWasProvided; + private Collection $tags; + private ?Chronos $validSince; + private ?Chronos $validUntil; + private ?int $maxVisits; + private ?Domain $domain; + private bool $customSlugWasProvided; public function __construct( string $longUrl, @@ -196,9 +188,7 @@ class ShortUrl extends AbstractEntity $shortUrlTags = invoke($this->getTags(), '__toString'); $hasAllTags = count($shortUrlTags) === count($tags) && array_reduce( $tags, - function (bool $hasAllTags, string $tag) use ($shortUrlTags) { - return $hasAllTags && contains($shortUrlTags, $tag); - }, + fn (bool $hasAllTags, string $tag) => $hasAllTags && contains($shortUrlTags, $tag), true ); diff --git a/module/Core/src/Entity/Tag.php b/module/Core/src/Entity/Tag.php index a703ebab..7530b70a 100644 --- a/module/Core/src/Entity/Tag.php +++ b/module/Core/src/Entity/Tag.php @@ -9,8 +9,7 @@ use Shlinkio\Shlink\Common\Entity\AbstractEntity; class Tag extends AbstractEntity implements JsonSerializable { - /** @var string */ - private $name; + private string $name; public function __construct(string $name) { diff --git a/module/Core/src/Entity/Visit.php b/module/Core/src/Entity/Visit.php index b2ce3640..c4ee97a2 100644 --- a/module/Core/src/Entity/Visit.php +++ b/module/Core/src/Entity/Visit.php @@ -15,18 +15,12 @@ use Shlinkio\Shlink\Core\Visit\Model\VisitLocationInterface; class Visit extends AbstractEntity implements JsonSerializable { - /** @var string */ - private $referer; - /** @var Chronos */ - private $date; - /** @var string|null */ - private $remoteAddr; - /** @var string */ - private $userAgent; - /** @var ShortUrl */ - private $shortUrl; - /** @var VisitLocation */ - private $visitLocation; + private string $referer; + private Chronos $date; + private ?string $remoteAddr; + private string $userAgent; + private ShortUrl $shortUrl; + private ?VisitLocation $visitLocation = null; public function __construct(ShortUrl $shortUrl, Visitor $visitor, ?Chronos $date = null) { @@ -93,7 +87,7 @@ class Visit extends AbstractEntity implements JsonSerializable { return [ 'referer' => $this->referer, - 'date' => $this->date !== null ? $this->date->toAtomString() : null, + 'date' => $this->date->toAtomString(), 'userAgent' => $this->userAgent, 'visitLocation' => $this->visitLocation, diff --git a/module/Core/src/Entity/VisitLocation.php b/module/Core/src/Entity/VisitLocation.php index 9108a719..ebc8829a 100644 --- a/module/Core/src/Entity/VisitLocation.php +++ b/module/Core/src/Entity/VisitLocation.php @@ -10,20 +10,13 @@ use Shlinkio\Shlink\IpGeolocation\Model\Location; class VisitLocation extends AbstractEntity implements VisitLocationInterface { - /** @var string */ - private $countryCode; - /** @var string */ - private $countryName; - /** @var string */ - private $regionName; - /** @var string */ - private $cityName; - /** @var string */ - private $latitude; - /** @var string */ - private $longitude; - /** @var string */ - private $timezone; + private string $countryCode; + private string $countryName; + private string $regionName; + private string $cityName; + private string $latitude; // FIXME Should be float + private string $longitude; // FIXME Should be float + private string $timezone; public function __construct(Location $location) { diff --git a/module/Core/src/ErrorHandler/NotFoundRedirectHandler.php b/module/Core/src/ErrorHandler/NotFoundRedirectHandler.php index f6a03395..54dc9cac 100644 --- a/module/Core/src/ErrorHandler/NotFoundRedirectHandler.php +++ b/module/Core/src/ErrorHandler/NotFoundRedirectHandler.php @@ -18,10 +18,8 @@ use function rtrim; class NotFoundRedirectHandler implements MiddlewareInterface { - /** @var NotFoundRedirectOptions */ - private $redirectOptions; - /** @var string */ - private $shlinkBasePath; + private NotFoundRedirectOptions $redirectOptions; + private string $shlinkBasePath; public function __construct(NotFoundRedirectOptions $redirectOptions, string $shlinkBasePath) { diff --git a/module/Core/src/ErrorHandler/NotFoundTemplateHandler.php b/module/Core/src/ErrorHandler/NotFoundTemplateHandler.php index 7b84043d..69cc8036 100644 --- a/module/Core/src/ErrorHandler/NotFoundTemplateHandler.php +++ b/module/Core/src/ErrorHandler/NotFoundTemplateHandler.php @@ -18,8 +18,7 @@ class NotFoundTemplateHandler implements RequestHandlerInterface public const NOT_FOUND_TEMPLATE = 'ShlinkCore::error/404'; public const INVALID_SHORT_CODE_TEMPLATE = 'ShlinkCore::invalid-short-code'; - /** @var TemplateRendererInterface */ - private $renderer; + private TemplateRendererInterface $renderer; public function __construct(TemplateRendererInterface $renderer) { diff --git a/module/Core/src/EventDispatcher/LocateShortUrlVisit.php b/module/Core/src/EventDispatcher/LocateShortUrlVisit.php index 4d767272..0dd6b56f 100644 --- a/module/Core/src/EventDispatcher/LocateShortUrlVisit.php +++ b/module/Core/src/EventDispatcher/LocateShortUrlVisit.php @@ -19,16 +19,11 @@ use function sprintf; class LocateShortUrlVisit { - /** @var IpLocationResolverInterface */ - private $ipLocationResolver; - /** @var EntityManagerInterface */ - private $em; - /** @var LoggerInterface */ - private $logger; - /** @var GeolocationDbUpdaterInterface */ - private $dbUpdater; - /** @var EventDispatcherInterface */ - private $eventDispatcher; + private IpLocationResolverInterface $ipLocationResolver; + private EntityManagerInterface $em; + private LoggerInterface $logger; + private GeolocationDbUpdaterInterface $dbUpdater; + private EventDispatcherInterface $eventDispatcher; public function __construct( IpLocationResolverInterface $ipLocationResolver, diff --git a/module/Core/src/EventDispatcher/NotifyVisitToWebHooks.php b/module/Core/src/EventDispatcher/NotifyVisitToWebHooks.php index d99defb5..7f901d33 100644 --- a/module/Core/src/EventDispatcher/NotifyVisitToWebHooks.php +++ b/module/Core/src/EventDispatcher/NotifyVisitToWebHooks.php @@ -22,18 +22,13 @@ use function GuzzleHttp\Promise\settle; class NotifyVisitToWebHooks { - /** @var ClientInterface */ - private $httpClient; - /** @var EntityManagerInterface */ - private $em; - /** @var LoggerInterface */ - private $logger; - /** @var array */ - private $webhooks; - /** @var ShortUrlDataTransformer */ - private $transformer; - /** @var AppOptions */ - private $appOptions; + private ClientInterface $httpClient; + private EntityManagerInterface $em; + private LoggerInterface $logger; + /** @var string[] */ + private array $webhooks; + private ShortUrlDataTransformer $transformer; + private AppOptions $appOptions; public function __construct( ClientInterface $httpClient, diff --git a/module/Core/src/EventDispatcher/ShortUrlVisited.php b/module/Core/src/EventDispatcher/ShortUrlVisited.php index d12cdaf7..1f0b5b5c 100644 --- a/module/Core/src/EventDispatcher/ShortUrlVisited.php +++ b/module/Core/src/EventDispatcher/ShortUrlVisited.php @@ -8,8 +8,7 @@ use JsonSerializable; final class ShortUrlVisited implements JsonSerializable { - /** @var string */ - private $visitId; + private string $visitId; public function __construct(string $visitId) { diff --git a/module/Core/src/EventDispatcher/VisitLocated.php b/module/Core/src/EventDispatcher/VisitLocated.php index 4873ffa7..0e1c1176 100644 --- a/module/Core/src/EventDispatcher/VisitLocated.php +++ b/module/Core/src/EventDispatcher/VisitLocated.php @@ -8,8 +8,7 @@ use JsonSerializable; final class VisitLocated implements JsonSerializable { - /** @var string */ - private $visitId; + private string $visitId; public function __construct(string $visitId) { diff --git a/module/Core/src/Exception/IpCannotBeLocatedException.php b/module/Core/src/Exception/IpCannotBeLocatedException.php index 8c0b220f..b1ba731c 100644 --- a/module/Core/src/Exception/IpCannotBeLocatedException.php +++ b/module/Core/src/Exception/IpCannotBeLocatedException.php @@ -8,32 +8,24 @@ use Throwable; class IpCannotBeLocatedException extends RuntimeException { - /** @var bool */ - private $isNonLocatableAddress; - - public function __construct( - bool $isNonLocatableAddress, - string $message, - int $code = 0, - ?Throwable $previous = null - ) { - $this->isNonLocatableAddress = $isNonLocatableAddress; - parent::__construct($message, $code, $previous); - } + private bool $isNonLocatableAddress = true; public static function forEmptyAddress(): self { - return new self(true, 'Ignored visit with no IP address'); + return new self('Ignored visit with no IP address'); } public static function forLocalhost(): self { - return new self(true, 'Ignored localhost address'); + return new self('Ignored localhost address'); } public static function forError(Throwable $e): self { - return new self(false, 'An error occurred while locating IP', $e->getCode(), $e); + $e = new self('An error occurred while locating IP', $e->getCode(), $e); + $e->isNonLocatableAddress = false; + + return $e; } /** diff --git a/module/Core/src/Exception/ValidationException.php b/module/Core/src/Exception/ValidationException.php index abceec91..8710b737 100644 --- a/module/Core/src/Exception/ValidationException.php +++ b/module/Core/src/Exception/ValidationException.php @@ -25,8 +25,7 @@ class ValidationException extends InvalidArgumentException implements ProblemDet private const TITLE = 'Invalid data'; private const TYPE = 'INVALID_ARGUMENT'; - /** @var array */ - private $invalidElements; + private array $invalidElements; public static function fromInputFilter(InputFilterInterface $inputFilter, ?Throwable $prev = null): self { @@ -70,12 +69,10 @@ class ValidationException extends InvalidArgumentException implements ProblemDet private function invalidElementsToString(): string { - return reduce_left($this->getInvalidElements(), function ($messageSet, string $name, $_, string $acc) { - return $acc . sprintf( - "\n '%s' => %s", - $name, - is_array($messageSet) ? print_r($messageSet, true) : $messageSet - ); - }, ''); + return reduce_left($this->getInvalidElements(), fn ($messages, string $name, $_, string $acc) => $acc . sprintf( + "\n '%s' => %s", + $name, + is_array($messages) ? print_r($messages, true) : $messages + ), ''); } } diff --git a/module/Core/src/Middleware/QrCodeCacheMiddleware.php b/module/Core/src/Middleware/QrCodeCacheMiddleware.php index 2036d687..14554e8c 100644 --- a/module/Core/src/Middleware/QrCodeCacheMiddleware.php +++ b/module/Core/src/Middleware/QrCodeCacheMiddleware.php @@ -13,8 +13,7 @@ use Zend\Diactoros\Response as DiactResp; class QrCodeCacheMiddleware implements MiddlewareInterface { - /** @var Cache */ - private $cache; + private Cache $cache; public function __construct(Cache $cache) { diff --git a/module/Core/src/Model/CreateShortUrlData.php b/module/Core/src/Model/CreateShortUrlData.php index 125f379a..3bd2cb7f 100644 --- a/module/Core/src/Model/CreateShortUrlData.php +++ b/module/Core/src/Model/CreateShortUrlData.php @@ -8,12 +8,9 @@ use Psr\Http\Message\UriInterface; final class CreateShortUrlData { - /** @var UriInterface */ - private $longUrl; - /** @var array */ - private $tags; - /** @var ShortUrlMeta */ - private $meta; + private UriInterface $longUrl; + private array $tags; + private ShortUrlMeta $meta; public function __construct( UriInterface $longUrl, diff --git a/module/Core/src/Model/ShortUrlMeta.php b/module/Core/src/Model/ShortUrlMeta.php index 24e770c6..1f8b0a7d 100644 --- a/module/Core/src/Model/ShortUrlMeta.php +++ b/module/Core/src/Model/ShortUrlMeta.php @@ -11,18 +11,12 @@ use Shlinkio\Shlink\Core\Validation\ShortUrlMetaInputFilter; final class ShortUrlMeta { - /** @var Chronos|null */ - private $validSince; - /** @var Chronos|null */ - private $validUntil; - /** @var string|null */ - private $customSlug; - /** @var int|null */ - private $maxVisits; - /** @var bool|null */ - private $findIfExists; - /** @var string|null */ - private $domain; + private ?Chronos $validSince = null; + private ?Chronos $validUntil = null; + private ?string $customSlug = null; + private ?int $maxVisits = null; + private ?bool $findIfExists = null; + private ?string $domain = null; // Force named constructors private function __construct() @@ -90,8 +84,8 @@ final class ShortUrlMeta $this->validSince = $this->parseDateField($inputFilter->getValue(ShortUrlMetaInputFilter::VALID_SINCE)); $this->validUntil = $this->parseDateField($inputFilter->getValue(ShortUrlMetaInputFilter::VALID_UNTIL)); $this->customSlug = $inputFilter->getValue(ShortUrlMetaInputFilter::CUSTOM_SLUG); - $this->maxVisits = $inputFilter->getValue(ShortUrlMetaInputFilter::MAX_VISITS); - $this->maxVisits = $this->maxVisits !== null ? (int) $this->maxVisits : null; + $maxVisits = $inputFilter->getValue(ShortUrlMetaInputFilter::MAX_VISITS); + $this->maxVisits = $maxVisits !== null ? (int) $maxVisits : null; $this->findIfExists = $inputFilter->getValue(ShortUrlMetaInputFilter::FIND_IF_EXISTS); $this->domain = $inputFilter->getValue(ShortUrlMetaInputFilter::DOMAIN); } diff --git a/module/Core/src/Model/Visitor.php b/module/Core/src/Model/Visitor.php index 584e8956..de9bb791 100644 --- a/module/Core/src/Model/Visitor.php +++ b/module/Core/src/Model/Visitor.php @@ -15,12 +15,9 @@ final class Visitor public const REFERER_MAX_LENGTH = 1024; public const REMOTE_ADDRESS_MAX_LENGTH = 256; - /** @var string */ - private $userAgent; - /** @var string */ - private $referer; - /** @var string|null */ - private $remoteAddress; + private string $userAgent; + private string $referer; + private ?string $remoteAddress; public function __construct(string $userAgent, string $referer, ?string $remoteAddress) { diff --git a/module/Core/src/Model/VisitsParams.php b/module/Core/src/Model/VisitsParams.php index f5af1c67..ffc13dc7 100644 --- a/module/Core/src/Model/VisitsParams.php +++ b/module/Core/src/Model/VisitsParams.php @@ -12,12 +12,9 @@ final class VisitsParams private const FIRST_PAGE = 1; private const ALL_ITEMS = -1; - /** @var null|DateRange */ - private $dateRange; - /** @var int */ - private $page; - /** @var int */ - private $itemsPerPage; + private ?DateRange $dateRange; + private int $page; + private int $itemsPerPage; public function __construct(?DateRange $dateRange = null, int $page = self::FIRST_PAGE, ?int $itemsPerPage = null) { diff --git a/module/Core/src/Options/AppOptions.php b/module/Core/src/Options/AppOptions.php index a26998d4..36b6d58b 100644 --- a/module/Core/src/Options/AppOptions.php +++ b/module/Core/src/Options/AppOptions.php @@ -13,17 +13,11 @@ class AppOptions extends AbstractOptions { use StringUtilsTrait; - /** @var string */ - private $name = ''; - /** @var string */ - private $version = '1.0'; - /** - * @var string - * @deprecated - */ - private $secretKey = ''; - /** @var string|null */ - private $disableTrackParam; + private string $name = ''; + private string $version = '1.0'; + /** @deprecated */ + private string $secretKey = ''; + private ?string $disableTrackParam = null; public function getName(): string { diff --git a/module/Core/src/Options/NotFoundRedirectOptions.php b/module/Core/src/Options/NotFoundRedirectOptions.php index 0165f8fc..611c144c 100644 --- a/module/Core/src/Options/NotFoundRedirectOptions.php +++ b/module/Core/src/Options/NotFoundRedirectOptions.php @@ -8,12 +8,9 @@ use Zend\Stdlib\AbstractOptions; class NotFoundRedirectOptions extends AbstractOptions { - /** @var string|null */ - private $invalidShortUrl; - /** @var string|null */ - private $regular404; - /** @var string|null */ - private $baseUrl; + private ?string $invalidShortUrl = null; + private ?string $regular404 = null; + private ?string $baseUrl = null; public function getInvalidShortUrlRedirect(): ?string { diff --git a/module/Core/src/Paginator/Adapter/ShortUrlRepositoryAdapter.php b/module/Core/src/Paginator/Adapter/ShortUrlRepositoryAdapter.php index de382d17..2534e3f4 100644 --- a/module/Core/src/Paginator/Adapter/ShortUrlRepositoryAdapter.php +++ b/module/Core/src/Paginator/Adapter/ShortUrlRepositoryAdapter.php @@ -15,16 +15,12 @@ class ShortUrlRepositoryAdapter implements AdapterInterface { public const ITEMS_PER_PAGE = 10; - /** @var ShortUrlRepositoryInterface */ - private $repository; - /** @var null|string */ - private $searchTerm; + private ShortUrlRepositoryInterface $repository; + private ?string $searchTerm; /** @var null|array|string */ private $orderBy; - /** @var array */ - private $tags; - /** @var DateRange|null */ - private $dateRange; + private array $tags; + private ?DateRange $dateRange; public function __construct( ShortUrlRepositoryInterface $repository, diff --git a/module/Core/src/Paginator/Adapter/VisitsPaginatorAdapter.php b/module/Core/src/Paginator/Adapter/VisitsPaginatorAdapter.php index cffa2f3d..83aff355 100644 --- a/module/Core/src/Paginator/Adapter/VisitsPaginatorAdapter.php +++ b/module/Core/src/Paginator/Adapter/VisitsPaginatorAdapter.php @@ -10,12 +10,9 @@ use Zend\Paginator\Adapter\AdapterInterface; class VisitsPaginatorAdapter implements AdapterInterface { - /** @var VisitRepositoryInterface */ - private $visitRepository; - /** @var string */ - private $shortCode; - /** @var VisitsParams */ - private $params; + private VisitRepositoryInterface $visitRepository; + private string $shortCode; + private VisitsParams $params; public function __construct(VisitRepositoryInterface $visitRepository, string $shortCode, VisitsParams $params) { diff --git a/module/Core/src/Service/ShortUrl/DeleteShortUrlService.php b/module/Core/src/Service/ShortUrl/DeleteShortUrlService.php index c7cfb9c4..b6d574ee 100644 --- a/module/Core/src/Service/ShortUrl/DeleteShortUrlService.php +++ b/module/Core/src/Service/ShortUrl/DeleteShortUrlService.php @@ -13,10 +13,8 @@ class DeleteShortUrlService implements DeleteShortUrlServiceInterface { use FindShortCodeTrait; - /** @var EntityManagerInterface */ - private $em; - /** @var DeleteShortUrlsOptions */ - private $deleteShortUrlsOptions; + private EntityManagerInterface $em; + private DeleteShortUrlsOptions $deleteShortUrlsOptions; public function __construct(EntityManagerInterface $em, DeleteShortUrlsOptions $deleteShortUrlsOptions) { diff --git a/module/Core/src/Service/ShortUrlService.php b/module/Core/src/Service/ShortUrlService.php index 15a3b432..65dc57bd 100644 --- a/module/Core/src/Service/ShortUrlService.php +++ b/module/Core/src/Service/ShortUrlService.php @@ -20,8 +20,7 @@ class ShortUrlService implements ShortUrlServiceInterface use FindShortCodeTrait; use TagManagerTrait; - /** @var ORM\EntityManagerInterface */ - private $em; + private ORM\EntityManagerInterface $em; public function __construct(ORM\EntityManagerInterface $em) { diff --git a/module/Core/src/Service/Tag/TagService.php b/module/Core/src/Service/Tag/TagService.php index 672f0b05..b95ddf82 100644 --- a/module/Core/src/Service/Tag/TagService.php +++ b/module/Core/src/Service/Tag/TagService.php @@ -16,8 +16,7 @@ class TagService implements TagServiceInterface { use TagManagerTrait; - /** @var ORM\EntityManagerInterface */ - private $em; + private ORM\EntityManagerInterface $em; public function __construct(ORM\EntityManagerInterface $em) { diff --git a/module/Core/src/Service/UrlShortener.php b/module/Core/src/Service/UrlShortener.php index 70112bd7..be61d15b 100644 --- a/module/Core/src/Service/UrlShortener.php +++ b/module/Core/src/Service/UrlShortener.php @@ -24,12 +24,9 @@ class UrlShortener implements UrlShortenerInterface { use TagManagerTrait; - /** @var EntityManagerInterface */ - private $em; - /** @var UrlShortenerOptions */ - private $options; - /** @var UrlValidatorInterface */ - private $urlValidator; + private EntityManagerInterface $em; + private UrlShortenerOptions $options; + private UrlValidatorInterface $urlValidator; public function __construct( UrlValidatorInterface $urlValidator, diff --git a/module/Core/src/Service/VisitService.php b/module/Core/src/Service/VisitService.php index 582a10fe..20a30f4c 100644 --- a/module/Core/src/Service/VisitService.php +++ b/module/Core/src/Service/VisitService.php @@ -13,8 +13,7 @@ use Shlinkio\Shlink\IpGeolocation\Model\Location; class VisitService implements VisitServiceInterface { - /** @var EntityManagerInterface */ - private $em; + private EntityManagerInterface $em; public function __construct(EntityManagerInterface $em) { diff --git a/module/Core/src/Service/VisitsTracker.php b/module/Core/src/Service/VisitsTracker.php index 612ad4ee..f3c8c448 100644 --- a/module/Core/src/Service/VisitsTracker.php +++ b/module/Core/src/Service/VisitsTracker.php @@ -18,10 +18,8 @@ use Zend\Paginator\Paginator; class VisitsTracker implements VisitsTrackerInterface { - /** @var ORM\EntityManagerInterface */ - private $em; - /** @var EventDispatcherInterface */ - private $eventDispatcher; + private ORM\EntityManagerInterface $em; + private EventDispatcherInterface $eventDispatcher; public function __construct(ORM\EntityManagerInterface $em, EventDispatcherInterface $eventDispatcher) { diff --git a/module/Core/src/Transformer/ShortUrlDataTransformer.php b/module/Core/src/Transformer/ShortUrlDataTransformer.php index 348ff0d5..f734cf01 100644 --- a/module/Core/src/Transformer/ShortUrlDataTransformer.php +++ b/module/Core/src/Transformer/ShortUrlDataTransformer.php @@ -12,8 +12,7 @@ use function Functional\invoke_if; class ShortUrlDataTransformer implements DataTransformerInterface { - /** @var array */ - private $domainConfig; + private array $domainConfig; public function __construct(array $domainConfig) { diff --git a/module/Core/src/Util/UrlValidator.php b/module/Core/src/Util/UrlValidator.php index db7c6c2a..dca037cd 100644 --- a/module/Core/src/Util/UrlValidator.php +++ b/module/Core/src/Util/UrlValidator.php @@ -14,8 +14,7 @@ class UrlValidator implements UrlValidatorInterface, RequestMethodInterface { private const MAX_REDIRECTS = 15; - /** @var ClientInterface */ - private $httpClient; + private ClientInterface $httpClient; public function __construct(ClientInterface $httpClient) { diff --git a/module/Core/test-db/Repository/ShortUrlRepositoryTest.php b/module/Core/test-db/Repository/ShortUrlRepositoryTest.php index 2006623a..9cd92dc0 100644 --- a/module/Core/test-db/Repository/ShortUrlRepositoryTest.php +++ b/module/Core/test-db/Repository/ShortUrlRepositoryTest.php @@ -28,8 +28,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase Domain::class, ]; - /** @var ShortUrlRepository */ - private $repo; + private ShortUrlRepository $repo; public function setUp(): void { diff --git a/module/Core/test-db/Repository/TagRepositoryTest.php b/module/Core/test-db/Repository/TagRepositoryTest.php index 6e4ae404..9c5ab574 100644 --- a/module/Core/test-db/Repository/TagRepositoryTest.php +++ b/module/Core/test-db/Repository/TagRepositoryTest.php @@ -14,8 +14,7 @@ class TagRepositoryTest extends DatabaseTestCase Tag::class, ]; - /** @var TagRepository */ - private $repo; + private TagRepository $repo; protected function setUp(): void { diff --git a/module/Core/test-db/Repository/VisitRepositoryTest.php b/module/Core/test-db/Repository/VisitRepositoryTest.php index 23fa4c7a..bbccea41 100644 --- a/module/Core/test-db/Repository/VisitRepositoryTest.php +++ b/module/Core/test-db/Repository/VisitRepositoryTest.php @@ -26,8 +26,7 @@ class VisitRepositoryTest extends DatabaseTestCase ShortUrl::class, ]; - /** @var VisitRepository */ - private $repo; + private VisitRepository $repo; protected function setUp(): void { @@ -67,9 +66,7 @@ class VisitRepositoryTest extends DatabaseTestCase public function provideBlockSize(): iterable { - return map(range(1, 5), function (int $value) { - return [$value]; - }); + return map(range(1, 5), fn (int $value) => [$value]); } /** @test */ diff --git a/module/Core/test/Action/PixelActionTest.php b/module/Core/test/Action/PixelActionTest.php index df39f1df..682d5e17 100644 --- a/module/Core/test/Action/PixelActionTest.php +++ b/module/Core/test/Action/PixelActionTest.php @@ -10,7 +10,6 @@ use Prophecy\Prophecy\ObjectProphecy; use Psr\Http\Server\RequestHandlerInterface; use Shlinkio\Shlink\Common\Response\PixelResponse; use Shlinkio\Shlink\Core\Action\PixelAction; -use Shlinkio\Shlink\Core\Action\RedirectAction; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Options\AppOptions; use Shlinkio\Shlink\Core\Service\UrlShortener; @@ -19,12 +18,9 @@ use Zend\Diactoros\ServerRequest; class PixelActionTest extends TestCase { - /** @var RedirectAction */ - private $action; - /** @var ObjectProphecy */ - private $urlShortener; - /** @var ObjectProphecy */ - private $visitTracker; + private PixelAction $action; + private ObjectProphecy $urlShortener; + private ObjectProphecy $visitTracker; public function setUp(): void { diff --git a/module/Core/test/Action/PreviewActionTest.php b/module/Core/test/Action/PreviewActionTest.php index e2cb089c..0725c957 100644 --- a/module/Core/test/Action/PreviewActionTest.php +++ b/module/Core/test/Action/PreviewActionTest.php @@ -21,6 +21,7 @@ use function filesize; use const FILEINFO_MIME; +/** @deprecated */ class PreviewActionTest extends TestCase { /** @var PreviewAction */ diff --git a/module/Core/test/Action/QrCodeActionTest.php b/module/Core/test/Action/QrCodeActionTest.php index 6327ad69..0f5a0c7d 100644 --- a/module/Core/test/Action/QrCodeActionTest.php +++ b/module/Core/test/Action/QrCodeActionTest.php @@ -19,10 +19,8 @@ use Zend\Expressive\Router\RouterInterface; class QrCodeActionTest extends TestCase { - /** @var QrCodeAction */ - private $action; - /** @var ObjectProphecy */ - private $urlShortener; + private QrCodeAction $action; + private ObjectProphecy $urlShortener; public function setUp(): void { diff --git a/module/Core/test/Action/RedirectActionTest.php b/module/Core/test/Action/RedirectActionTest.php index 55342cb5..812857d4 100644 --- a/module/Core/test/Action/RedirectActionTest.php +++ b/module/Core/test/Action/RedirectActionTest.php @@ -21,12 +21,9 @@ use function array_key_exists; class RedirectActionTest extends TestCase { - /** @var RedirectAction */ - private $action; - /** @var ObjectProphecy */ - private $urlShortener; - /** @var ObjectProphecy */ - private $visitTracker; + private RedirectAction $action; + private ObjectProphecy $urlShortener; + private ObjectProphecy $visitTracker; public function setUp(): void { diff --git a/module/Core/test/Config/BasePathPrefixerTest.php b/module/Core/test/Config/BasePathPrefixerTest.php index fe4c7940..0e08fa89 100644 --- a/module/Core/test/Config/BasePathPrefixerTest.php +++ b/module/Core/test/Config/BasePathPrefixerTest.php @@ -9,8 +9,7 @@ use Shlinkio\Shlink\Core\Config\BasePathPrefixer; class BasePathPrefixerTest extends TestCase { - /** @var BasePathPrefixer */ - private $prefixer; + private BasePathPrefixer $prefixer; public function setUp(): void { diff --git a/module/Core/test/Config/DeprecatedConfigParserTest.php b/module/Core/test/Config/DeprecatedConfigParserTest.php index be76ba80..3d6d4815 100644 --- a/module/Core/test/Config/DeprecatedConfigParserTest.php +++ b/module/Core/test/Config/DeprecatedConfigParserTest.php @@ -11,8 +11,7 @@ use function array_merge; class DeprecatedConfigParserTest extends TestCase { - /** @var DeprecatedConfigParser */ - private $postProcessor; + private DeprecatedConfigParser $postProcessor; public function setUp(): void { diff --git a/module/Core/test/ConfigProviderTest.php b/module/Core/test/ConfigProviderTest.php index f38fe6bd..5077c61e 100644 --- a/module/Core/test/ConfigProviderTest.php +++ b/module/Core/test/ConfigProviderTest.php @@ -9,8 +9,7 @@ use Shlinkio\Shlink\Core\ConfigProvider; class ConfigProviderTest extends TestCase { - /** @var ConfigProvider */ - private $configProvider; + private ConfigProvider $configProvider; public function setUp(): void { diff --git a/module/Core/test/Domain/Resolver/PersistenceDomainResolverTest.php b/module/Core/test/Domain/Resolver/PersistenceDomainResolverTest.php index 4ba796ab..d3769af9 100644 --- a/module/Core/test/Domain/Resolver/PersistenceDomainResolverTest.php +++ b/module/Core/test/Domain/Resolver/PersistenceDomainResolverTest.php @@ -13,10 +13,8 @@ use Shlinkio\Shlink\Core\Entity\Domain; class PersistenceDomainResolverTest extends TestCase { - /** @var PersistenceDomainResolver */ - private $domainResolver; - /** @var ObjectProphecy */ - private $em; + private PersistenceDomainResolver $domainResolver; + private ObjectProphecy $em; public function setUp(): void { diff --git a/module/Core/test/Domain/Resolver/SimpleDomainResolverTest.php b/module/Core/test/Domain/Resolver/SimpleDomainResolverTest.php index 4fe4f74f..a0fa4bf1 100644 --- a/module/Core/test/Domain/Resolver/SimpleDomainResolverTest.php +++ b/module/Core/test/Domain/Resolver/SimpleDomainResolverTest.php @@ -10,8 +10,7 @@ use Shlinkio\Shlink\Core\Entity\Domain; class SimpleDomainResolverTest extends TestCase { - /** @var SimpleDomainResolver */ - private $domainResolver; + private SimpleDomainResolver $domainResolver; public function setUp(): void { diff --git a/module/Core/test/ErrorHandler/NotFoundRedirectHandlerTest.php b/module/Core/test/ErrorHandler/NotFoundRedirectHandlerTest.php index b7796e61..7672fbab 100644 --- a/module/Core/test/ErrorHandler/NotFoundRedirectHandlerTest.php +++ b/module/Core/test/ErrorHandler/NotFoundRedirectHandlerTest.php @@ -19,10 +19,8 @@ use Zend\Expressive\Router\RouteResult; class NotFoundRedirectHandlerTest extends TestCase { - /** @var NotFoundRedirectHandler */ - private $middleware; - /** @var NotFoundRedirectOptions */ - private $redirectOptions; + private NotFoundRedirectHandler $middleware; + private NotFoundRedirectOptions $redirectOptions; public function setUp(): void { diff --git a/module/Core/test/ErrorHandler/NotFoundTemplateHandlerTest.php b/module/Core/test/ErrorHandler/NotFoundTemplateHandlerTest.php index 7d763448..a9e2c4af 100644 --- a/module/Core/test/ErrorHandler/NotFoundTemplateHandlerTest.php +++ b/module/Core/test/ErrorHandler/NotFoundTemplateHandlerTest.php @@ -17,10 +17,8 @@ use Zend\Expressive\Template\TemplateRendererInterface; class NotFoundTemplateHandlerTest extends TestCase { - /** @var NotFoundTemplateHandler */ - private $handler; - /** @var ObjectProphecy */ - private $renderer; + private NotFoundTemplateHandler $handler; + private ObjectProphecy $renderer; public function setUp(): void { diff --git a/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php b/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php index a451ddea..0d79539e 100644 --- a/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php +++ b/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php @@ -27,18 +27,12 @@ use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface; class LocateShortUrlVisitTest extends TestCase { - /** @var LocateShortUrlVisit */ - private $locateVisit; - /** @var ObjectProphecy */ - private $ipLocationResolver; - /** @var ObjectProphecy */ - private $em; - /** @var ObjectProphecy */ - private $logger; - /** @var ObjectProphecy */ - private $dbUpdater; - /** @var ObjectProphecy */ - private $eventDispatcher; + private LocateShortUrlVisit $locateVisit; + private ObjectProphecy $ipLocationResolver; + private ObjectProphecy $em; + private ObjectProphecy $logger; + private ObjectProphecy $dbUpdater; + private ObjectProphecy $eventDispatcher; public function setUp(): void { diff --git a/module/Core/test/Exception/IpCannotBeLocatedExceptionTest.php b/module/Core/test/Exception/IpCannotBeLocatedExceptionTest.php index 47246e99..84ee433c 100644 --- a/module/Core/test/Exception/IpCannotBeLocatedExceptionTest.php +++ b/module/Core/test/Exception/IpCannotBeLocatedExceptionTest.php @@ -11,10 +11,6 @@ use Shlinkio\Shlink\Core\Exception\IpCannotBeLocatedException; use Shlinkio\Shlink\Core\Exception\RuntimeException; use Throwable; -use function count; -use function func_get_args; -use function random_int; - class IpCannotBeLocatedExceptionTest extends TestCase { /** @test */ @@ -59,39 +55,4 @@ class IpCannotBeLocatedExceptionTest extends TestCase yield 'Runtime exception with negative code' => [new RuntimeException('Something went wrong', -50)]; yield 'Logic exception with default code' => [new LogicException('Conditions unmet')]; } - - /** - * @test - * @dataProvider provideConstructorArgs - */ - public function constructorInitializesException(): void - { - $args = func_get_args(); - [$isNonLocatableAddress, $message] = $args; - $code = $args[2] ?? 0; - $prev = $args[3] ?? null; - - switch (count($args)) { - case 2: - $e = new IpCannotBeLocatedException($isNonLocatableAddress, $message); - break; - case 3: - $e = new IpCannotBeLocatedException($isNonLocatableAddress, $message, $code); - break; - default: - $e = new IpCannotBeLocatedException($isNonLocatableAddress, $message, $code, $prev); - } - - $this->assertEquals($isNonLocatableAddress, $e->isNonLocatableAddress()); - $this->assertEquals($message, $e->getMessage()); - $this->assertEquals($code, $e->getCode()); - $this->assertEquals($prev, $e->getPrevious()); - } - - public function provideConstructorArgs(): iterable - { - yield 'without default args' => [true, 'Message']; - yield 'without prev' => [true, 'Message', random_int(1, 100)]; - yield 'without all args' => [false, 'Foo', random_int(1, 100), new RuntimeException('Foo')]; - } } diff --git a/module/Core/test/Middleware/QrCodeCacheMiddlewareTest.php b/module/Core/test/Middleware/QrCodeCacheMiddlewareTest.php index a11f9b0d..6bda041f 100644 --- a/module/Core/test/Middleware/QrCodeCacheMiddlewareTest.php +++ b/module/Core/test/Middleware/QrCodeCacheMiddlewareTest.php @@ -16,10 +16,8 @@ use Zend\Diactoros\Uri; class QrCodeCacheMiddlewareTest extends TestCase { - /** @var QrCodeCacheMiddleware */ - private $middleware; - /** @var Cache */ - private $cache; + private QrCodeCacheMiddleware $middleware; + private Cache $cache; public function setUp(): void { diff --git a/module/Core/test/Paginator/Adapter/ShortUrlRepositoryAdapterTest.php b/module/Core/test/Paginator/Adapter/ShortUrlRepositoryAdapterTest.php index 8bf69faf..f5192fde 100644 --- a/module/Core/test/Paginator/Adapter/ShortUrlRepositoryAdapterTest.php +++ b/module/Core/test/Paginator/Adapter/ShortUrlRepositoryAdapterTest.php @@ -13,8 +13,7 @@ use Shlinkio\Shlink\Core\Repository\ShortUrlRepositoryInterface; class ShortUrlRepositoryAdapterTest extends TestCase { - /** @var ObjectProphecy */ - private $repo; + private ObjectProphecy $repo; public function setUp(): void { diff --git a/module/Core/test/Service/ShortUrl/DeleteShortUrlServiceTest.php b/module/Core/test/Service/ShortUrl/DeleteShortUrlServiceTest.php index cbb99c57..b708e465 100644 --- a/module/Core/test/Service/ShortUrl/DeleteShortUrlServiceTest.php +++ b/module/Core/test/Service/ShortUrl/DeleteShortUrlServiceTest.php @@ -23,16 +23,14 @@ use function sprintf; class DeleteShortUrlServiceTest extends TestCase { - /** @var ObjectProphecy */ - private $em; - /** @var string */ - private $shortCode; + private ObjectProphecy $em; + private string $shortCode; public function setUp(): void { - $shortUrl = (new ShortUrl(''))->setVisits(new ArrayCollection(map(range(0, 10), function () { - return new Visit(new ShortUrl(''), Visitor::emptyInstance()); - }))); + $shortUrl = (new ShortUrl(''))->setVisits( + new ArrayCollection(map(range(0, 10), fn () => new Visit(new ShortUrl(''), Visitor::emptyInstance()))) + ); $this->shortCode = $shortUrl->getShortCode(); $this->em = $this->prophesize(EntityManagerInterface::class); diff --git a/module/Core/test/Service/ShortUrlServiceTest.php b/module/Core/test/Service/ShortUrlServiceTest.php index 3dae00a7..d1f8697b 100644 --- a/module/Core/test/Service/ShortUrlServiceTest.php +++ b/module/Core/test/Service/ShortUrlServiceTest.php @@ -21,10 +21,8 @@ use function count; class ShortUrlServiceTest extends TestCase { - /** @var ShortUrlService */ - private $service; - /** @var ObjectProphecy|EntityManagerInterface */ - private $em; + private ShortUrlService $service; + private ObjectProphecy $em; public function setUp(): void { diff --git a/module/Core/test/Service/Tag/TagServiceTest.php b/module/Core/test/Service/Tag/TagServiceTest.php index d7e5b631..b8c9d59b 100644 --- a/module/Core/test/Service/Tag/TagServiceTest.php +++ b/module/Core/test/Service/Tag/TagServiceTest.php @@ -17,10 +17,8 @@ use Shlinkio\Shlink\Core\Service\Tag\TagService; class TagServiceTest extends TestCase { - /** @var TagService */ - private $service; - /** @var ObjectProphecy */ - private $em; + private TagService $service; + private ObjectProphecy $em; public function setUp(): void { diff --git a/module/Core/test/Service/UrlShortenerTest.php b/module/Core/test/Service/UrlShortenerTest.php index 1995c921..9d183381 100644 --- a/module/Core/test/Service/UrlShortenerTest.php +++ b/module/Core/test/Service/UrlShortenerTest.php @@ -27,12 +27,9 @@ use function array_map; class UrlShortenerTest extends TestCase { - /** @var UrlShortener */ - private $urlShortener; - /** @var ObjectProphecy */ - private $em; - /** @var ObjectProphecy */ - private $urlValidator; + private UrlShortener $urlShortener; + private ObjectProphecy $em; + private ObjectProphecy $urlValidator; public function setUp(): void { @@ -47,7 +44,7 @@ class UrlShortenerTest extends TestCase $this->em->beginTransaction()->willReturn(null); $this->em->persist(Argument::any())->will(function ($arguments) { /** @var ShortUrl $shortUrl */ - $shortUrl = $arguments[0]; + [$shortUrl] = $arguments; $shortUrl->setId('10'); }); $repo = $this->prophesize(ShortUrlRepository::class); @@ -243,9 +240,7 @@ class UrlShortenerTest extends TestCase 'validUntil' => Chronos::parse('2017-01-01'), 'maxVisits' => 4, ]); - $tagsCollection = new ArrayCollection(array_map(function (string $tag) { - return new Tag($tag); - }, $tags)); + $tagsCollection = new ArrayCollection(array_map(fn (string $tag) => new Tag($tag), $tags)); $expected = (new ShortUrl($url, $meta))->setTags($tagsCollection); $repo = $this->prophesize(ShortUrlRepository::class); diff --git a/module/Core/test/Service/VisitServiceTest.php b/module/Core/test/Service/VisitServiceTest.php index 3e8d1627..e09b0a4c 100644 --- a/module/Core/test/Service/VisitServiceTest.php +++ b/module/Core/test/Service/VisitServiceTest.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\Core\Service; use Doctrine\ORM\EntityManager; +use Exception; use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; @@ -27,10 +28,8 @@ use function sprintf; class VisitServiceTest extends TestCase { - /** @var VisitService */ - private $visitService; - /** @var ObjectProphecy */ - private $em; + private VisitService $visitService; + private ObjectProphecy $em; public function setUp(): void { @@ -41,9 +40,10 @@ class VisitServiceTest extends TestCase /** @test */ public function locateVisitsIteratesAndLocatesUnlocatedVisits(): void { - $unlocatedVisits = map(range(1, 200), function (int $i) { - return new Visit(new ShortUrl(sprintf('short_code_%s', $i)), Visitor::emptyInstance()); - }); + $unlocatedVisits = map( + range(1, 200), + fn (int $i) => new Visit(new ShortUrl(sprintf('short_code_%s', $i)), Visitor::emptyInstance()) + ); $repo = $this->prophesize(VisitRepository::class); $findUnlocatedVisits = $repo->findUnlocatedVisits(false)->willReturn($unlocatedVisits); @@ -56,9 +56,7 @@ class VisitServiceTest extends TestCase $clear = $this->em->clear()->will(function () { }); - $this->visitService->locateUnlocatedVisits(function () { - return Location::emptyInstance(); - }, function () { + $this->visitService->locateUnlocatedVisits(fn () => Location::emptyInstance(), function () { $args = func_get_args(); $this->assertInstanceOf(VisitLocation::class, array_shift($args)); @@ -94,7 +92,9 @@ class VisitServiceTest extends TestCase }); $this->visitService->locateUnlocatedVisits(function () use ($isNonLocatableAddress) { - throw new IpCannotBeLocatedException($isNonLocatableAddress, 'Cannot be located'); + throw $isNonLocatableAddress + ? new IpCannotBeLocatedException('Cannot be located') + : IpCannotBeLocatedException::forError(new Exception('')); }); $findUnlocatedVisits->shouldHaveBeenCalledOnce(); diff --git a/module/Core/test/Service/VisitsTrackerTest.php b/module/Core/test/Service/VisitsTrackerTest.php index a59429fb..9b9ab948 100644 --- a/module/Core/test/Service/VisitsTrackerTest.php +++ b/module/Core/test/Service/VisitsTrackerTest.php @@ -23,12 +23,9 @@ use Zend\Stdlib\ArrayUtils; class VisitsTrackerTest extends TestCase { - /** @var VisitsTracker */ - private $visitsTracker; - /** @var ObjectProphecy */ - private $em; - /** @var EventDispatcherInterface */ - private $eventDispatcher; + private VisitsTracker $visitsTracker; + private ObjectProphecy $em; + private ObjectProphecy $eventDispatcher; public function setUp(): void { @@ -46,10 +43,7 @@ class VisitsTrackerTest extends TestCase $repo->findOneBy(['shortCode' => $shortCode])->willReturn(new ShortUrl('')); $this->em->getRepository(ShortUrl::class)->willReturn($repo->reveal())->shouldBeCalledOnce(); - $this->em->persist(Argument::that(function (Visit $visit) { - $visit->setId('1'); - return $visit; - }))->shouldBeCalledOnce(); + $this->em->persist(Argument::that(fn (Visit $visit) => $visit->setId('1')))->shouldBeCalledOnce(); $this->em->flush()->shouldBeCalledOnce(); $this->visitsTracker->track($shortCode, Visitor::emptyInstance()); diff --git a/module/Core/test/Transformer/ShortUrlDataTransformerTest.php b/module/Core/test/Transformer/ShortUrlDataTransformerTest.php index 92f2c848..094e09d6 100644 --- a/module/Core/test/Transformer/ShortUrlDataTransformerTest.php +++ b/module/Core/test/Transformer/ShortUrlDataTransformerTest.php @@ -14,8 +14,7 @@ use function random_int; class ShortUrlDataTransformerTest extends TestCase { - /** @var ShortUrlDataTransformer */ - private $transformer; + private ShortUrlDataTransformer $transformer; public function setUp(): void { diff --git a/module/Core/test/Util/UrlValidatorTest.php b/module/Core/test/Util/UrlValidatorTest.php index 3a6880ea..e437c8e7 100644 --- a/module/Core/test/Util/UrlValidatorTest.php +++ b/module/Core/test/Util/UrlValidatorTest.php @@ -17,10 +17,8 @@ use Zend\Diactoros\Response; class UrlValidatorTest extends TestCase { - /** @var UrlValidator */ - private $urlValidator; - /** @var ObjectProphecy */ - private $httpClient; + private UrlValidator $urlValidator; + private ObjectProphecy $httpClient; public function setUp(): void { diff --git a/module/Rest/src/Action/AbstractRestAction.php b/module/Rest/src/Action/AbstractRestAction.php index 8eb9ceb4..826290b7 100644 --- a/module/Rest/src/Action/AbstractRestAction.php +++ b/module/Rest/src/Action/AbstractRestAction.php @@ -17,8 +17,7 @@ abstract class AbstractRestAction implements RequestHandlerInterface, RequestMet protected const ROUTE_PATH = ''; protected const ROUTE_ALLOWED_METHODS = []; - /** @var LoggerInterface */ - protected $logger; + protected LoggerInterface $logger; public function __construct(?LoggerInterface $logger = null) { diff --git a/module/Rest/src/Action/HealthAction.php b/module/Rest/src/Action/HealthAction.php index ac548fde..eeec763d 100644 --- a/module/Rest/src/Action/HealthAction.php +++ b/module/Rest/src/Action/HealthAction.php @@ -21,10 +21,8 @@ class HealthAction extends AbstractRestAction protected const ROUTE_PATH = '/health'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; - /** @var AppOptions */ - private $options; - /** @var Connection */ - private $conn; + private AppOptions $options; + private Connection $conn; public function __construct(Connection $conn, AppOptions $options, ?LoggerInterface $logger = null) { diff --git a/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php b/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php index af392067..d6deae27 100644 --- a/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php @@ -16,10 +16,8 @@ use Zend\Diactoros\Response\JsonResponse; abstract class AbstractCreateShortUrlAction extends AbstractRestAction { - /** @var UrlShortenerInterface */ - private $urlShortener; - /** @var array */ - private $domainConfig; + private UrlShortenerInterface $urlShortener; + private array $domainConfig; public function __construct( UrlShortenerInterface $urlShortener, diff --git a/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php b/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php index ba39ec82..d7a18007 100644 --- a/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php @@ -16,8 +16,7 @@ class DeleteShortUrlAction extends AbstractRestAction protected const ROUTE_PATH = '/short-urls/{shortCode}'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_DELETE]; - /** @var DeleteShortUrlServiceInterface */ - private $deleteShortUrlService; + private DeleteShortUrlServiceInterface $deleteShortUrlService; public function __construct(DeleteShortUrlServiceInterface $deleteShortUrlService, ?LoggerInterface $logger = null) { diff --git a/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php b/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php index 33796f7d..f7c87d0d 100644 --- a/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php @@ -17,8 +17,7 @@ class EditShortUrlAction extends AbstractRestAction protected const ROUTE_PATH = '/short-urls/{shortCode}'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_PATCH, self::METHOD_PUT]; - /** @var ShortUrlServiceInterface */ - private $shortUrlService; + private ShortUrlServiceInterface $shortUrlService; public function __construct(ShortUrlServiceInterface $shortUrlService, ?LoggerInterface $logger = null) { diff --git a/module/Rest/src/Action/ShortUrl/EditShortUrlTagsAction.php b/module/Rest/src/Action/ShortUrl/EditShortUrlTagsAction.php index 208be169..4fe61e4c 100644 --- a/module/Rest/src/Action/ShortUrl/EditShortUrlTagsAction.php +++ b/module/Rest/src/Action/ShortUrl/EditShortUrlTagsAction.php @@ -17,8 +17,7 @@ class EditShortUrlTagsAction extends AbstractRestAction protected const ROUTE_PATH = '/short-urls/{shortCode}/tags'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_PUT]; - /** @var ShortUrlServiceInterface */ - private $shortUrlService; + private ShortUrlServiceInterface $shortUrlService; public function __construct(ShortUrlServiceInterface $shortUrlService, ?LoggerInterface $logger = null) { diff --git a/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php b/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php index 87e7930b..98b48dc5 100644 --- a/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php +++ b/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php @@ -23,10 +23,8 @@ class ListShortUrlsAction extends AbstractRestAction protected const ROUTE_PATH = '/short-urls'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; - /** @var ShortUrlServiceInterface */ - private $shortUrlService; - /** @var array */ - private $domainConfig; + private ShortUrlServiceInterface $shortUrlService; + private array $domainConfig; public function __construct( ShortUrlServiceInterface $shortUrlService, diff --git a/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php b/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php index e041f4dc..5089ff22 100644 --- a/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php @@ -18,10 +18,8 @@ class ResolveShortUrlAction extends AbstractRestAction protected const ROUTE_PATH = '/short-urls/{shortCode}'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; - /** @var UrlShortenerInterface */ - private $urlShortener; - /** @var array */ - private $domainConfig; + private UrlShortenerInterface $urlShortener; + private array $domainConfig; public function __construct( UrlShortenerInterface $urlShortener, diff --git a/module/Rest/src/Action/ShortUrl/SingleStepCreateShortUrlAction.php b/module/Rest/src/Action/ShortUrl/SingleStepCreateShortUrlAction.php index 834c6b12..8a11d1d5 100644 --- a/module/Rest/src/Action/ShortUrl/SingleStepCreateShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/SingleStepCreateShortUrlAction.php @@ -17,8 +17,7 @@ class SingleStepCreateShortUrlAction extends AbstractCreateShortUrlAction protected const ROUTE_PATH = '/short-urls/shorten'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; - /** @var ApiKeyServiceInterface */ - private $apiKeyService; + private ApiKeyServiceInterface $apiKeyService; public function __construct( UrlShortenerInterface $urlShortener, diff --git a/module/Rest/src/Action/Tag/CreateTagsAction.php b/module/Rest/src/Action/Tag/CreateTagsAction.php index c26e274b..645de78d 100644 --- a/module/Rest/src/Action/Tag/CreateTagsAction.php +++ b/module/Rest/src/Action/Tag/CreateTagsAction.php @@ -16,8 +16,7 @@ class CreateTagsAction extends AbstractRestAction protected const ROUTE_PATH = '/tags'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_POST]; - /** @var TagServiceInterface */ - private $tagService; + private TagServiceInterface $tagService; public function __construct(TagServiceInterface $tagService, ?LoggerInterface $logger = null) { diff --git a/module/Rest/src/Action/Tag/DeleteTagsAction.php b/module/Rest/src/Action/Tag/DeleteTagsAction.php index 3d22d8dc..941e51df 100644 --- a/module/Rest/src/Action/Tag/DeleteTagsAction.php +++ b/module/Rest/src/Action/Tag/DeleteTagsAction.php @@ -16,8 +16,7 @@ class DeleteTagsAction extends AbstractRestAction protected const ROUTE_PATH = '/tags'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_DELETE]; - /** @var TagServiceInterface */ - private $tagService; + private TagServiceInterface $tagService; public function __construct(TagServiceInterface $tagService, ?LoggerInterface $logger = null) { diff --git a/module/Rest/src/Action/Tag/ListTagsAction.php b/module/Rest/src/Action/Tag/ListTagsAction.php index 22c85fb1..78f507e6 100644 --- a/module/Rest/src/Action/Tag/ListTagsAction.php +++ b/module/Rest/src/Action/Tag/ListTagsAction.php @@ -16,8 +16,7 @@ class ListTagsAction extends AbstractRestAction protected const ROUTE_PATH = '/tags'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; - /** @var TagServiceInterface */ - private $tagService; + private TagServiceInterface $tagService; public function __construct(TagServiceInterface $tagService, ?LoggerInterface $logger = null) { diff --git a/module/Rest/src/Action/Tag/UpdateTagAction.php b/module/Rest/src/Action/Tag/UpdateTagAction.php index 175ed0a0..b1a3a4b6 100644 --- a/module/Rest/src/Action/Tag/UpdateTagAction.php +++ b/module/Rest/src/Action/Tag/UpdateTagAction.php @@ -17,8 +17,7 @@ class UpdateTagAction extends AbstractRestAction protected const ROUTE_PATH = '/tags'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_PUT]; - /** @var TagServiceInterface */ - private $tagService; + private TagServiceInterface $tagService; public function __construct(TagServiceInterface $tagService, ?LoggerInterface $logger = null) { diff --git a/module/Rest/src/Action/Visit/GetVisitsAction.php b/module/Rest/src/Action/Visit/GetVisitsAction.php index ca8c2838..7483f9d2 100644 --- a/module/Rest/src/Action/Visit/GetVisitsAction.php +++ b/module/Rest/src/Action/Visit/GetVisitsAction.php @@ -20,8 +20,7 @@ class GetVisitsAction extends AbstractRestAction protected const ROUTE_PATH = '/short-urls/{shortCode}/visits'; protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; - /** @var VisitsTrackerInterface */ - private $visitsTracker; + private VisitsTrackerInterface $visitsTracker; public function __construct(VisitsTrackerInterface $visitsTracker, ?LoggerInterface $logger = null) { diff --git a/module/Rest/src/Authentication/Plugin/ApiKeyHeaderPlugin.php b/module/Rest/src/Authentication/Plugin/ApiKeyHeaderPlugin.php index 14735f9a..bf28748f 100644 --- a/module/Rest/src/Authentication/Plugin/ApiKeyHeaderPlugin.php +++ b/module/Rest/src/Authentication/Plugin/ApiKeyHeaderPlugin.php @@ -13,8 +13,7 @@ class ApiKeyHeaderPlugin implements AuthenticationPluginInterface { public const HEADER_NAME = 'X-Api-Key'; - /** @var ApiKeyServiceInterface */ - private $apiKeyService; + private ApiKeyServiceInterface $apiKeyService; public function __construct(ApiKeyServiceInterface $apiKeyService) { diff --git a/module/Rest/src/Authentication/RequestToHttpAuthPlugin.php b/module/Rest/src/Authentication/RequestToHttpAuthPlugin.php index c10c0321..bb6454b2 100644 --- a/module/Rest/src/Authentication/RequestToHttpAuthPlugin.php +++ b/module/Rest/src/Authentication/RequestToHttpAuthPlugin.php @@ -20,8 +20,7 @@ class RequestToHttpAuthPlugin implements RequestToHttpAuthPluginInterface Plugin\AuthorizationHeaderPlugin::HEADER_NAME, ]; - /** @var AuthenticationPluginManagerInterface */ - private $authPluginManager; + private AuthenticationPluginManagerInterface $authPluginManager; public function __construct(AuthenticationPluginManagerInterface $authPluginManager) { @@ -44,9 +43,7 @@ class RequestToHttpAuthPlugin implements RequestToHttpAuthPluginInterface { return array_reduce( self::SUPPORTED_AUTH_HEADERS, - function (bool $carry, string $header) use ($request) { - return $carry || $request->hasHeader($header); - }, + fn (bool $carry, string $header) => $carry || $request->hasHeader($header), false ); } diff --git a/module/Rest/src/ConfigProvider.php b/module/Rest/src/ConfigProvider.php index 0c0e99a5..8624ad66 100644 --- a/module/Rest/src/ConfigProvider.php +++ b/module/Rest/src/ConfigProvider.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Rest; +use Closure; + use function Shlinkio\Shlink\Common\loadConfigFromGlob; use function sprintf; @@ -11,14 +13,11 @@ class ConfigProvider { private const ROUTES_PREFIX = '/rest/v{version:1|2}'; - /** @var callable */ - private $loadConfig; + private Closure $loadConfig; public function __construct(?callable $loadConfig = null) { - $this->loadConfig = $loadConfig ?? function (string $glob) { - return loadConfigFromGlob($glob); - }; + $this->loadConfig = Closure::fromCallable($loadConfig ?? fn (string $glob) => loadConfigFromGlob($glob)); } public function __invoke() diff --git a/module/Rest/src/Entity/ApiKey.php b/module/Rest/src/Entity/ApiKey.php index 887768d1..8c6d3aeb 100644 --- a/module/Rest/src/Entity/ApiKey.php +++ b/module/Rest/src/Entity/ApiKey.php @@ -12,12 +12,9 @@ class ApiKey extends AbstractEntity { use StringUtilsTrait; - /** @var string */ - private $key; - /** @var Chronos|null */ - private $expirationDate; - /** @var bool */ - private $enabled; + private string $key; + private ?Chronos $expirationDate; + private bool $enabled; public function __construct(?Chronos $expirationDate = null) { diff --git a/module/Rest/src/Middleware/AuthenticationMiddleware.php b/module/Rest/src/Middleware/AuthenticationMiddleware.php index 4fd44bcf..caa2a6f4 100644 --- a/module/Rest/src/Middleware/AuthenticationMiddleware.php +++ b/module/Rest/src/Middleware/AuthenticationMiddleware.php @@ -17,10 +17,8 @@ use function Functional\contains; class AuthenticationMiddleware implements MiddlewareInterface, StatusCodeInterface, RequestMethodInterface { - /** @var array */ - private $routesWhitelist; - /** @var RequestToHttpAuthPluginInterface */ - private $requestToAuthPlugin; + private array $routesWhitelist; + private RequestToHttpAuthPluginInterface $requestToAuthPlugin; public function __construct(RequestToHttpAuthPluginInterface $requestToAuthPlugin, array $routesWhitelist) { diff --git a/module/Rest/src/Middleware/BackwardsCompatibleProblemDetailsMiddleware.php b/module/Rest/src/Middleware/BackwardsCompatibleProblemDetailsMiddleware.php index 0812c7e0..65bd12b0 100644 --- a/module/Rest/src/Middleware/BackwardsCompatibleProblemDetailsMiddleware.php +++ b/module/Rest/src/Middleware/BackwardsCompatibleProblemDetailsMiddleware.php @@ -22,10 +22,8 @@ class BackwardsCompatibleProblemDetailsMiddleware implements MiddlewareInterface 'message' => 'detail', ]; - /** @var array */ - private $defaultTypeFallbacks; - /** @var int */ - private $jsonFlags; + private array $defaultTypeFallbacks; + private int $jsonFlags; public function __construct(array $defaultTypeFallbacks, int $jsonFlags) { diff --git a/module/Rest/src/Middleware/EmptyResponseImplicitOptionsMiddlewareFactory.php b/module/Rest/src/Middleware/EmptyResponseImplicitOptionsMiddlewareFactory.php index 06cdc435..5075e244 100644 --- a/module/Rest/src/Middleware/EmptyResponseImplicitOptionsMiddlewareFactory.php +++ b/module/Rest/src/Middleware/EmptyResponseImplicitOptionsMiddlewareFactory.php @@ -11,8 +11,6 @@ class EmptyResponseImplicitOptionsMiddlewareFactory { public function __invoke() { - return new ImplicitOptionsMiddleware(function () { - return new EmptyResponse(); - }); + return new ImplicitOptionsMiddleware(fn () => new EmptyResponse()); } } diff --git a/module/Rest/src/Service/ApiKeyService.php b/module/Rest/src/Service/ApiKeyService.php index 030957fd..baa545c0 100644 --- a/module/Rest/src/Service/ApiKeyService.php +++ b/module/Rest/src/Service/ApiKeyService.php @@ -13,8 +13,7 @@ use function sprintf; class ApiKeyService implements ApiKeyServiceInterface { - /** @var EntityManagerInterface */ - private $em; + private EntityManagerInterface $em; public function __construct(EntityManagerInterface $em) { diff --git a/module/Rest/test-api/Action/CreateShortUrlActionTest.php b/module/Rest/test-api/Action/CreateShortUrlActionTest.php index 37a2630c..efff5f33 100644 --- a/module/Rest/test-api/Action/CreateShortUrlActionTest.php +++ b/module/Rest/test-api/Action/CreateShortUrlActionTest.php @@ -91,9 +91,7 @@ class CreateShortUrlActionTest extends ApiTestCase public function provideMaxVisits(): array { - return map(range(10, 15), function (int $i) { - return [$i]; - }); + return map(range(10, 15), fn (int $i) => [$i]); } /** @test */ diff --git a/module/Rest/test/Action/AuthenticateActionTest.php b/module/Rest/test/Action/AuthenticateActionTest.php index eb4ca6dc..84aa8fbe 100644 --- a/module/Rest/test/Action/AuthenticateActionTest.php +++ b/module/Rest/test/Action/AuthenticateActionTest.php @@ -15,6 +15,7 @@ use Zend\Diactoros\ServerRequest; use function strpos; +/** @deprecated */ class AuthenticateActionTest extends TestCase { /** @var AuthenticateAction */ diff --git a/module/Rest/test/Action/HealthActionTest.php b/module/Rest/test/Action/HealthActionTest.php index a52b7d5e..23d7dd88 100644 --- a/module/Rest/test/Action/HealthActionTest.php +++ b/module/Rest/test/Action/HealthActionTest.php @@ -15,10 +15,8 @@ use Zend\Diactoros\ServerRequest; class HealthActionTest extends TestCase { - /** @var HealthAction */ - private $action; - /** @var ObjectProphecy */ - private $conn; + private HealthAction $action; + private ObjectProphecy $conn; public function setUp(): void { diff --git a/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php index 37f737f9..5dd76142 100644 --- a/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php @@ -26,10 +26,8 @@ class CreateShortUrlActionTest extends TestCase 'hostname' => 'foo.com', ]; - /** @var CreateShortUrlAction */ - private $action; - /** @var ObjectProphecy */ - private $urlShortener; + private CreateShortUrlAction $action; + private ObjectProphecy $urlShortener; public function setUp(): void { diff --git a/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php index 782181ce..df0cde37 100644 --- a/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php @@ -13,10 +13,8 @@ use Zend\Diactoros\ServerRequest; class DeleteShortUrlActionTest extends TestCase { - /** @var DeleteShortUrlAction */ - private $action; - /** @var ObjectProphecy */ - private $service; + private DeleteShortUrlAction $action; + private ObjectProphecy $service; public function setUp(): void { diff --git a/module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php index ff86117e..e85c2f04 100644 --- a/module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php @@ -15,10 +15,8 @@ use Zend\Diactoros\ServerRequest; class EditShortUrlActionTest extends TestCase { - /** @var EditShortUrlAction */ - private $action; - /** @var ObjectProphecy */ - private $shortUrlService; + private EditShortUrlAction $action; + private ObjectProphecy $shortUrlService; public function setUp(): void { diff --git a/module/Rest/test/Action/ShortUrl/EditShortUrlTagsActionTest.php b/module/Rest/test/Action/ShortUrl/EditShortUrlTagsActionTest.php index 17293f05..e8a398fb 100644 --- a/module/Rest/test/Action/ShortUrl/EditShortUrlTagsActionTest.php +++ b/module/Rest/test/Action/ShortUrl/EditShortUrlTagsActionTest.php @@ -14,10 +14,8 @@ use Zend\Diactoros\ServerRequest; class EditShortUrlTagsActionTest extends TestCase { - /** @var EditShortUrlTagsAction */ - private $action; - /** @var ObjectProphecy */ - private $shortUrlService; + private EditShortUrlTagsAction $action; + private ObjectProphecy $shortUrlService; public function setUp(): void { diff --git a/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php b/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php index 1dfdc258..1e083eb9 100644 --- a/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php +++ b/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php @@ -18,12 +18,9 @@ use Zend\Paginator\Paginator; class ListShortUrlsActionTest extends TestCase { - /** @var ListShortUrlsAction */ - private $action; - /** @var ObjectProphecy */ - private $service; - /** @var ObjectProphecy */ - private $logger; + private ListShortUrlsAction $action; + private ObjectProphecy $service; + private ObjectProphecy $logger; public function setUp(): void { diff --git a/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php index b77a6e45..3fcc8e75 100644 --- a/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php @@ -15,10 +15,8 @@ use function strpos; class ResolveShortUrlActionTest extends TestCase { - /** @var ResolveShortUrlAction */ - private $action; - /** @var ObjectProphecy */ - private $urlShortener; + private ResolveShortUrlAction $action; + private ObjectProphecy $urlShortener; public function setUp(): void { diff --git a/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php index b0d8c65d..fe95b6ea 100644 --- a/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php @@ -19,12 +19,9 @@ use Zend\Diactoros\ServerRequest; class SingleStepCreateShortUrlActionTest extends TestCase { - /** @var SingleStepCreateShortUrlAction */ - private $action; - /** @var ObjectProphecy */ - private $urlShortener; - /** @var ObjectProphecy */ - private $apiKeyService; + private SingleStepCreateShortUrlAction $action; + private ObjectProphecy $urlShortener; + private ObjectProphecy $apiKeyService; public function setUp(): void { diff --git a/module/Rest/test/Action/Tag/CreateTagsActionTest.php b/module/Rest/test/Action/Tag/CreateTagsActionTest.php index c210d97c..e87dc163 100644 --- a/module/Rest/test/Action/Tag/CreateTagsActionTest.php +++ b/module/Rest/test/Action/Tag/CreateTagsActionTest.php @@ -13,10 +13,8 @@ use Zend\Diactoros\ServerRequest; class CreateTagsActionTest extends TestCase { - /** @var CreateTagsAction */ - private $action; - /** @var ObjectProphecy */ - private $tagService; + private CreateTagsAction $action; + private ObjectProphecy $tagService; public function setUp(): void { diff --git a/module/Rest/test/Action/Tag/DeleteTagsActionTest.php b/module/Rest/test/Action/Tag/DeleteTagsActionTest.php index 69df8938..98535056 100644 --- a/module/Rest/test/Action/Tag/DeleteTagsActionTest.php +++ b/module/Rest/test/Action/Tag/DeleteTagsActionTest.php @@ -12,10 +12,8 @@ use Zend\Diactoros\ServerRequest; class DeleteTagsActionTest extends TestCase { - /** @var DeleteTagsAction */ - private $action; - /** @var ObjectProphecy */ - private $tagService; + private DeleteTagsAction $action; + private ObjectProphecy $tagService; public function setUp(): void { diff --git a/module/Rest/test/Action/Tag/ListTagsActionTest.php b/module/Rest/test/Action/Tag/ListTagsActionTest.php index 03546fdb..5209ba02 100644 --- a/module/Rest/test/Action/Tag/ListTagsActionTest.php +++ b/module/Rest/test/Action/Tag/ListTagsActionTest.php @@ -15,10 +15,8 @@ use function Shlinkio\Shlink\Common\json_decode; class ListTagsActionTest extends TestCase { - /** @var ListTagsAction */ - private $action; - /** @var ObjectProphecy */ - private $tagService; + private ListTagsAction $action; + private ObjectProphecy $tagService; public function setUp(): void { diff --git a/module/Rest/test/Action/Tag/UpdateTagActionTest.php b/module/Rest/test/Action/Tag/UpdateTagActionTest.php index 3b068add..2a050c6c 100644 --- a/module/Rest/test/Action/Tag/UpdateTagActionTest.php +++ b/module/Rest/test/Action/Tag/UpdateTagActionTest.php @@ -14,10 +14,8 @@ use Zend\Diactoros\ServerRequest; class UpdateTagActionTest extends TestCase { - /** @var UpdateTagAction */ - private $action; - /** @var ObjectProphecy */ - private $tagService; + private UpdateTagAction $action; + private ObjectProphecy $tagService; public function setUp(): void { diff --git a/module/Rest/test/Action/Visit/GetVisitsActionTest.php b/module/Rest/test/Action/Visit/GetVisitsActionTest.php index 80e06085..767d095c 100644 --- a/module/Rest/test/Action/Visit/GetVisitsActionTest.php +++ b/module/Rest/test/Action/Visit/GetVisitsActionTest.php @@ -18,10 +18,8 @@ use Zend\Paginator\Paginator; class GetVisitsActionTest extends TestCase { - /** @var GetVisitsAction */ - private $action; - /** @var ObjectProphecy */ - private $visitsTracker; + private GetVisitsAction $action; + private ObjectProphecy $visitsTracker; public function setUp(): void { diff --git a/module/Rest/test/Authentication/AuthenticationPluginManagerFactoryTest.php b/module/Rest/test/Authentication/AuthenticationPluginManagerFactoryTest.php index 15beefc0..4c24e26a 100644 --- a/module/Rest/test/Authentication/AuthenticationPluginManagerFactoryTest.php +++ b/module/Rest/test/Authentication/AuthenticationPluginManagerFactoryTest.php @@ -12,8 +12,7 @@ use Zend\ServiceManager\ServiceManager; class AuthenticationPluginManagerFactoryTest extends TestCase { - /** @var AuthenticationPluginManagerFactory */ - private $factory; + private AuthenticationPluginManagerFactory $factory; public function setUp(): void { @@ -35,9 +34,7 @@ class AuthenticationPluginManagerFactoryTest extends TestCase private function getPlugins(AuthenticationPluginManager $pluginManager): array { - return (function () { - return $this->services; - })->call($pluginManager); + return (fn () => $this->services)->call($pluginManager); } public function provideConfigs(): iterable diff --git a/module/Rest/test/Authentication/JWTServiceTest.php b/module/Rest/test/Authentication/JWTServiceTest.php index ab416ca0..76375fdc 100644 --- a/module/Rest/test/Authentication/JWTServiceTest.php +++ b/module/Rest/test/Authentication/JWTServiceTest.php @@ -13,6 +13,7 @@ use Shlinkio\Shlink\Rest\Exception\AuthenticationException; use function time; +/** @deprecated */ class JWTServiceTest extends TestCase { /** @var JWTService */ diff --git a/module/Rest/test/Authentication/Plugin/ApiKeyHeaderPluginTest.php b/module/Rest/test/Authentication/Plugin/ApiKeyHeaderPluginTest.php index 65cedcfc..36210918 100644 --- a/module/Rest/test/Authentication/Plugin/ApiKeyHeaderPluginTest.php +++ b/module/Rest/test/Authentication/Plugin/ApiKeyHeaderPluginTest.php @@ -15,10 +15,8 @@ use Zend\Diactoros\ServerRequest; class ApiKeyHeaderPluginTest extends TestCase { - /** @var ApiKeyHeaderPlugin */ - private $plugin; - /** @var ObjectProphecy */ - private $apiKeyService; + private ApiKeyHeaderPlugin $plugin; + private ObjectProphecy $apiKeyService; public function setUp(): void { diff --git a/module/Rest/test/Authentication/Plugin/AuthorizationHeaderPluginTest.php b/module/Rest/test/Authentication/Plugin/AuthorizationHeaderPluginTest.php index 0bd03e8a..71d6eb20 100644 --- a/module/Rest/test/Authentication/Plugin/AuthorizationHeaderPluginTest.php +++ b/module/Rest/test/Authentication/Plugin/AuthorizationHeaderPluginTest.php @@ -14,6 +14,7 @@ use Zend\Diactoros\ServerRequest; use function sprintf; +/** @deprecated */ class AuthorizationHeaderPluginTest extends TestCase { /** @var AuthorizationHeaderPlugin */ diff --git a/module/Rest/test/Authentication/RequestToAuthPluginTest.php b/module/Rest/test/Authentication/RequestToAuthPluginTest.php index a49a4e19..d4de01a8 100644 --- a/module/Rest/test/Authentication/RequestToAuthPluginTest.php +++ b/module/Rest/test/Authentication/RequestToAuthPluginTest.php @@ -19,10 +19,8 @@ use function sprintf; class RequestToAuthPluginTest extends TestCase { - /** @var RequestToHttpAuthPlugin */ - private $requestToPlugin; - /** @var ObjectProphecy */ - private $pluginManager; + private RequestToHttpAuthPlugin $requestToPlugin; + private ObjectProphecy $pluginManager; public function setUp(): void { diff --git a/module/Rest/test/ConfigProviderTest.php b/module/Rest/test/ConfigProviderTest.php index 2922faad..b8cebf93 100644 --- a/module/Rest/test/ConfigProviderTest.php +++ b/module/Rest/test/ConfigProviderTest.php @@ -9,8 +9,7 @@ use Shlinkio\Shlink\Rest\ConfigProvider; class ConfigProviderTest extends TestCase { - /** @var ConfigProvider */ - private $configProvider; + private ConfigProvider $configProvider; public function setUp(): void { @@ -29,15 +28,13 @@ class ConfigProviderTest extends TestCase /** @test */ public function routesAreProperlyPrefixed(): void { - $configProvider = new ConfigProvider(function () { - return [ - 'routes' => [ - ['path' => '/foo'], - ['path' => '/bar'], - ['path' => '/baz/foo'], - ], - ]; - }); + $configProvider = new ConfigProvider(fn () => [ + 'routes' => [ + ['path' => '/foo'], + ['path' => '/bar'], + ['path' => '/baz/foo'], + ], + ]); $config = $configProvider(); diff --git a/module/Rest/test/EventDispatcher/NotifyVisitToWebHooksTest.php b/module/Rest/test/EventDispatcher/NotifyVisitToWebHooksTest.php index 305f2e23..bb043e66 100644 --- a/module/Rest/test/EventDispatcher/NotifyVisitToWebHooksTest.php +++ b/module/Rest/test/EventDispatcher/NotifyVisitToWebHooksTest.php @@ -28,12 +28,9 @@ use function Functional\contains; class NotifyVisitToWebHooksTest extends TestCase { - /** @var ObjectProphecy */ - private $httpClient; - /** @var ObjectProphecy */ - private $em; - /** @var ObjectProphecy */ - private $logger; + private ObjectProphecy $httpClient; + private ObjectProphecy $em; + private ObjectProphecy $logger; public function setUp(): void { diff --git a/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php b/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php index 36dfaeee..8bef98a1 100644 --- a/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php +++ b/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php @@ -26,12 +26,9 @@ use function Zend\Stratigility\middleware; class AuthenticationMiddlewareTest extends TestCase { - /** @var AuthenticationMiddleware */ - private $middleware; - /** @var ObjectProphecy */ - private $requestToPlugin; - /** @var ObjectProphecy */ - private $logger; + private AuthenticationMiddleware $middleware; + private ObjectProphecy $requestToPlugin; + private ObjectProphecy $logger; public function setUp(): void { @@ -112,8 +109,6 @@ class AuthenticationMiddlewareTest extends TestCase private function getDummyMiddleware(): MiddlewareInterface { - return middleware(function () { - return new Response\EmptyResponse(); - }); + return middleware(fn () => new Response\EmptyResponse()); } } diff --git a/module/Rest/test/Middleware/BackwardsCompatibleProblemDetailsMiddlewareTest.php b/module/Rest/test/Middleware/BackwardsCompatibleProblemDetailsMiddlewareTest.php index 4d47c4cb..5f58e7eb 100644 --- a/module/Rest/test/Middleware/BackwardsCompatibleProblemDetailsMiddlewareTest.php +++ b/module/Rest/test/Middleware/BackwardsCompatibleProblemDetailsMiddlewareTest.php @@ -14,10 +14,8 @@ use Zend\Diactoros\Uri; class BackwardsCompatibleProblemDetailsMiddlewareTest extends TestCase { - /** @var BackwardsCompatibleProblemDetailsMiddleware */ - private $middleware; - /** @var ObjectProphecy */ - private $handler; + private BackwardsCompatibleProblemDetailsMiddleware $middleware; + private ObjectProphecy $handler; public function setUp(): void { diff --git a/module/Rest/test/Middleware/BodyParserMiddlewareTest.php b/module/Rest/test/Middleware/BodyParserMiddlewareTest.php index 829b4b59..ba8f27ef 100644 --- a/module/Rest/test/Middleware/BodyParserMiddlewareTest.php +++ b/module/Rest/test/Middleware/BodyParserMiddlewareTest.php @@ -18,8 +18,7 @@ use function array_shift; class BodyParserMiddlewareTest extends TestCase { - /** @var BodyParserMiddleware */ - private $middleware; + private BodyParserMiddleware $middleware; public function setUp(): void { diff --git a/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php b/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php index 1716c19e..735338ca 100644 --- a/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php +++ b/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php @@ -20,10 +20,8 @@ use function Zend\Stratigility\middleware; class CrossDomainMiddlewareTest extends TestCase { - /** @var CrossDomainMiddleware */ - private $middleware; - /** @var ObjectProphecy */ - private $handler; + private CrossDomainMiddleware $middleware; + private ObjectProphecy $handler; public function setUp(): void { diff --git a/module/Rest/test/Middleware/EmptyResponseImplicitOptionsMiddlewareFactoryTest.php b/module/Rest/test/Middleware/EmptyResponseImplicitOptionsMiddlewareFactoryTest.php index 23dc7983..fed1e1f8 100644 --- a/module/Rest/test/Middleware/EmptyResponseImplicitOptionsMiddlewareFactoryTest.php +++ b/module/Rest/test/Middleware/EmptyResponseImplicitOptionsMiddlewareFactoryTest.php @@ -12,8 +12,7 @@ use Zend\Expressive\Router\Middleware\ImplicitOptionsMiddleware; class EmptyResponseImplicitOptionsMiddlewareFactoryTest extends TestCase { - /** @var EmptyResponseImplicitOptionsMiddlewareFactory */ - private $factory; + private EmptyResponseImplicitOptionsMiddlewareFactory $factory; public function setUp(): void { diff --git a/module/Rest/test/Middleware/PathVersionMiddlewareTest.php b/module/Rest/test/Middleware/PathVersionMiddlewareTest.php index 887b8fbf..98e6698d 100644 --- a/module/Rest/test/Middleware/PathVersionMiddlewareTest.php +++ b/module/Rest/test/Middleware/PathVersionMiddlewareTest.php @@ -18,8 +18,7 @@ use function array_shift; class PathVersionMiddlewareTest extends TestCase { - /** @var PathVersionMiddleware */ - private $middleware; + private PathVersionMiddleware $middleware; public function setUp(): void { @@ -27,7 +26,7 @@ class PathVersionMiddlewareTest extends TestCase } /** @test */ - public function whenVersionIsProvidedRequestRemainsUnchanged() + public function whenVersionIsProvidedRequestRemainsUnchanged(): void { $request = (new ServerRequest())->withUri(new Uri('/v2/foo')); @@ -40,7 +39,7 @@ class PathVersionMiddlewareTest extends TestCase } /** @test */ - public function versionOneIsPrependedWhenNoVersionIsDefined() + public function versionOneIsPrependedWhenNoVersionIsDefined(): void { $request = (new ServerRequest())->withUri(new Uri('/bar/baz')); diff --git a/module/Rest/test/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddlewareTest.php b/module/Rest/test/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddlewareTest.php index 83903b82..bfcb2bcc 100644 --- a/module/Rest/test/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddlewareTest.php +++ b/module/Rest/test/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddlewareTest.php @@ -6,6 +6,7 @@ namespace ShlinkioTest\Shlink\Rest\Middleware\ShortUrl; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\Prophecy\ObjectProphecy; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use Shlinkio\Shlink\Rest\Middleware\ShortUrl\CreateShortUrlContentNegotiationMiddleware; @@ -15,10 +16,8 @@ use Zend\Diactoros\ServerRequest; class CreateShortUrlContentNegotiationMiddlewareTest extends TestCase { - /** @var CreateShortUrlContentNegotiationMiddleware */ - private $middleware; - /** @var RequestHandlerInterface */ - private $requestHandler; + private CreateShortUrlContentNegotiationMiddleware $middleware; + private ObjectProphecy $requestHandler; public function setUp(): void {