Added property types to some classes

This commit is contained in:
Alejandro Celaya 2019-12-29 22:27:00 +01:00
parent 050050a9eb
commit b904c6d00d
86 changed files with 218 additions and 457 deletions

View file

@ -60,7 +60,7 @@
"devster/ubench": "^2.0", "devster/ubench": "^2.0",
"eaglewu/swoole-ide-helper": "dev-master", "eaglewu/swoole-ide-helper": "dev-master",
"infection/infection": "^0.15.0", "infection/infection": "^0.15.0",
"phpstan/phpstan-shim": "^0.11.16", "phpstan/phpstan": "^0.12.3",
"phpunit/phpunit": "^8.3", "phpunit/phpunit": "^8.3",
"roave/security-advisories": "dev-master", "roave/security-advisories": "dev-master",
"shlinkio/php-coding-standard": "~2.0.0", "shlinkio/php-coding-standard": "~2.0.0",

View file

@ -19,8 +19,7 @@ class DisableKeyCommand extends Command
{ {
public const NAME = 'api-key:disable'; public const NAME = 'api-key:disable';
/** @var ApiKeyServiceInterface */ private ApiKeyServiceInterface $apiKeyService;
private $apiKeyService;
public function __construct(ApiKeyServiceInterface $apiKeyService) public function __construct(ApiKeyServiceInterface $apiKeyService)
{ {

View file

@ -19,8 +19,7 @@ class GenerateKeyCommand extends Command
{ {
public const NAME = 'api-key:generate'; public const NAME = 'api-key:generate';
/** @var ApiKeyServiceInterface */ private ApiKeyServiceInterface $apiKeyService;
private $apiKeyService;
public function __construct(ApiKeyServiceInterface $apiKeyService) public function __construct(ApiKeyServiceInterface $apiKeyService)
{ {

View file

@ -25,8 +25,7 @@ class ListKeysCommand extends Command
public const NAME = 'api-key:list'; public const NAME = 'api-key:list';
/** @var ApiKeyServiceInterface */ private ApiKeyServiceInterface $apiKeyService;
private $apiKeyService;
public function __construct(ApiKeyServiceInterface $apiKeyService) public function __construct(ApiKeyServiceInterface $apiKeyService)
{ {

View file

@ -15,10 +15,8 @@ use function array_unshift;
abstract class AbstractDatabaseCommand extends AbstractLockedCommand abstract class AbstractDatabaseCommand extends AbstractLockedCommand
{ {
/** @var ProcessHelper */ private ProcessHelper $processHelper;
private $processHelper; private string $phpBinary;
/** @var string */
private $phpBinary;
public function __construct(LockFactory $locker, ProcessHelper $processHelper, PhpExecutableFinder $phpFinder) public function __construct(LockFactory $locker, ProcessHelper $processHelper, PhpExecutableFinder $phpFinder)
{ {

View file

@ -21,10 +21,8 @@ class CreateDatabaseCommand extends AbstractDatabaseCommand
public const DOCTRINE_SCRIPT = 'vendor/doctrine/orm/bin/doctrine.php'; public const DOCTRINE_SCRIPT = 'vendor/doctrine/orm/bin/doctrine.php';
public const DOCTRINE_CREATE_SCHEMA_COMMAND = 'orm:schema-tool:create'; public const DOCTRINE_CREATE_SCHEMA_COMMAND = 'orm:schema-tool:create';
/** @var Connection */ private Connection $regularConn;
private $regularConn; private Connection $noDbNameConn;
/** @var Connection */
private $noDbNameConn;
public function __construct( public function __construct(
LockFactory $locker, LockFactory $locker,

View file

@ -21,8 +21,7 @@ class DeleteShortUrlCommand extends Command
public const NAME = 'short-url:delete'; public const NAME = 'short-url:delete';
private const ALIASES = ['short-code:delete']; private const ALIASES = ['short-code:delete'];
/** @var DeleteShortUrlServiceInterface */ private DeleteShortUrlServiceInterface $deleteShortUrlService;
private $deleteShortUrlService;
public function __construct(DeleteShortUrlServiceInterface $deleteShortUrlService) public function __construct(DeleteShortUrlServiceInterface $deleteShortUrlService)
{ {

View file

@ -28,10 +28,8 @@ class GenerateShortUrlCommand extends Command
public const NAME = 'short-url:generate'; public const NAME = 'short-url:generate';
private const ALIASES = ['shortcode:generate', 'short-code:generate']; private const ALIASES = ['shortcode:generate', 'short-code:generate'];
/** @var UrlShortenerInterface */ private UrlShortenerInterface $urlShortener;
private $urlShortener; private array $domainConfig;
/** @var array */
private $domainConfig;
public function __construct(UrlShortenerInterface $urlShortener, array $domainConfig) public function __construct(UrlShortenerInterface $urlShortener, array $domainConfig)
{ {

View file

@ -24,8 +24,7 @@ class GetVisitsCommand extends AbstractWithDateRangeCommand
public const NAME = 'short-url:visits'; public const NAME = 'short-url:visits';
private const ALIASES = ['shortcode:visits', 'short-code:visits']; private const ALIASES = ['shortcode:visits', 'short-code:visits'];
/** @var VisitsTrackerInterface */ private VisitsTrackerInterface $visitsTracker;
private $visitsTracker;
public function __construct(VisitsTrackerInterface $visitsTracker) public function __construct(VisitsTrackerInterface $visitsTracker)
{ {

View file

@ -42,10 +42,8 @@ class ListShortUrlsCommand extends AbstractWithDateRangeCommand
'tags', 'tags',
]; ];
/** @var ShortUrlServiceInterface */ private ShortUrlServiceInterface $shortUrlService;
private $shortUrlService; private ShortUrlDataTransformer $transformer;
/** @var ShortUrlDataTransformer */
private $transformer;
public function __construct(ShortUrlServiceInterface $shortUrlService, array $domainConfig) public function __construct(ShortUrlServiceInterface $shortUrlService, array $domainConfig)
{ {

View file

@ -21,8 +21,7 @@ class ResolveUrlCommand extends Command
public const NAME = 'short-url:parse'; public const NAME = 'short-url:parse';
private const ALIASES = ['shortcode:parse', 'short-code:parse']; private const ALIASES = ['shortcode:parse', 'short-code:parse'];
/** @var UrlShortenerInterface */ private UrlShortenerInterface $urlShortener;
private $urlShortener;
public function __construct(UrlShortenerInterface $urlShortener) public function __construct(UrlShortenerInterface $urlShortener)
{ {

View file

@ -16,8 +16,7 @@ class CreateTagCommand extends Command
{ {
public const NAME = 'tag:create'; public const NAME = 'tag:create';
/** @var TagServiceInterface */ private TagServiceInterface $tagService;
private $tagService;
public function __construct(TagServiceInterface $tagService) public function __construct(TagServiceInterface $tagService)
{ {

View file

@ -16,8 +16,7 @@ class DeleteTagsCommand extends Command
{ {
public const NAME = 'tag:delete'; public const NAME = 'tag:delete';
/** @var TagServiceInterface */ private TagServiceInterface $tagService;
private $tagService;
public function __construct(TagServiceInterface $tagService) public function __construct(TagServiceInterface $tagService)
{ {

View file

@ -18,8 +18,7 @@ class ListTagsCommand extends Command
{ {
public const NAME = 'tag:list'; public const NAME = 'tag:list';
/** @var TagServiceInterface */ private TagServiceInterface $tagService;
private $tagService;
public function __construct(TagServiceInterface $tagService) public function __construct(TagServiceInterface $tagService)
{ {

View file

@ -18,8 +18,7 @@ class RenameTagCommand extends Command
{ {
public const NAME = 'tag:rename'; public const NAME = 'tag:rename';
/** @var TagServiceInterface */ private TagServiceInterface $tagService;
private $tagService;
public function __construct(TagServiceInterface $tagService) public function __construct(TagServiceInterface $tagService)
{ {

View file

@ -14,8 +14,7 @@ use function sprintf;
abstract class AbstractLockedCommand extends Command abstract class AbstractLockedCommand extends Command
{ {
/** @var LockFactory */ private LockFactory $locker;
private $locker;
public function __construct(LockFactory $locker) public function __construct(LockFactory $locker)
{ {

View file

@ -8,12 +8,9 @@ final class LockedCommandConfig
{ {
private const DEFAULT_TTL = 90.0; // 1.5 minutes private const DEFAULT_TTL = 90.0; // 1.5 minutes
/** @var string */ private string $lockName;
private $lockName; private bool $isBlocking;
/** @var bool */ private float $ttl;
private $isBlocking;
/** @var float */
private $ttl;
public function __construct(string $lockName, bool $isBlocking = false, float $ttl = self::DEFAULT_TTL) public function __construct(string $lockName, bool $isBlocking = false, float $ttl = self::DEFAULT_TTL)
{ {

View file

@ -32,17 +32,12 @@ class LocateVisitsCommand extends AbstractLockedCommand
public const NAME = 'visit:locate'; public const NAME = 'visit:locate';
public const ALIASES = ['visit:process']; public const ALIASES = ['visit:process'];
/** @var VisitServiceInterface */ private VisitServiceInterface $visitService;
private $visitService; private IpLocationResolverInterface $ipLocationResolver;
/** @var IpLocationResolverInterface */ private GeolocationDbUpdaterInterface $dbUpdater;
private $ipLocationResolver;
/** @var GeolocationDbUpdaterInterface */
private $dbUpdater;
/** @var SymfonyStyle */ private SymfonyStyle $io;
private $io; private ?ProgressBar $progressBar = null;
/** @var ProgressBar */
private $progressBar;
public function __construct( public function __construct(
VisitServiceInterface $visitService, VisitServiceInterface $visitService,

View file

@ -9,8 +9,7 @@ use Throwable;
class GeolocationDbUpdateFailedException extends RuntimeException implements ExceptionInterface class GeolocationDbUpdateFailedException extends RuntimeException implements ExceptionInterface
{ {
/** @var bool */ private bool $olderDbExists;
private $olderDbExists;
public static function create(bool $olderDbExists, ?Throwable $prev = null): self public static function create(bool $olderDbExists, ?Throwable $prev = null): self
{ {

View file

@ -15,12 +15,9 @@ class GeolocationDbUpdater implements GeolocationDbUpdaterInterface
{ {
private const LOCK_NAME = 'geolocation-db-update'; private const LOCK_NAME = 'geolocation-db-update';
/** @var DbUpdaterInterface */ private DbUpdaterInterface $dbUpdater;
private $dbUpdater; private Reader $geoLiteDbReader;
/** @var Reader */ private LockFactory $locker;
private $geoLiteDbReader;
/** @var LockFactory */
private $locker;
public function __construct(DbUpdaterInterface $dbUpdater, Reader $geoLiteDbReader, LockFactory $locker) public function __construct(DbUpdaterInterface $dbUpdater, Reader $geoLiteDbReader, LockFactory $locker)
{ {

View file

@ -12,8 +12,7 @@ final class ShlinkTable
private const DEFAULT_STYLE_NAME = 'default'; private const DEFAULT_STYLE_NAME = 'default';
private const TABLE_TITLE_STYLE = '<options=bold> %s </>'; private const TABLE_TITLE_STYLE = '<options=bold> %s </>';
/** @var Table|null */ private ?Table $baseTable;
private $baseTable;
public function __construct(Table $baseTable) public function __construct(Table $baseTable)
{ {

View file

@ -8,20 +8,18 @@ use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\CLI\Command\Api\DisableKeyCommand; use Shlinkio\Shlink\CLI\Command\Api\DisableKeyCommand;
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException; 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\Application;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
class DisableKeyCommandTest extends TestCase class DisableKeyCommandTest extends TestCase
{ {
/** @var CommandTester */ private CommandTester $commandTester;
private $commandTester; private ObjectProphecy $apiKeyService;
/** @var ObjectProphecy */
private $apiKeyService;
public function setUp(): void public function setUp(): void
{ {
$this->apiKeyService = $this->prophesize(ApiKeyService::class); $this->apiKeyService = $this->prophesize(ApiKeyServiceInterface::class);
$command = new DisableKeyCommand($this->apiKeyService->reveal()); $command = new DisableKeyCommand($this->apiKeyService->reveal());
$app = new Application(); $app = new Application();
$app->add($command); $app->add($command);

View file

@ -10,20 +10,18 @@ use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\CLI\Command\Api\GenerateKeyCommand; use Shlinkio\Shlink\CLI\Command\Api\GenerateKeyCommand;
use Shlinkio\Shlink\Rest\Entity\ApiKey; 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\Application;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
class GenerateKeyCommandTest extends TestCase class GenerateKeyCommandTest extends TestCase
{ {
/** @var CommandTester */ private CommandTester $commandTester;
private $commandTester; private ObjectProphecy $apiKeyService;
/** @var ObjectProphecy */
private $apiKeyService;
public function setUp(): void public function setUp(): void
{ {
$this->apiKeyService = $this->prophesize(ApiKeyService::class); $this->apiKeyService = $this->prophesize(ApiKeyServiceInterface::class);
$command = new GenerateKeyCommand($this->apiKeyService->reveal()); $command = new GenerateKeyCommand($this->apiKeyService->reveal());
$app = new Application(); $app = new Application();
$app->add($command); $app->add($command);

View file

@ -8,20 +8,18 @@ use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\CLI\Command\Api\ListKeysCommand; use Shlinkio\Shlink\CLI\Command\Api\ListKeysCommand;
use Shlinkio\Shlink\Rest\Entity\ApiKey; 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\Application;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
class ListKeysCommandTest extends TestCase class ListKeysCommandTest extends TestCase
{ {
/** @var CommandTester */ private CommandTester $commandTester;
private $commandTester; private ObjectProphecy $apiKeyService;
/** @var ObjectProphecy */
private $apiKeyService;
public function setUp(): void public function setUp(): void
{ {
$this->apiKeyService = $this->prophesize(ApiKeyService::class); $this->apiKeyService = $this->prophesize(ApiKeyServiceInterface::class);
$command = new ListKeysCommand($this->apiKeyService->reveal()); $command = new ListKeysCommand($this->apiKeyService->reveal());
$app = new Application(); $app = new Application();
$app->add($command); $app->add($command);

View file

@ -15,8 +15,7 @@ use function str_split;
class GenerateCharsetCommandTest extends TestCase class GenerateCharsetCommandTest extends TestCase
{ {
/** @var CommandTester */ private CommandTester $commandTester;
private $commandTester;
public function setUp(): void public function setUp(): void
{ {

View file

@ -21,18 +21,12 @@ use Symfony\Component\Process\PhpExecutableFinder;
class CreateDatabaseCommandTest extends TestCase class CreateDatabaseCommandTest extends TestCase
{ {
/** @var CommandTester */ private CommandTester $commandTester;
private $commandTester; private ObjectProphecy $processHelper;
/** @var ObjectProphecy */ private ObjectProphecy $regularConn;
private $processHelper; private ObjectProphecy $noDbNameConn;
/** @var ObjectProphecy */ private ObjectProphecy $schemaManager;
private $regularConn; private ObjectProphecy $databasePlatform;
/** @var ObjectProphecy */
private $noDbNameConn;
/** @var ObjectProphecy */
private $schemaManager;
/** @var ObjectProphecy */
private $databasePlatform;
public function setUp(): void public function setUp(): void
{ {

View file

@ -18,10 +18,8 @@ use Symfony\Component\Process\PhpExecutableFinder;
class MigrateDatabaseCommandTest extends TestCase class MigrateDatabaseCommandTest extends TestCase
{ {
/** @var CommandTester */ private CommandTester $commandTester;
private $commandTester; private ObjectProphecy $processHelper;
/** @var ObjectProphecy */
private $processHelper;
public function setUp(): void public function setUp(): void
{ {

View file

@ -20,10 +20,8 @@ use const PHP_EOL;
class DeleteShortUrlCommandTest extends TestCase class DeleteShortUrlCommandTest extends TestCase
{ {
/** @var CommandTester */ private CommandTester $commandTester;
private $commandTester; private ObjectProphecy $service;
/** @var ObjectProphecy */
private $service;
public function setUp(): void public function setUp(): void
{ {

View file

@ -22,12 +22,9 @@ use function substr_count;
class GeneratePreviewCommandTest extends TestCase class GeneratePreviewCommandTest extends TestCase
{ {
/** @var CommandTester */ private CommandTester $commandTester;
private $commandTester; private ObjectProphecy $previewGenerator;
/** @var ObjectProphecy */ private ObjectProphecy $shortUrlService;
private $previewGenerator;
/** @var ObjectProphecy */
private $shortUrlService;
public function setUp(): void public function setUp(): void
{ {

View file

@ -25,10 +25,8 @@ class GenerateShortUrlCommandTest extends TestCase
'hostname' => 'foo.com', 'hostname' => 'foo.com',
]; ];
/** @var CommandTester */ private CommandTester $commandTester;
private $commandTester; private ObjectProphecy $urlShortener;
/** @var ObjectProphecy */
private $urlShortener;
public function setUp(): void public function setUp(): void
{ {

View file

@ -26,10 +26,8 @@ use function sprintf;
class GetVisitsCommandTest extends TestCase class GetVisitsCommandTest extends TestCase
{ {
/** @var CommandTester */ private CommandTester $commandTester;
private $commandTester; private ObjectProphecy $visitsTracker;
/** @var ObjectProphecy */
private $visitsTracker;
public function setUp(): void public function setUp(): void
{ {

View file

@ -21,10 +21,8 @@ use function explode;
class ListShortUrlsCommandTest extends TestCase class ListShortUrlsCommandTest extends TestCase
{ {
/** @var CommandTester */ private CommandTester $commandTester;
private $commandTester; private ObjectProphecy $shortUrlService;
/** @var ObjectProphecy */
private $shortUrlService;
public function setUp(): void public function setUp(): void
{ {

View file

@ -19,10 +19,8 @@ use const PHP_EOL;
class ResolveUrlCommandTest extends TestCase class ResolveUrlCommandTest extends TestCase
{ {
/** @var CommandTester */ private CommandTester $commandTester;
private $commandTester; private ObjectProphecy $urlShortener;
/** @var ObjectProphecy */
private $urlShortener;
public function setUp(): void public function setUp(): void
{ {

View file

@ -14,10 +14,8 @@ use Symfony\Component\Console\Tester\CommandTester;
class CreateTagCommandTest extends TestCase class CreateTagCommandTest extends TestCase
{ {
/** @var CommandTester */ private CommandTester $commandTester;
private $commandTester; private ObjectProphecy $tagService;
/** @var ObjectProphecy */
private $tagService;
public function setUp(): void public function setUp(): void
{ {
@ -31,7 +29,7 @@ class CreateTagCommandTest extends TestCase
} }
/** @test */ /** @test */
public function errorIsReturnedWhenNoTagsAreProvided() public function errorIsReturnedWhenNoTagsAreProvided(): void
{ {
$this->commandTester->execute([]); $this->commandTester->execute([]);
@ -40,7 +38,7 @@ class CreateTagCommandTest extends TestCase
} }
/** @test */ /** @test */
public function serviceIsInvokedOnSuccess() public function serviceIsInvokedOnSuccess(): void
{ {
$tagNames = ['foo', 'bar']; $tagNames = ['foo', 'bar'];
$createTags = $this->tagService->createTags($tagNames)->willReturn(new ArrayCollection()); $createTags = $this->tagService->createTags($tagNames)->willReturn(new ArrayCollection());

View file

@ -13,12 +13,8 @@ use Symfony\Component\Console\Tester\CommandTester;
class DeleteTagsCommandTest extends TestCase class DeleteTagsCommandTest extends TestCase
{ {
/** @var DeleteTagsCommand */ private CommandTester $commandTester;
private $command; private ObjectProphecy $tagService;
/** @var CommandTester */
private $commandTester;
/** @var ObjectProphecy */
private $tagService;
public function setUp(): void public function setUp(): void
{ {
@ -32,7 +28,7 @@ class DeleteTagsCommandTest extends TestCase
} }
/** @test */ /** @test */
public function errorIsReturnedWhenNoTagsAreProvided() public function errorIsReturnedWhenNoTagsAreProvided(): void
{ {
$this->commandTester->execute([]); $this->commandTester->execute([]);
@ -41,7 +37,7 @@ class DeleteTagsCommandTest extends TestCase
} }
/** @test */ /** @test */
public function serviceIsInvokedOnSuccess() public function serviceIsInvokedOnSuccess(): void
{ {
$tagNames = ['foo', 'bar']; $tagNames = ['foo', 'bar'];
$deleteTags = $this->tagService->deleteTags($tagNames)->will(function () { $deleteTags = $this->tagService->deleteTags($tagNames)->will(function () {

View file

@ -14,12 +14,8 @@ use Symfony\Component\Console\Tester\CommandTester;
class ListTagsCommandTest extends TestCase class ListTagsCommandTest extends TestCase
{ {
/** @var ListTagsCommand */ private CommandTester $commandTester;
private $command; private ObjectProphecy $tagService;
/** @var CommandTester */
private $commandTester;
/** @var ObjectProphecy */
private $tagService;
public function setUp(): void public function setUp(): void
{ {
@ -33,7 +29,7 @@ class ListTagsCommandTest extends TestCase
} }
/** @test */ /** @test */
public function noTagsPrintsEmptyMessage() public function noTagsPrintsEmptyMessage(): void
{ {
$listTags = $this->tagService->listTags()->willReturn([]); $listTags = $this->tagService->listTags()->willReturn([]);
@ -45,7 +41,7 @@ class ListTagsCommandTest extends TestCase
} }
/** @test */ /** @test */
public function listOfTagsIsPrinted() public function listOfTagsIsPrinted(): void
{ {
$listTags = $this->tagService->listTags()->willReturn([ $listTags = $this->tagService->listTags()->willReturn([
new Tag('foo'), new Tag('foo'),

View file

@ -15,12 +15,8 @@ use Symfony\Component\Console\Tester\CommandTester;
class RenameTagCommandTest extends TestCase class RenameTagCommandTest extends TestCase
{ {
/** @var RenameTagCommand */ private CommandTester $commandTester;
private $command; private ObjectProphecy $tagService;
/** @var CommandTester */
private $commandTester;
/** @var ObjectProphecy */
private $tagService;
public function setUp(): void public function setUp(): void
{ {

View file

@ -29,18 +29,12 @@ use function sprintf;
class LocateVisitsCommandTest extends TestCase class LocateVisitsCommandTest extends TestCase
{ {
/** @var CommandTester */ private CommandTester $commandTester;
private $commandTester; private ObjectProphecy $visitService;
/** @var ObjectProphecy */ private ObjectProphecy $ipResolver;
private $visitService; private ObjectProphecy $locker;
/** @var ObjectProphecy */ private ObjectProphecy $lock;
private $ipResolver; private ObjectProphecy $dbUpdater;
/** @var ObjectProphecy */
private $locker;
/** @var ObjectProphecy */
private $lock;
/** @var ObjectProphecy */
private $dbUpdater;
public function setUp(): void public function setUp(): void
{ {

View file

@ -16,10 +16,8 @@ use Symfony\Component\Console\Tester\CommandTester;
class UpdateDbCommandTest extends TestCase class UpdateDbCommandTest extends TestCase
{ {
/** @var CommandTester */ private CommandTester $commandTester;
private $commandTester; private ObjectProphecy $dbUpdater;
/** @var ObjectProphecy */
private $dbUpdater;
public function setUp(): void public function setUp(): void
{ {

View file

@ -9,8 +9,7 @@ use Shlinkio\Shlink\CLI\ConfigProvider;
class ConfigProviderTest extends TestCase class ConfigProviderTest extends TestCase
{ {
/** @var ConfigProvider */ private ConfigProvider $configProvider;
private $configProvider;
public function setUp(): void public function setUp(): void
{ {

View file

@ -15,8 +15,7 @@ use Zend\ServiceManager\ServiceManager;
class ApplicationFactoryTest extends TestCase class ApplicationFactoryTest extends TestCase
{ {
/** @var ApplicationFactory */ private ApplicationFactory $factory;
private $factory;
public function setUp(): void public function setUp(): void
{ {
@ -36,7 +35,6 @@ class ApplicationFactoryTest extends TestCase
$sm->setService('foo', $this->createCommandMock('foo')->reveal()); $sm->setService('foo', $this->createCommandMock('foo')->reveal());
$sm->setService('bar', $this->createCommandMock('bar')->reveal()); $sm->setService('bar', $this->createCommandMock('bar')->reveal());
/** @var Application $instance */
$instance = ($this->factory)($sm); $instance = ($this->factory)($sm);
$this->assertTrue($instance->has('foo')); $this->assertTrue($instance->has('foo'));

View file

@ -22,16 +22,11 @@ use function range;
class GeolocationDbUpdaterTest extends TestCase class GeolocationDbUpdaterTest extends TestCase
{ {
/** @var GeolocationDbUpdater */ private GeolocationDbUpdater $geolocationDbUpdater;
private $geolocationDbUpdater; private ObjectProphecy $dbUpdater;
/** @var ObjectProphecy */ private ObjectProphecy $geoLiteDbReader;
private $dbUpdater; private ObjectProphecy $locker;
/** @var ObjectProphecy */ private ObjectProphecy $lock;
private $geoLiteDbReader;
/** @var ObjectProphecy */
private $locker;
/** @var ObjectProphecy */
private $lock;
public function setUp(): void public function setUp(): void
{ {

View file

@ -15,10 +15,8 @@ use Symfony\Component\Console\Output\OutputInterface;
class ShlinkTableTest extends TestCase class ShlinkTableTest extends TestCase
{ {
/** @var ShlinkTable */ private ShlinkTable $shlinkTable;
private $shlinkTable; private ObjectProphecy $baseTable;
/** @var ObjectProphecy */
private $baseTable;
public function setUp(): void public function setUp(): void
{ {

View file

@ -25,14 +25,10 @@ use function http_build_query;
abstract class AbstractTrackingAction implements MiddlewareInterface abstract class AbstractTrackingAction implements MiddlewareInterface
{ {
/** @var UrlShortenerInterface */ private UrlShortenerInterface $urlShortener;
private $urlShortener; private VisitsTrackerInterface $visitTracker;
/** @var VisitsTrackerInterface */ private AppOptions $appOptions;
private $visitTracker; private LoggerInterface $logger;
/** @var AppOptions */
private $appOptions;
/** @var LoggerInterface */
private $logger;
public function __construct( public function __construct(
UrlShortenerInterface $urlShortener, UrlShortenerInterface $urlShortener,

View file

@ -23,12 +23,9 @@ class QrCodeAction implements MiddlewareInterface
private const MIN_SIZE = 50; private const MIN_SIZE = 50;
private const MAX_SIZE = 1000; private const MAX_SIZE = 1000;
/** @var RouterInterface */ private RouterInterface $router;
private $router; private UrlShortenerInterface $urlShortener;
/** @var UrlShortenerInterface */ private LoggerInterface $logger;
private $urlShortener;
/** @var LoggerInterface */
private $logger;
public function __construct( public function __construct(
RouterInterface $router, RouterInterface $router,

View file

@ -9,8 +9,7 @@ use Shlinkio\Shlink\Core\Entity\Domain;
class PersistenceDomainResolver implements DomainResolverInterface class PersistenceDomainResolver implements DomainResolverInterface
{ {
/** @var EntityManagerInterface */ private EntityManagerInterface $em;
private $em;
public function __construct(EntityManagerInterface $em) public function __construct(EntityManagerInterface $em)
{ {

View file

@ -8,8 +8,7 @@ use Shlinkio\Shlink\Common\Entity\AbstractEntity;
class Domain extends AbstractEntity class Domain extends AbstractEntity
{ {
/** @var string */ private string $authority;
private $authority;
public function __construct(string $authority) public function __construct(string $authority)
{ {

View file

@ -22,26 +22,18 @@ use function Shlinkio\Shlink\Core\generateRandomShortCode;
class ShortUrl extends AbstractEntity class ShortUrl extends AbstractEntity
{ {
/** @var string */ private string $longUrl;
private $longUrl; private string $shortCode;
/** @var string */ private Chronos $dateCreated;
private $shortCode;
/** @var Chronos */
private $dateCreated;
/** @var Collection|Visit[] */ /** @var Collection|Visit[] */
private $visits; private Collection $visits;
/** @var Collection|Tag[] */ /** @var Collection|Tag[] */
private $tags; private Collection $tags;
/** @var Chronos|null */ private ?Chronos $validSince;
private $validSince; private ?Chronos $validUntil;
/** @var Chronos|null */ private ?int $maxVisits;
private $validUntil; private ?Domain $domain;
/** @var integer|null */ private bool $customSlugWasProvided;
private $maxVisits;
/** @var Domain|null */
private $domain;
/** @var bool */
private $customSlugWasProvided;
public function __construct( public function __construct(
string $longUrl, string $longUrl,

View file

@ -9,8 +9,7 @@ use Shlinkio\Shlink\Common\Entity\AbstractEntity;
class Tag extends AbstractEntity implements JsonSerializable class Tag extends AbstractEntity implements JsonSerializable
{ {
/** @var string */ private string $name;
private $name;
public function __construct(string $name) public function __construct(string $name)
{ {

View file

@ -15,18 +15,12 @@ use Shlinkio\Shlink\Core\Visit\Model\VisitLocationInterface;
class Visit extends AbstractEntity implements JsonSerializable class Visit extends AbstractEntity implements JsonSerializable
{ {
/** @var string */ private string $referer;
private $referer; private Chronos $date;
/** @var Chronos */ private ?string $remoteAddr;
private $date; private string $userAgent;
/** @var string|null */ private ShortUrl $shortUrl;
private $remoteAddr; private ?VisitLocation $visitLocation = null;
/** @var string */
private $userAgent;
/** @var ShortUrl */
private $shortUrl;
/** @var VisitLocation */
private $visitLocation;
public function __construct(ShortUrl $shortUrl, Visitor $visitor, ?Chronos $date = null) public function __construct(ShortUrl $shortUrl, Visitor $visitor, ?Chronos $date = null)
{ {

View file

@ -10,20 +10,13 @@ use Shlinkio\Shlink\IpGeolocation\Model\Location;
class VisitLocation extends AbstractEntity implements VisitLocationInterface class VisitLocation extends AbstractEntity implements VisitLocationInterface
{ {
/** @var string */ private string $countryCode;
private $countryCode; private string $countryName;
/** @var string */ private string $regionName;
private $countryName; private string $cityName;
/** @var string */ private string $latitude; // FIXME Should be float
private $regionName; private string $longitude; // FIXME Should be float
/** @var string */ private string $timezone;
private $cityName;
/** @var string */
private $latitude;
/** @var string */
private $longitude;
/** @var string */
private $timezone;
public function __construct(Location $location) public function __construct(Location $location)
{ {

View file

@ -18,10 +18,8 @@ use function rtrim;
class NotFoundRedirectHandler implements MiddlewareInterface class NotFoundRedirectHandler implements MiddlewareInterface
{ {
/** @var NotFoundRedirectOptions */ private NotFoundRedirectOptions $redirectOptions;
private $redirectOptions; private string $shlinkBasePath;
/** @var string */
private $shlinkBasePath;
public function __construct(NotFoundRedirectOptions $redirectOptions, string $shlinkBasePath) public function __construct(NotFoundRedirectOptions $redirectOptions, string $shlinkBasePath)
{ {

View file

@ -18,8 +18,7 @@ class NotFoundTemplateHandler implements RequestHandlerInterface
public const NOT_FOUND_TEMPLATE = 'ShlinkCore::error/404'; public const NOT_FOUND_TEMPLATE = 'ShlinkCore::error/404';
public const INVALID_SHORT_CODE_TEMPLATE = 'ShlinkCore::invalid-short-code'; public const INVALID_SHORT_CODE_TEMPLATE = 'ShlinkCore::invalid-short-code';
/** @var TemplateRendererInterface */ private TemplateRendererInterface $renderer;
private $renderer;
public function __construct(TemplateRendererInterface $renderer) public function __construct(TemplateRendererInterface $renderer)
{ {

View file

@ -19,16 +19,11 @@ use function sprintf;
class LocateShortUrlVisit class LocateShortUrlVisit
{ {
/** @var IpLocationResolverInterface */ private IpLocationResolverInterface $ipLocationResolver;
private $ipLocationResolver; private EntityManagerInterface $em;
/** @var EntityManagerInterface */ private LoggerInterface $logger;
private $em; private GeolocationDbUpdaterInterface $dbUpdater;
/** @var LoggerInterface */ private EventDispatcherInterface $eventDispatcher;
private $logger;
/** @var GeolocationDbUpdaterInterface */
private $dbUpdater;
/** @var EventDispatcherInterface */
private $eventDispatcher;
public function __construct( public function __construct(
IpLocationResolverInterface $ipLocationResolver, IpLocationResolverInterface $ipLocationResolver,

View file

@ -22,18 +22,13 @@ use function GuzzleHttp\Promise\settle;
class NotifyVisitToWebHooks class NotifyVisitToWebHooks
{ {
/** @var ClientInterface */ private ClientInterface $httpClient;
private $httpClient; private EntityManagerInterface $em;
/** @var EntityManagerInterface */ private LoggerInterface $logger;
private $em; /** @var string[] */
/** @var LoggerInterface */ private array $webhooks;
private $logger; private ShortUrlDataTransformer $transformer;
/** @var array */ private AppOptions $appOptions;
private $webhooks;
/** @var ShortUrlDataTransformer */
private $transformer;
/** @var AppOptions */
private $appOptions;
public function __construct( public function __construct(
ClientInterface $httpClient, ClientInterface $httpClient,

View file

@ -8,8 +8,7 @@ use JsonSerializable;
final class ShortUrlVisited implements JsonSerializable final class ShortUrlVisited implements JsonSerializable
{ {
/** @var string */ private string $visitId;
private $visitId;
public function __construct(string $visitId) public function __construct(string $visitId)
{ {

View file

@ -8,8 +8,7 @@ use JsonSerializable;
final class VisitLocated implements JsonSerializable final class VisitLocated implements JsonSerializable
{ {
/** @var string */ private string $visitId;
private $visitId;
public function __construct(string $visitId) public function __construct(string $visitId)
{ {

View file

@ -8,32 +8,24 @@ use Throwable;
class IpCannotBeLocatedException extends RuntimeException class IpCannotBeLocatedException extends RuntimeException
{ {
/** @var bool */ private bool $isNonLocatableAddress = true;
private $isNonLocatableAddress;
public function __construct(
bool $isNonLocatableAddress,
string $message,
int $code = 0,
?Throwable $previous = null
) {
$this->isNonLocatableAddress = $isNonLocatableAddress;
parent::__construct($message, $code, $previous);
}
public static function forEmptyAddress(): self 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 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 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;
} }
/** /**

View file

@ -25,8 +25,7 @@ class ValidationException extends InvalidArgumentException implements ProblemDet
private const TITLE = 'Invalid data'; private const TITLE = 'Invalid data';
private const TYPE = 'INVALID_ARGUMENT'; private const TYPE = 'INVALID_ARGUMENT';
/** @var array */ private array $invalidElements;
private $invalidElements;
public static function fromInputFilter(InputFilterInterface $inputFilter, ?Throwable $prev = null): self public static function fromInputFilter(InputFilterInterface $inputFilter, ?Throwable $prev = null): self
{ {

View file

@ -13,8 +13,7 @@ use Zend\Diactoros\Response as DiactResp;
class QrCodeCacheMiddleware implements MiddlewareInterface class QrCodeCacheMiddleware implements MiddlewareInterface
{ {
/** @var Cache */ private Cache $cache;
private $cache;
public function __construct(Cache $cache) public function __construct(Cache $cache)
{ {

View file

@ -8,12 +8,9 @@ use Psr\Http\Message\UriInterface;
final class CreateShortUrlData final class CreateShortUrlData
{ {
/** @var UriInterface */ private UriInterface $longUrl;
private $longUrl; private array $tags;
/** @var array */ private ShortUrlMeta $meta;
private $tags;
/** @var ShortUrlMeta */
private $meta;
public function __construct( public function __construct(
UriInterface $longUrl, UriInterface $longUrl,

View file

@ -11,18 +11,12 @@ use Shlinkio\Shlink\Core\Validation\ShortUrlMetaInputFilter;
final class ShortUrlMeta final class ShortUrlMeta
{ {
/** @var Chronos|null */ private ?Chronos $validSince = null;
private $validSince; private ?Chronos $validUntil = null;
/** @var Chronos|null */ private ?string $customSlug = null;
private $validUntil; private ?int $maxVisits = null;
/** @var string|null */ private ?bool $findIfExists = null;
private $customSlug; private ?string $domain = null;
/** @var int|null */
private $maxVisits;
/** @var bool|null */
private $findIfExists;
/** @var string|null */
private $domain;
// Force named constructors // Force named constructors
private function __construct() private function __construct()
@ -90,8 +84,8 @@ final class ShortUrlMeta
$this->validSince = $this->parseDateField($inputFilter->getValue(ShortUrlMetaInputFilter::VALID_SINCE)); $this->validSince = $this->parseDateField($inputFilter->getValue(ShortUrlMetaInputFilter::VALID_SINCE));
$this->validUntil = $this->parseDateField($inputFilter->getValue(ShortUrlMetaInputFilter::VALID_UNTIL)); $this->validUntil = $this->parseDateField($inputFilter->getValue(ShortUrlMetaInputFilter::VALID_UNTIL));
$this->customSlug = $inputFilter->getValue(ShortUrlMetaInputFilter::CUSTOM_SLUG); $this->customSlug = $inputFilter->getValue(ShortUrlMetaInputFilter::CUSTOM_SLUG);
$this->maxVisits = $inputFilter->getValue(ShortUrlMetaInputFilter::MAX_VISITS); $maxVisits = $inputFilter->getValue(ShortUrlMetaInputFilter::MAX_VISITS);
$this->maxVisits = $this->maxVisits !== null ? (int) $this->maxVisits : null; $this->maxVisits = $maxVisits !== null ? (int) $maxVisits : null;
$this->findIfExists = $inputFilter->getValue(ShortUrlMetaInputFilter::FIND_IF_EXISTS); $this->findIfExists = $inputFilter->getValue(ShortUrlMetaInputFilter::FIND_IF_EXISTS);
$this->domain = $inputFilter->getValue(ShortUrlMetaInputFilter::DOMAIN); $this->domain = $inputFilter->getValue(ShortUrlMetaInputFilter::DOMAIN);
} }

View file

@ -15,12 +15,9 @@ final class Visitor
public const REFERER_MAX_LENGTH = 1024; public const REFERER_MAX_LENGTH = 1024;
public const REMOTE_ADDRESS_MAX_LENGTH = 256; public const REMOTE_ADDRESS_MAX_LENGTH = 256;
/** @var string */ private string $userAgent;
private $userAgent; private string $referer;
/** @var string */ private ?string $remoteAddress;
private $referer;
/** @var string|null */
private $remoteAddress;
public function __construct(string $userAgent, string $referer, ?string $remoteAddress) public function __construct(string $userAgent, string $referer, ?string $remoteAddress)
{ {

View file

@ -12,12 +12,9 @@ final class VisitsParams
private const FIRST_PAGE = 1; private const FIRST_PAGE = 1;
private const ALL_ITEMS = -1; private const ALL_ITEMS = -1;
/** @var null|DateRange */ private ?DateRange $dateRange;
private $dateRange; private int $page;
/** @var int */ private int $itemsPerPage;
private $page;
/** @var int */
private $itemsPerPage;
public function __construct(?DateRange $dateRange = null, int $page = self::FIRST_PAGE, ?int $itemsPerPage = null) public function __construct(?DateRange $dateRange = null, int $page = self::FIRST_PAGE, ?int $itemsPerPage = null)
{ {

View file

@ -13,17 +13,11 @@ class AppOptions extends AbstractOptions
{ {
use StringUtilsTrait; use StringUtilsTrait;
/** @var string */ private string $name = '';
private $name = ''; private string $version = '1.0';
/** @var string */ /** @deprecated */
private $version = '1.0'; private string $secretKey = '';
/** private ?string $disableTrackParam = null;
* @var string
* @deprecated
*/
private $secretKey = '';
/** @var string|null */
private $disableTrackParam;
public function getName(): string public function getName(): string
{ {

View file

@ -8,12 +8,9 @@ use Zend\Stdlib\AbstractOptions;
class NotFoundRedirectOptions extends AbstractOptions class NotFoundRedirectOptions extends AbstractOptions
{ {
/** @var string|null */ private ?string $invalidShortUrl = null;
private $invalidShortUrl; private ?string $regular404 = null;
/** @var string|null */ private ?string $baseUrl = null;
private $regular404;
/** @var string|null */
private $baseUrl;
public function getInvalidShortUrlRedirect(): ?string public function getInvalidShortUrlRedirect(): ?string
{ {

View file

@ -15,16 +15,12 @@ class ShortUrlRepositoryAdapter implements AdapterInterface
{ {
public const ITEMS_PER_PAGE = 10; public const ITEMS_PER_PAGE = 10;
/** @var ShortUrlRepositoryInterface */ private ShortUrlRepositoryInterface $repository;
private $repository; private ?string $searchTerm;
/** @var null|string */
private $searchTerm;
/** @var null|array|string */ /** @var null|array|string */
private $orderBy; private $orderBy;
/** @var array */ private array $tags;
private $tags; private ?DateRange $dateRange;
/** @var DateRange|null */
private $dateRange;
public function __construct( public function __construct(
ShortUrlRepositoryInterface $repository, ShortUrlRepositoryInterface $repository,

View file

@ -10,12 +10,9 @@ use Zend\Paginator\Adapter\AdapterInterface;
class VisitsPaginatorAdapter implements AdapterInterface class VisitsPaginatorAdapter implements AdapterInterface
{ {
/** @var VisitRepositoryInterface */ private VisitRepositoryInterface $visitRepository;
private $visitRepository; private string $shortCode;
/** @var string */ private VisitsParams $params;
private $shortCode;
/** @var VisitsParams */
private $params;
public function __construct(VisitRepositoryInterface $visitRepository, string $shortCode, VisitsParams $params) public function __construct(VisitRepositoryInterface $visitRepository, string $shortCode, VisitsParams $params)
{ {

View file

@ -13,10 +13,8 @@ class DeleteShortUrlService implements DeleteShortUrlServiceInterface
{ {
use FindShortCodeTrait; use FindShortCodeTrait;
/** @var EntityManagerInterface */ private EntityManagerInterface $em;
private $em; private DeleteShortUrlsOptions $deleteShortUrlsOptions;
/** @var DeleteShortUrlsOptions */
private $deleteShortUrlsOptions;
public function __construct(EntityManagerInterface $em, DeleteShortUrlsOptions $deleteShortUrlsOptions) public function __construct(EntityManagerInterface $em, DeleteShortUrlsOptions $deleteShortUrlsOptions)
{ {

View file

@ -20,8 +20,7 @@ class ShortUrlService implements ShortUrlServiceInterface
use FindShortCodeTrait; use FindShortCodeTrait;
use TagManagerTrait; use TagManagerTrait;
/** @var ORM\EntityManagerInterface */ private ORM\EntityManagerInterface $em;
private $em;
public function __construct(ORM\EntityManagerInterface $em) public function __construct(ORM\EntityManagerInterface $em)
{ {

View file

@ -16,8 +16,7 @@ class TagService implements TagServiceInterface
{ {
use TagManagerTrait; use TagManagerTrait;
/** @var ORM\EntityManagerInterface */ private ORM\EntityManagerInterface $em;
private $em;
public function __construct(ORM\EntityManagerInterface $em) public function __construct(ORM\EntityManagerInterface $em)
{ {

View file

@ -24,12 +24,9 @@ class UrlShortener implements UrlShortenerInterface
{ {
use TagManagerTrait; use TagManagerTrait;
/** @var EntityManagerInterface */ private EntityManagerInterface $em;
private $em; private UrlShortenerOptions $options;
/** @var UrlShortenerOptions */ private UrlValidatorInterface $urlValidator;
private $options;
/** @var UrlValidatorInterface */
private $urlValidator;
public function __construct( public function __construct(
UrlValidatorInterface $urlValidator, UrlValidatorInterface $urlValidator,

View file

@ -13,8 +13,7 @@ use Shlinkio\Shlink\IpGeolocation\Model\Location;
class VisitService implements VisitServiceInterface class VisitService implements VisitServiceInterface
{ {
/** @var EntityManagerInterface */ private EntityManagerInterface $em;
private $em;
public function __construct(EntityManagerInterface $em) public function __construct(EntityManagerInterface $em)
{ {

View file

@ -18,10 +18,8 @@ use Zend\Paginator\Paginator;
class VisitsTracker implements VisitsTrackerInterface class VisitsTracker implements VisitsTrackerInterface
{ {
/** @var ORM\EntityManagerInterface */ private ORM\EntityManagerInterface $em;
private $em; private EventDispatcherInterface $eventDispatcher;
/** @var EventDispatcherInterface */
private $eventDispatcher;
public function __construct(ORM\EntityManagerInterface $em, EventDispatcherInterface $eventDispatcher) public function __construct(ORM\EntityManagerInterface $em, EventDispatcherInterface $eventDispatcher)
{ {

View file

@ -12,8 +12,7 @@ use function Functional\invoke_if;
class ShortUrlDataTransformer implements DataTransformerInterface class ShortUrlDataTransformer implements DataTransformerInterface
{ {
/** @var array */ private array $domainConfig;
private $domainConfig;
public function __construct(array $domainConfig) public function __construct(array $domainConfig)
{ {

View file

@ -14,8 +14,7 @@ class UrlValidator implements UrlValidatorInterface, RequestMethodInterface
{ {
private const MAX_REDIRECTS = 15; private const MAX_REDIRECTS = 15;
/** @var ClientInterface */ private ClientInterface $httpClient;
private $httpClient;
public function __construct(ClientInterface $httpClient) public function __construct(ClientInterface $httpClient)
{ {

View file

@ -28,8 +28,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
Domain::class, Domain::class,
]; ];
/** @var ShortUrlRepository */ private ShortUrlRepository $repo;
private $repo;
public function setUp(): void public function setUp(): void
{ {

View file

@ -14,8 +14,7 @@ class TagRepositoryTest extends DatabaseTestCase
Tag::class, Tag::class,
]; ];
/** @var TagRepository */ private TagRepository $repo;
private $repo;
protected function setUp(): void protected function setUp(): void
{ {

View file

@ -26,8 +26,7 @@ class VisitRepositoryTest extends DatabaseTestCase
ShortUrl::class, ShortUrl::class,
]; ];
/** @var VisitRepository */ private VisitRepository $repo;
private $repo;
protected function setUp(): void protected function setUp(): void
{ {

View file

@ -10,7 +10,6 @@ use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Server\RequestHandlerInterface;
use Shlinkio\Shlink\Common\Response\PixelResponse; use Shlinkio\Shlink\Common\Response\PixelResponse;
use Shlinkio\Shlink\Core\Action\PixelAction; use Shlinkio\Shlink\Core\Action\PixelAction;
use Shlinkio\Shlink\Core\Action\RedirectAction;
use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Options\AppOptions; use Shlinkio\Shlink\Core\Options\AppOptions;
use Shlinkio\Shlink\Core\Service\UrlShortener; use Shlinkio\Shlink\Core\Service\UrlShortener;
@ -19,12 +18,9 @@ use Zend\Diactoros\ServerRequest;
class PixelActionTest extends TestCase class PixelActionTest extends TestCase
{ {
/** @var RedirectAction */ private PixelAction $action;
private $action; private ObjectProphecy $urlShortener;
/** @var ObjectProphecy */ private ObjectProphecy $visitTracker;
private $urlShortener;
/** @var ObjectProphecy */
private $visitTracker;
public function setUp(): void public function setUp(): void
{ {

View file

@ -21,6 +21,7 @@ use function filesize;
use const FILEINFO_MIME; use const FILEINFO_MIME;
/** @deprecated */
class PreviewActionTest extends TestCase class PreviewActionTest extends TestCase
{ {
/** @var PreviewAction */ /** @var PreviewAction */

View file

@ -19,10 +19,8 @@ use Zend\Expressive\Router\RouterInterface;
class QrCodeActionTest extends TestCase class QrCodeActionTest extends TestCase
{ {
/** @var QrCodeAction */ private QrCodeAction $action;
private $action; private ObjectProphecy $urlShortener;
/** @var ObjectProphecy */
private $urlShortener;
public function setUp(): void public function setUp(): void
{ {

View file

@ -21,12 +21,9 @@ use function array_key_exists;
class RedirectActionTest extends TestCase class RedirectActionTest extends TestCase
{ {
/** @var RedirectAction */ private RedirectAction $action;
private $action; private ObjectProphecy $urlShortener;
/** @var ObjectProphecy */ private ObjectProphecy $visitTracker;
private $urlShortener;
/** @var ObjectProphecy */
private $visitTracker;
public function setUp(): void public function setUp(): void
{ {

View file

@ -9,8 +9,7 @@ use Shlinkio\Shlink\Core\ConfigProvider;
class ConfigProviderTest extends TestCase class ConfigProviderTest extends TestCase
{ {
/** @var ConfigProvider */ private ConfigProvider $configProvider;
private $configProvider;
public function setUp(): void public function setUp(): void
{ {

View file

@ -11,10 +11,6 @@ use Shlinkio\Shlink\Core\Exception\IpCannotBeLocatedException;
use Shlinkio\Shlink\Core\Exception\RuntimeException; use Shlinkio\Shlink\Core\Exception\RuntimeException;
use Throwable; use Throwable;
use function count;
use function func_get_args;
use function random_int;
class IpCannotBeLocatedExceptionTest extends TestCase class IpCannotBeLocatedExceptionTest extends TestCase
{ {
/** @test */ /** @test */
@ -59,39 +55,4 @@ class IpCannotBeLocatedExceptionTest extends TestCase
yield 'Runtime exception with negative code' => [new RuntimeException('Something went wrong', -50)]; yield 'Runtime exception with negative code' => [new RuntimeException('Something went wrong', -50)];
yield 'Logic exception with default code' => [new LogicException('Conditions unmet')]; 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')];
}
} }

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Service; namespace ShlinkioTest\Shlink\Core\Service;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Exception;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
@ -94,7 +95,9 @@ class VisitServiceTest extends TestCase
}); });
$this->visitService->locateUnlocatedVisits(function () use ($isNonLocatableAddress) { $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(); $findUnlocatedVisits->shouldHaveBeenCalledOnce();