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/module/CLI/src/Command/Tag/ListTagsCommand.php b/module/CLI/src/Command/Tag/ListTagsCommand.php index e4059291..0b8f0aa3 100644 --- a/module/CLI/src/Command/Tag/ListTagsCommand.php +++ b/module/CLI/src/Command/Tag/ListTagsCommand.php @@ -46,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/test/Command/ShortUrl/ListShortUrlsCommandTest.php b/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php index 5fc3ecee..a704111d 100644 --- a/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php @@ -42,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/Util/GeolocationDbUpdaterTest.php b/module/CLI/test/Util/GeolocationDbUpdaterTest.php index 7120c735..640c0e7c 100644 --- a/module/CLI/test/Util/GeolocationDbUpdaterTest.php +++ b/module/CLI/test/Util/GeolocationDbUpdaterTest.php @@ -50,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); @@ -148,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/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/Entity/ShortUrl.php b/module/Core/src/Entity/ShortUrl.php index ef8a3b2f..64d6d4b5 100644 --- a/module/Core/src/Entity/ShortUrl.php +++ b/module/Core/src/Entity/ShortUrl.php @@ -188,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/Exception/ValidationException.php b/module/Core/src/Exception/ValidationException.php index c2308f06..8710b737 100644 --- a/module/Core/src/Exception/ValidationException.php +++ b/module/Core/src/Exception/ValidationException.php @@ -69,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/test-db/Repository/VisitRepositoryTest.php b/module/Core/test-db/Repository/VisitRepositoryTest.php index 51ffbc3c..bbccea41 100644 --- a/module/Core/test-db/Repository/VisitRepositoryTest.php +++ b/module/Core/test-db/Repository/VisitRepositoryTest.php @@ -66,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/Service/ShortUrl/DeleteShortUrlServiceTest.php b/module/Core/test/Service/ShortUrl/DeleteShortUrlServiceTest.php index 22dddcb5..b708e465 100644 --- a/module/Core/test/Service/ShortUrl/DeleteShortUrlServiceTest.php +++ b/module/Core/test/Service/ShortUrl/DeleteShortUrlServiceTest.php @@ -28,9 +28,9 @@ class DeleteShortUrlServiceTest extends TestCase 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/UrlShortenerTest.php b/module/Core/test/Service/UrlShortenerTest.php index 25720671..9d183381 100644 --- a/module/Core/test/Service/UrlShortenerTest.php +++ b/module/Core/test/Service/UrlShortenerTest.php @@ -44,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); @@ -240,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 42b201b2..e09b0a4c 100644 --- a/module/Core/test/Service/VisitServiceTest.php +++ b/module/Core/test/Service/VisitServiceTest.php @@ -40,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); @@ -55,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)); diff --git a/module/Core/test/Service/VisitsTrackerTest.php b/module/Core/test/Service/VisitsTrackerTest.php index 0cb4d205..9b9ab948 100644 --- a/module/Core/test/Service/VisitsTrackerTest.php +++ b/module/Core/test/Service/VisitsTrackerTest.php @@ -43,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/Rest/src/Authentication/RequestToHttpAuthPlugin.php b/module/Rest/src/Authentication/RequestToHttpAuthPlugin.php index 9496ceff..bb6454b2 100644 --- a/module/Rest/src/Authentication/RequestToHttpAuthPlugin.php +++ b/module/Rest/src/Authentication/RequestToHttpAuthPlugin.php @@ -43,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/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/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/Authentication/AuthenticationPluginManagerFactoryTest.php b/module/Rest/test/Authentication/AuthenticationPluginManagerFactoryTest.php index 71bcfe9c..4c24e26a 100644 --- a/module/Rest/test/Authentication/AuthenticationPluginManagerFactoryTest.php +++ b/module/Rest/test/Authentication/AuthenticationPluginManagerFactoryTest.php @@ -34,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/ConfigProviderTest.php b/module/Rest/test/ConfigProviderTest.php index f914edf6..b8cebf93 100644 --- a/module/Rest/test/ConfigProviderTest.php +++ b/module/Rest/test/ConfigProviderTest.php @@ -28,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/Middleware/AuthenticationMiddlewareTest.php b/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php index 8f9e8052..8bef98a1 100644 --- a/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php +++ b/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php @@ -109,8 +109,6 @@ class AuthenticationMiddlewareTest extends TestCase private function getDummyMiddleware(): MiddlewareInterface { - return middleware(function () { - return new Response\EmptyResponse(); - }); + return middleware(fn () => new Response\EmptyResponse()); } }