From f50263d2d992f127fe796b6b3b21ebb0e13928a1 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Wed, 29 Nov 2023 12:34:13 +0100 Subject: [PATCH] Remove usage of Functional\map function --- docker-compose.yml | 2 +- .../CLI/src/Command/Api/ListKeysCommand.php | 6 ++-- .../src/Command/Db/CreateDatabaseCommand.php | 4 +-- .../src/Command/Domain/ListDomainsCommand.php | 8 ++--- .../Command/ShortUrl/ListShortUrlsCommand.php | 8 ++--- .../CLI/src/Command/Tag/ListTagsCommand.php | 8 ++--- .../Visit/AbstractVisitsListCommand.php | 24 ++++++++++---- module/CLI/test/ApiKey/RoleResolverTest.php | 11 ++++--- .../test/GeoLite/GeolocationDbUpdaterTest.php | 4 +-- module/Core/functions/functions.php | 4 +-- .../Config/PostProcessor/BasePathPrefixer.php | 6 ++-- .../MultiSegmentSlugProcessor.php | 6 ++-- module/Core/src/Domain/DomainService.php | 4 +-- .../EventDispatcher/NotifyVisitToWebHooks.php | 18 +++++----- module/Core/src/ShortUrl/Entity/ShortUrl.php | 6 ++-- .../src/ShortUrl/Model/DeviceLongUrlPair.php | 26 +++++++++------ .../PersistenceShortUrlRelationResolver.php | 26 +++++++++------ .../SimpleShortUrlRelationResolver.php | 4 +-- .../Transformer/ShortUrlDataTransformer.php | 10 +++--- .../Core/src/Tag/Repository/TagRepository.php | 6 ++-- module/Core/src/Visit/RequestTracker.php | 22 +++++++++---- .../Repository/ShortUrlListRepositoryTest.php | 10 +++--- .../Adapter/TagsPaginatorAdapterTest.php | 4 +-- .../VisitLocationRepositoryTest.php | 4 +-- .../EventDispatcher/UpdateGeoLiteDbTest.php | 6 ++-- .../Exception/DeleteShortUrlExceptionTest.php | 6 ++-- module/Core/test/Functions/FunctionsTest.php | 13 +++++--- .../ShortUrl/DeleteShortUrlServiceTest.php | 4 +-- .../test/ShortUrl/Entity/ShortUrlTest.php | 4 +-- .../test/ShortUrl/ShortUrlResolverTest.php | 10 +++--- .../ShortUrlDataTransformerTest.php | 10 ++++++ .../Visit/Geolocation/VisitLocatorTest.php | 6 ++-- .../Core/test/Visit/VisitsStatsHelperTest.php | 33 ++++++++++++++----- module/Rest/config/access-logs.config.php | 4 +-- module/Rest/src/Action/Tag/ListTagsAction.php | 4 +-- module/Rest/src/ConfigProvider.php | 6 ++-- .../test-api/Action/CreateShortUrlTest.php | 4 +-- 37 files changed, 201 insertions(+), 140 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index e44ca82b..f33693ad 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -199,7 +199,7 @@ services: shlink_swagger_ui: container_name: shlink_swagger_ui - image: swaggerapi/swagger-ui:v5.9.1 + image: swaggerapi/swagger-ui:v5.10.3 ports: - "8005:8080" volumes: diff --git a/module/CLI/src/Command/Api/ListKeysCommand.php b/module/CLI/src/Command/Api/ListKeysCommand.php index 4fd4b005..b55dcd7d 100644 --- a/module/CLI/src/Command/Api/ListKeysCommand.php +++ b/module/CLI/src/Command/Api/ListKeysCommand.php @@ -15,7 +15,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use function array_filter; -use function Functional\map; +use function array_map; use function implode; use function sprintf; @@ -49,7 +49,7 @@ class ListKeysCommand extends Command { $enabledOnly = $input->getOption('enabled-only'); - $rows = map($this->apiKeyService->listKeys($enabledOnly), function (ApiKey $apiKey) use ($enabledOnly) { + $rows = array_map(function (ApiKey $apiKey) use ($enabledOnly) { $expiration = $apiKey->getExpirationDate(); $messagePattern = $this->determineMessagePattern($apiKey); @@ -64,7 +64,7 @@ class ListKeysCommand extends Command )); return $rowData; - }); + }, $this->apiKeyService->listKeys($enabledOnly)); ShlinkTable::withRowSeparators($output)->render(array_filter([ 'Key', diff --git a/module/CLI/src/Command/Db/CreateDatabaseCommand.php b/module/CLI/src/Command/Db/CreateDatabaseCommand.php index 129db1e0..c70e2f76 100644 --- a/module/CLI/src/Command/Db/CreateDatabaseCommand.php +++ b/module/CLI/src/Command/Db/CreateDatabaseCommand.php @@ -16,8 +16,8 @@ use Symfony\Component\Lock\LockFactory; use Symfony\Component\Process\PhpExecutableFinder; use Throwable; +use function array_map; use function Functional\contains; -use function Functional\map; use function Functional\some; class CreateDatabaseCommand extends AbstractDatabaseCommand @@ -70,7 +70,7 @@ class CreateDatabaseCommand extends AbstractDatabaseCommand { $existingTables = $this->ensureDatabaseExistsAndGetTables(); $allMetadata = $this->em->getMetadataFactory()->getAllMetadata(); - $shlinkTables = map($allMetadata, static fn (ClassMetadata $metadata) => $metadata->getTableName()); + $shlinkTables = array_map(static fn (ClassMetadata $metadata) => $metadata->getTableName(), $allMetadata); // If at least one of the shlink tables exist, we will consider the database exists somehow. // Any other inconsistency will be taken care of by the migrations. diff --git a/module/CLI/src/Command/Domain/ListDomainsCommand.php b/module/CLI/src/Command/Domain/ListDomainsCommand.php index 11a0f5b9..50107292 100644 --- a/module/CLI/src/Command/Domain/ListDomainsCommand.php +++ b/module/CLI/src/Command/Domain/ListDomainsCommand.php @@ -14,13 +14,13 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use function Functional\map; +use function array_map; class ListDomainsCommand extends Command { public const NAME = 'domain:list'; - public function __construct(private DomainServiceInterface $domainService) + public function __construct(private readonly DomainServiceInterface $domainService) { parent::__construct(); } @@ -47,7 +47,7 @@ class ListDomainsCommand extends Command $table->render( $showRedirects ? [...$commonFields, '"Not found" redirects'] : $commonFields, - map($domains, function (DomainItem $domain) use ($showRedirects) { + array_map(function (DomainItem $domain) use ($showRedirects) { $commonValues = [$domain->toString(), $domain->isDefault ? 'Yes' : 'No']; return $showRedirects @@ -56,7 +56,7 @@ class ListDomainsCommand extends Command $this->notFoundRedirectsToString($domain->notFoundRedirectConfig), ] : $commonValues; - }), + }, $domains), ); return ExitCode::EXIT_SUCCESS; diff --git a/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php b/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php index 14ea1851..c9497daf 100644 --- a/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php +++ b/module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php @@ -23,9 +23,9 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use function array_keys; +use function array_map; use function array_pad; use function explode; -use function Functional\map; use function implode; use function sprintf; @@ -184,10 +184,10 @@ class ListShortUrlsCommand extends Command ): Paginator { $shortUrls = $this->shortUrlService->listShortUrls($params); - $rows = map($shortUrls, function (ShortUrl $shortUrl) use ($columnsMap) { + $rows = array_map(function (ShortUrl $shortUrl) use ($columnsMap) { $rawShortUrl = $this->transformer->transform($shortUrl); - return map($columnsMap, fn (callable $call) => $call($rawShortUrl, $shortUrl)); - }); + return array_map(fn (callable $call) => $call($rawShortUrl, $shortUrl), $columnsMap); + }, [...$shortUrls]); ShlinkTable::default($output)->render( array_keys($columnsMap), diff --git a/module/CLI/src/Command/Tag/ListTagsCommand.php b/module/CLI/src/Command/Tag/ListTagsCommand.php index 41ca9b60..d56e4101 100644 --- a/module/CLI/src/Command/Tag/ListTagsCommand.php +++ b/module/CLI/src/Command/Tag/ListTagsCommand.php @@ -13,13 +13,13 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use function Functional\map; +use function array_map; class ListTagsCommand extends Command { public const NAME = 'tag:list'; - public function __construct(private TagServiceInterface $tagService) + public function __construct(private readonly TagServiceInterface $tagService) { parent::__construct(); } @@ -44,9 +44,9 @@ class ListTagsCommand extends Command return [['No tags found', '-', '-']]; } - return map( - $tags, + return array_map( static fn (TagInfo $tagInfo) => [$tagInfo->tag, $tagInfo->shortUrlsCount, $tagInfo->visitsSummary->total], + [...$tags], ); } } diff --git a/module/CLI/src/Command/Visit/AbstractVisitsListCommand.php b/module/CLI/src/Command/Visit/AbstractVisitsListCommand.php index ba518656..a247380e 100644 --- a/module/CLI/src/Command/Visit/AbstractVisitsListCommand.php +++ b/module/CLI/src/Command/Visit/AbstractVisitsListCommand.php @@ -16,12 +16,15 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use function array_filter; use function array_keys; -use function Functional\map; -use function Functional\select_keys; +use function array_map; +use function in_array; use function Shlinkio\Shlink\Common\buildDateRange; use function Shlinkio\Shlink\Core\camelCaseToHumanFriendly; +use const ARRAY_FILTER_USE_KEY; + abstract class AbstractVisitsListCommand extends Command { private readonly StartDateOption $startDateOption; @@ -49,7 +52,7 @@ abstract class AbstractVisitsListCommand extends Command private function resolveRowsAndHeaders(Paginator $paginator): array { $extraKeys = []; - $rows = map($paginator->getCurrentPageResults(), function (Visit $visit) use (&$extraKeys) { + $rows = array_map(function (Visit $visit) use (&$extraKeys) { $extraFields = $this->mapExtraFields($visit); $extraKeys = array_keys($extraFields); @@ -60,9 +63,18 @@ abstract class AbstractVisitsListCommand extends Command ...$extraFields, ]; - return select_keys($rowData, ['referer', 'date', 'userAgent', 'country', 'city', ...$extraKeys]); - }); - $extra = map($extraKeys, camelCaseToHumanFriendly(...)); + // Filter out unknown keys + return array_filter( + $rowData, + static fn (string $key) => in_array( + $key, + ['referer', 'date', 'userAgent', 'country', 'city', ...$extraKeys], + strict: true, + ), + ARRAY_FILTER_USE_KEY, + ); + }, [...$paginator->getCurrentPageResults()]); + $extra = array_map(camelCaseToHumanFriendly(...), $extraKeys); return [ $rows, diff --git a/module/CLI/test/ApiKey/RoleResolverTest.php b/module/CLI/test/ApiKey/RoleResolverTest.php index 7aecda6d..cbd4f0fa 100644 --- a/module/CLI/test/ApiKey/RoleResolverTest.php +++ b/module/CLI/test/ApiKey/RoleResolverTest.php @@ -16,8 +16,6 @@ use Shlinkio\Shlink\Rest\ApiKey\Model\RoleDefinition; use Shlinkio\Shlink\Rest\ApiKey\Role; use Symfony\Component\Console\Input\InputInterface; -use function Functional\map; - class RoleResolverTest extends TestCase { private RoleResolver $resolver; @@ -49,10 +47,13 @@ class RoleResolverTest extends TestCase { $domain = self::domainWithId(Domain::withAuthority('example.com')); $buildInput = static fn (array $definition) => function (TestCase $test) use ($definition): InputInterface { + $returnMap = []; + foreach ($definition as $param => $returnValue) { + $returnMap[] = [$param, $returnValue]; + } + $input = $test->createStub(InputInterface::class); - $input->method('getOption')->willReturnMap( - map($definition, static fn (mixed $returnValue, string $param) => [$param, $returnValue]), - ); + $input->method('getOption')->willReturnMap($returnMap); return $input; }; diff --git a/module/CLI/test/GeoLite/GeolocationDbUpdaterTest.php b/module/CLI/test/GeoLite/GeolocationDbUpdaterTest.php index 9d32ca79..0f911db8 100644 --- a/module/CLI/test/GeoLite/GeolocationDbUpdaterTest.php +++ b/module/CLI/test/GeoLite/GeolocationDbUpdaterTest.php @@ -21,7 +21,7 @@ use Shlinkio\Shlink\IpGeolocation\GeoLite2\DbUpdaterInterface; use Symfony\Component\Lock; use Throwable; -use function Functional\map; +use function array_map; use function range; class GeolocationDbUpdaterTest extends TestCase @@ -128,7 +128,7 @@ class GeolocationDbUpdaterTest extends TestCase return [$days % 2 === 0 ? $timestamp : (string) $timestamp]; }; - return map(range(0, 34), $generateParamsWithTimestamp); + return array_map($generateParamsWithTimestamp, range(0, 34)); } #[Test] diff --git a/module/Core/functions/functions.php b/module/Core/functions/functions.php index b6acbb35..32d357e3 100644 --- a/module/Core/functions/functions.php +++ b/module/Core/functions/functions.php @@ -17,8 +17,8 @@ use PUGX\Shortid\Factory as ShortIdFactory; use Shlinkio\Shlink\Common\Util\DateRange; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlMode; +use function array_map; use function date_default_timezone_get; -use function Functional\map; use function Functional\reduce_left; use function is_array; use function print_r; @@ -177,6 +177,6 @@ function enumValues(string $enum): array } return $cache[$enum] ?? ( - $cache[$enum] = map($enum::cases(), static fn (BackedEnum $type) => (string) $type->value) + $cache[$enum] = array_map(static fn (BackedEnum $type) => (string) $type->value, $enum::cases()) ); } diff --git a/module/Core/src/Config/PostProcessor/BasePathPrefixer.php b/module/Core/src/Config/PostProcessor/BasePathPrefixer.php index 619e6056..616759f1 100644 --- a/module/Core/src/Config/PostProcessor/BasePathPrefixer.php +++ b/module/Core/src/Config/PostProcessor/BasePathPrefixer.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Config\PostProcessor; -use function Functional\map; +use function array_map; class BasePathPrefixer { @@ -23,13 +23,13 @@ class BasePathPrefixer private function prefixPathsWithBasePath(string $configKey, array $config, string $basePath): array { - return map($config[$configKey] ?? [], function (array $element) use ($basePath) { + return array_map(function (array $element) use ($basePath) { if (! isset($element['path'])) { return $element; } $element['path'] = $basePath . $element['path']; return $element; - }); + }, $config[$configKey] ?? []); } } diff --git a/module/Core/src/Config/PostProcessor/MultiSegmentSlugProcessor.php b/module/Core/src/Config/PostProcessor/MultiSegmentSlugProcessor.php index 33945063..585f78b6 100644 --- a/module/Core/src/Config/PostProcessor/MultiSegmentSlugProcessor.php +++ b/module/Core/src/Config/PostProcessor/MultiSegmentSlugProcessor.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\Config\PostProcessor; -use function Functional\map; +use function array_map; use function str_replace; class MultiSegmentSlugProcessor @@ -19,11 +19,11 @@ class MultiSegmentSlugProcessor return $config; } - $config['routes'] = map($config['routes'] ?? [], static function (array $route): array { + $config['routes'] = array_map(static function (array $route): array { ['path' => $path] = $route; $route['path'] = str_replace(self::SINGLE_SEGMENT_PATTERN, self::MULTI_SEGMENT_PATTERN, $path); return $route; - }); + }, $config['routes'] ?? []); return $config; } diff --git a/module/Core/src/Domain/DomainService.php b/module/Core/src/Domain/DomainService.php index 703f77fd..9aa4e3d0 100644 --- a/module/Core/src/Domain/DomainService.php +++ b/module/Core/src/Domain/DomainService.php @@ -14,9 +14,9 @@ use Shlinkio\Shlink\Core\Exception\DomainNotFoundException; use Shlinkio\Shlink\Rest\ApiKey\Role; use Shlinkio\Shlink\Rest\Entity\ApiKey; +use function array_map; use function Functional\first; use function Functional\group; -use function Functional\map; class DomainService implements DomainServiceInterface { @@ -30,7 +30,7 @@ class DomainService implements DomainServiceInterface public function listDomains(?ApiKey $apiKey = null): array { [$default, $domains] = $this->defaultDomainAndRest($apiKey); - $mappedDomains = map($domains, fn (Domain $domain) => DomainItem::forNonDefaultDomain($domain)); + $mappedDomains = array_map(fn (Domain $domain) => DomainItem::forNonDefaultDomain($domain), $domains); if ($apiKey?->hasRole(Role::DOMAIN_SPECIFIC)) { return $mappedDomains; diff --git a/module/Core/src/EventDispatcher/NotifyVisitToWebHooks.php b/module/Core/src/EventDispatcher/NotifyVisitToWebHooks.php index 317821b1..028c3c13 100644 --- a/module/Core/src/EventDispatcher/NotifyVisitToWebHooks.php +++ b/module/Core/src/EventDispatcher/NotifyVisitToWebHooks.php @@ -19,18 +19,18 @@ use Shlinkio\Shlink\Core\Options\WebhookOptions; use Shlinkio\Shlink\Core\Visit\Entity\Visit; use Throwable; -use function Functional\map; +use function array_map; /** @deprecated */ class NotifyVisitToWebHooks { public function __construct( - private ClientInterface $httpClient, - private EntityManagerInterface $em, - private LoggerInterface $logger, - private WebhookOptions $webhookOptions, - private DataTransformerInterface $transformer, - private AppOptions $appOptions, + private readonly ClientInterface $httpClient, + private readonly EntityManagerInterface $em, + private readonly LoggerInterface $logger, + private readonly WebhookOptions $webhookOptions, + private readonly DataTransformerInterface $transformer, + private readonly AppOptions $appOptions, ) { } @@ -82,11 +82,11 @@ class NotifyVisitToWebHooks */ private function performRequests(array $requestOptions, string $visitId): array { - return map( - $this->webhookOptions->webhooks(), + return array_map( fn (string $webhook): PromiseInterface => $this->httpClient ->requestAsync(RequestMethodInterface::METHOD_POST, $webhook, $requestOptions) ->otherwise(fn (Throwable $e) => $this->logWebhookFailure($webhook, $visitId, $e)), + $this->webhookOptions->webhooks(), ); } diff --git a/module/Core/src/ShortUrl/Entity/ShortUrl.php b/module/Core/src/ShortUrl/Entity/ShortUrl.php index 8fbec5ed..e53e9afa 100644 --- a/module/Core/src/ShortUrl/Entity/ShortUrl.php +++ b/module/Core/src/ShortUrl/Entity/ShortUrl.php @@ -27,8 +27,8 @@ use Shlinkio\Shlink\Importer\Model\ImportedShlinkUrl; use Shlinkio\Shlink\Rest\Entity\ApiKey; use function array_fill_keys; +use function array_map; use function count; -use function Functional\map; use function Shlinkio\Shlink\Core\enumValues; use function Shlinkio\Shlink\Core\generateRandomShortCode; use function Shlinkio\Shlink\Core\normalizeDate; @@ -90,9 +90,9 @@ class ShortUrl extends AbstractEntity $instance->longUrl = $creation->getLongUrl(); $instance->dateCreated = Chronos::now(); $instance->visits = new ArrayCollection(); - $instance->deviceLongUrls = new ArrayCollection(map( - $creation->deviceLongUrls, + $instance->deviceLongUrls = new ArrayCollection(array_map( fn (DeviceLongUrlPair $pair) => DeviceLongUrl::fromShortUrlAndPair($instance, $pair), + $creation->deviceLongUrls, )); $instance->tags = $relationResolver->resolveTags($creation->tags); $instance->validSince = $creation->validSince; diff --git a/module/Core/src/ShortUrl/Model/DeviceLongUrlPair.php b/module/Core/src/ShortUrl/Model/DeviceLongUrlPair.php index d017c7e5..c7b1efc0 100644 --- a/module/Core/src/ShortUrl/Model/DeviceLongUrlPair.php +++ b/module/Core/src/ShortUrl/Model/DeviceLongUrlPair.php @@ -6,9 +6,7 @@ namespace Shlinkio\Shlink\Core\ShortUrl\Model; use Shlinkio\Shlink\Core\Model\DeviceType; -use function array_values; use function Functional\group; -use function Functional\map; use function trim; final class DeviceLongUrlPair @@ -32,15 +30,23 @@ final class DeviceLongUrlPair */ public static function fromMapToChangeSet(array $map): array { + $toRemove = []; // TODO Use when group is removed + $toKeep = []; // TODO Use when group is removed $typesWithNullUrl = group($map, static fn (?string $longUrl) => $longUrl === null ? 'remove' : 'keep'); - $deviceTypesToRemove = array_values(map( - $typesWithNullUrl['remove'] ?? [], - static fn ($_, string $deviceType) => DeviceType::from($deviceType), - )); - $pairsToKeep = map( - $typesWithNullUrl['keep'] ?? [], - fn (string $longUrl, string $deviceType) => self::fromRawTypeAndLongUrl($deviceType, $longUrl), - ); + + $deviceTypesToRemove = []; + foreach ($typesWithNullUrl['remove'] ?? [] as $deviceType => $_) { + $deviceTypesToRemove[] = DeviceType::from($deviceType); + } + + $pairsToKeep = []; + /** + * @var string $deviceType + * @var string $longUrl + */ + foreach ($typesWithNullUrl['keep'] ?? [] as $deviceType => $longUrl) { + $pairsToKeep[$deviceType] = self::fromRawTypeAndLongUrl($deviceType, $longUrl); + } return [$pairsToKeep, $deviceTypesToRemove]; } diff --git a/module/Core/src/ShortUrl/Resolver/PersistenceShortUrlRelationResolver.php b/module/Core/src/ShortUrl/Resolver/PersistenceShortUrlRelationResolver.php index 17669f32..6c49ab5f 100644 --- a/module/Core/src/ShortUrl/Resolver/PersistenceShortUrlRelationResolver.php +++ b/module/Core/src/ShortUrl/Resolver/PersistenceShortUrlRelationResolver.php @@ -15,9 +15,8 @@ use Symfony\Component\Lock\Lock; use Symfony\Component\Lock\LockFactory; use Symfony\Component\Lock\Store\InMemoryStore; -use function Functional\invoke; -use function Functional\map; -use function Functional\unique; +use function array_map; +use function array_unique; class PersistenceShortUrlRelationResolver implements ShortUrlRelationResolverInterface { @@ -74,10 +73,10 @@ class PersistenceShortUrlRelationResolver implements ShortUrlRelationResolverInt return new Collections\ArrayCollection(); } - $tags = unique($tags); + $tags = array_unique($tags); $repo = $this->em->getRepository(Tag::class); - return new Collections\ArrayCollection(map($tags, function (string $tagName) use ($repo): Tag { + return new Collections\ArrayCollection(array_map(function (string $tagName) use ($repo): Tag { $this->lock($this->tagLocks, 'tag_' . $tagName); $existingTag = $repo->findOneBy(['name' => $tagName]); @@ -91,7 +90,7 @@ class PersistenceShortUrlRelationResolver implements ShortUrlRelationResolverInt $this->em->persist($tag); return $tag; - })); + }, $tags)); } private function memoizeNewTag(string $tagName): Tag @@ -110,6 +109,7 @@ class PersistenceShortUrlRelationResolver implements ShortUrlRelationResolverInt $lock->acquire(true); } + /** /** * @param array $locks */ @@ -126,9 +126,15 @@ class PersistenceShortUrlRelationResolver implements ShortUrlRelationResolverInt $this->memoizedNewTags = []; // Release all locks - invoke($this->tagLocks, 'release'); - invoke($this->domainLocks, 'release'); - $this->tagLocks = []; - $this->domainLocks = []; + $this->releaseLocks($this->tagLocks); + $this->releaseLocks($this->domainLocks); + } + + private function releaseLocks(array &$locks): void + { + foreach ($locks as $tagLock) { + $tagLock->release(); + } + $locks = []; } } diff --git a/module/Core/src/ShortUrl/Resolver/SimpleShortUrlRelationResolver.php b/module/Core/src/ShortUrl/Resolver/SimpleShortUrlRelationResolver.php index 609a300c..c1a9d0ab 100644 --- a/module/Core/src/ShortUrl/Resolver/SimpleShortUrlRelationResolver.php +++ b/module/Core/src/ShortUrl/Resolver/SimpleShortUrlRelationResolver.php @@ -8,7 +8,7 @@ use Doctrine\Common\Collections; use Shlinkio\Shlink\Core\Domain\Entity\Domain; use Shlinkio\Shlink\Core\Tag\Entity\Tag; -use function Functional\map; +use function array_map; class SimpleShortUrlRelationResolver implements ShortUrlRelationResolverInterface { @@ -23,6 +23,6 @@ class SimpleShortUrlRelationResolver implements ShortUrlRelationResolverInterfac */ public function resolveTags(array $tags): Collections\Collection { - return new Collections\ArrayCollection(map($tags, fn (string $tag) => new Tag($tag))); + return new Collections\ArrayCollection(array_map(fn (string $tag) => new Tag($tag), $tags)); } } diff --git a/module/Core/src/ShortUrl/Transformer/ShortUrlDataTransformer.php b/module/Core/src/ShortUrl/Transformer/ShortUrlDataTransformer.php index 9de5c408..a6641998 100644 --- a/module/Core/src/ShortUrl/Transformer/ShortUrlDataTransformer.php +++ b/module/Core/src/ShortUrl/Transformer/ShortUrlDataTransformer.php @@ -7,10 +7,10 @@ namespace Shlinkio\Shlink\Core\ShortUrl\Transformer; use Shlinkio\Shlink\Common\Rest\DataTransformerInterface; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifierInterface; +use Shlinkio\Shlink\Core\Tag\Entity\Tag; use Shlinkio\Shlink\Core\Visit\Model\VisitsSummary; -use function Functional\invoke; -use function Functional\invoke_if; +use function array_map; class ShortUrlDataTransformer implements DataTransformerInterface { @@ -29,7 +29,7 @@ class ShortUrlDataTransformer implements DataTransformerInterface 'longUrl' => $shortUrl->getLongUrl(), 'deviceLongUrls' => $shortUrl->deviceLongUrls(), 'dateCreated' => $shortUrl->getDateCreated()->toAtomString(), - 'tags' => invoke($shortUrl->getTags(), '__toString'), + 'tags' => array_map(static fn (Tag $tag) => $tag->__toString(), $shortUrl->getTags()->toArray()), 'meta' => $this->buildMeta($shortUrl), 'domain' => $shortUrl->getDomain(), 'title' => $shortUrl->title(), @@ -52,8 +52,8 @@ class ShortUrlDataTransformer implements DataTransformerInterface $maxVisits = $shortUrl->getMaxVisits(); return [ - 'validSince' => invoke_if($validSince, 'toAtomString'), - 'validUntil' => invoke_if($validUntil, 'toAtomString'), + 'validSince' => $validSince?->toAtomString(), + 'validUntil' => $validUntil?->toAtomString(), 'maxVisits' => $maxVisits, ]; } diff --git a/module/Core/src/Tag/Repository/TagRepository.php b/module/Core/src/Tag/Repository/TagRepository.php index 278dbe8b..d74da44a 100644 --- a/module/Core/src/Tag/Repository/TagRepository.php +++ b/module/Core/src/Tag/Repository/TagRepository.php @@ -17,8 +17,8 @@ use Shlinkio\Shlink\Rest\ApiKey\Role; use Shlinkio\Shlink\Rest\ApiKey\Spec\WithApiKeySpecsEnsuringJoin; use Shlinkio\Shlink\Rest\Entity\ApiKey; +use function array_map; use function Functional\each; -use function Functional\map; use function Shlinkio\Shlink\Core\camelCaseToSnakeCase; use const PHP_INT_MAX; @@ -126,9 +126,9 @@ class TagRepository extends EntitySpecificationRepository implements TagReposito $rsm->addScalarResult('non_bot_visits', 'nonBotVisits'); $rsm->addScalarResult('short_urls_count', 'shortUrlsCount'); - return map( - $this->getEntityManager()->createNativeQuery($mainQb->getSQL(), $rsm)->getResult(), + return array_map( TagInfo::fromRawData(...), + $this->getEntityManager()->createNativeQuery($mainQb->getSQL(), $rsm)->getResult(), ); } diff --git a/module/Core/src/Visit/RequestTracker.php b/module/Core/src/Visit/RequestTracker.php index cb43e10d..e8647165 100644 --- a/module/Core/src/Visit/RequestTracker.php +++ b/module/Core/src/Visit/RequestTracker.php @@ -16,9 +16,9 @@ use Shlinkio\Shlink\Core\Options\TrackingOptions; use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl; use Shlinkio\Shlink\Core\Visit\Model\Visitor; +use function array_keys; +use function array_map; use function explode; -use function Functional\map; -use function Functional\some; use function implode; use function str_contains; @@ -85,22 +85,30 @@ class RequestTracker implements RequestTrackerInterface, RequestMethodInterface $remoteAddrParts = explode('.', $remoteAddr); $disableTrackingFrom = $this->trackingOptions->disableTrackingFrom; - return some($disableTrackingFrom, function (string $value) use ($ip, $remoteAddrParts): bool { + foreach ($disableTrackingFrom as $value) { $range = str_contains($value, '*') ? $this->parseValueWithWildcards($value, $remoteAddrParts) : Factory::parseRangeString($value); - return $range !== null && $ip->matches($range); - }); + if ($range !== null && $ip->matches($range)) { + return true; + } + } + + return false; } private function parseValueWithWildcards(string $value, array $remoteAddrParts): ?RangeInterface { + $octets = explode('.', $value); + $keys = array_keys($octets); + // Replace wildcard parts with the corresponding ones from the remote address return Factory::parseRangeString( - implode('.', map( - explode('.', $value), + implode('.', array_map( fn (string $part, int $index) => $part === '*' ? $remoteAddrParts[$index] : $part, + $octets, + $keys, )), ); } diff --git a/module/Core/test-db/ShortUrl/Repository/ShortUrlListRepositoryTest.php b/module/Core/test-db/ShortUrl/Repository/ShortUrlListRepositoryTest.php index 46c08d25..b359e35d 100644 --- a/module/Core/test-db/ShortUrl/Repository/ShortUrlListRepositoryTest.php +++ b/module/Core/test-db/ShortUrl/Repository/ShortUrlListRepositoryTest.php @@ -22,8 +22,8 @@ use Shlinkio\Shlink\Core\Visit\Entity\Visit; use Shlinkio\Shlink\Core\Visit\Model\Visitor; use Shlinkio\Shlink\TestUtils\DbTest\DatabaseTestCase; +use function array_map; use function count; -use function Functional\map; use function range; class ShortUrlListRepositoryTest extends DatabaseTestCase @@ -60,22 +60,22 @@ class ShortUrlListRepositoryTest extends DatabaseTestCase $this->getEntityManager()->persist($foo); $bar = ShortUrl::withLongUrl('https://bar'); - $visits = map(range(0, 5), function () use ($bar) { + $visits = array_map(function () use ($bar) { $visit = Visit::forValidShortUrl($bar, Visitor::botInstance()); $this->getEntityManager()->persist($visit); return $visit; - }); + }, range(0, 5)); $bar->setVisits(new ArrayCollection($visits)); $this->getEntityManager()->persist($bar); $foo2 = ShortUrl::withLongUrl('https://foo_2'); - $visits2 = map(range(0, 3), function () use ($foo2) { + $visits2 = array_map(function () use ($foo2) { $visit = Visit::forValidShortUrl($foo2, Visitor::emptyInstance()); $this->getEntityManager()->persist($visit); return $visit; - }); + }, range(0, 3)); $foo2->setVisits(new ArrayCollection($visits2)); $ref = new ReflectionObject($foo2); $dateProp = $ref->getProperty('dateCreated'); diff --git a/module/Core/test-db/Tag/Paginator/Adapter/TagsPaginatorAdapterTest.php b/module/Core/test-db/Tag/Paginator/Adapter/TagsPaginatorAdapterTest.php index 0dd83341..f88a8e7f 100644 --- a/module/Core/test-db/Tag/Paginator/Adapter/TagsPaginatorAdapterTest.php +++ b/module/Core/test-db/Tag/Paginator/Adapter/TagsPaginatorAdapterTest.php @@ -12,7 +12,7 @@ use Shlinkio\Shlink\Core\Tag\Paginator\Adapter\TagsPaginatorAdapter; use Shlinkio\Shlink\Core\Tag\Repository\TagRepository; use Shlinkio\Shlink\TestUtils\DbTest\DatabaseTestCase; -use function Functional\map; +use function array_map; class TagsPaginatorAdapterTest extends DatabaseTestCase { @@ -47,7 +47,7 @@ class TagsPaginatorAdapterTest extends DatabaseTestCase 'orderBy' => $orderBy, ]), null); - $tagNames = map($adapter->getSlice($offset, $length), static fn (Tag $tag) => $tag->__toString()); + $tagNames = array_map(static fn (Tag $tag) => $tag->__toString(), [...$adapter->getSlice($offset, $length)]); self::assertEquals($expectedTags, $tagNames); self::assertEquals($expectedTotalCount, $adapter->getNbResults()); diff --git a/module/Core/test-db/Visit/Repository/VisitLocationRepositoryTest.php b/module/Core/test-db/Visit/Repository/VisitLocationRepositoryTest.php index 79c80a24..c5aadf1f 100644 --- a/module/Core/test-db/Visit/Repository/VisitLocationRepositoryTest.php +++ b/module/Core/test-db/Visit/Repository/VisitLocationRepositoryTest.php @@ -14,7 +14,7 @@ use Shlinkio\Shlink\Core\Visit\Repository\VisitLocationRepository; use Shlinkio\Shlink\IpGeolocation\Model\Location; use Shlinkio\Shlink\TestUtils\DbTest\DatabaseTestCase; -use function Functional\map; +use function array_map; use function range; class VisitLocationRepositoryTest extends DatabaseTestCase @@ -57,6 +57,6 @@ class VisitLocationRepositoryTest extends DatabaseTestCase public static function provideBlockSize(): iterable { - return map(range(1, 10), fn (int $value) => [$value]); + return array_map(static fn (int $value) => [$value], range(1, 10)); } } diff --git a/module/Core/test/EventDispatcher/UpdateGeoLiteDbTest.php b/module/Core/test/EventDispatcher/UpdateGeoLiteDbTest.php index 6ba20ec8..dc604521 100644 --- a/module/Core/test/EventDispatcher/UpdateGeoLiteDbTest.php +++ b/module/Core/test/EventDispatcher/UpdateGeoLiteDbTest.php @@ -16,7 +16,7 @@ use Shlinkio\Shlink\CLI\GeoLite\GeolocationResult; use Shlinkio\Shlink\Core\EventDispatcher\Event\GeoLiteDbCreated; use Shlinkio\Shlink\Core\EventDispatcher\UpdateGeoLiteDb; -use function Functional\map; +use function array_map; class UpdateGeoLiteDbTest extends TestCase { @@ -124,9 +124,9 @@ class UpdateGeoLiteDbTest extends TestCase public static function provideGeolocationResults(): iterable { - return map(GeolocationResult::cases(), static fn (GeolocationResult $value) => [ + return array_map(static fn (GeolocationResult $value) => [ $value, $value === GeolocationResult::DB_CREATED ? 1 : 0, - ]); + ], GeolocationResult::cases()); } } diff --git a/module/Core/test/Exception/DeleteShortUrlExceptionTest.php b/module/Core/test/Exception/DeleteShortUrlExceptionTest.php index 8d82c11e..c1b2bcec 100644 --- a/module/Core/test/Exception/DeleteShortUrlExceptionTest.php +++ b/module/Core/test/Exception/DeleteShortUrlExceptionTest.php @@ -10,7 +10,7 @@ use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\Core\Exception\DeleteShortUrlException; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlIdentifier; -use function Functional\map; +use function array_map; use function range; use function Shlinkio\Shlink\Core\generateRandomShortCode; use function sprintf; @@ -42,13 +42,13 @@ class DeleteShortUrlExceptionTest extends TestCase public static function provideThresholds(): array { - return map(range(5, 50, 5), function (int $number) { + return array_map(function (int $number) { return [$number, $shortCode = generateRandomShortCode(6), sprintf( 'Impossible to delete short URL with short code "%s", since it has more than "%s" visits.', $shortCode, $number, )]; - }); + }, range(5, 50, 5)); } #[Test] diff --git a/module/Core/test/Functions/FunctionsTest.php b/module/Core/test/Functions/FunctionsTest.php index 3f6026a0..715685af 100644 --- a/module/Core/test/Functions/FunctionsTest.php +++ b/module/Core/test/Functions/FunctionsTest.php @@ -13,7 +13,7 @@ use Shlinkio\Shlink\Core\Model\DeviceType; use Shlinkio\Shlink\Core\ShortUrl\Model\OrderableField; use Shlinkio\Shlink\Core\Visit\Model\VisitType; -use function Functional\map; +use function array_map; use function Shlinkio\Shlink\Core\enumValues; class FunctionsTest extends TestCase @@ -29,18 +29,21 @@ class FunctionsTest extends TestCase public static function provideEnums(): iterable { - yield EnvVars::class => [EnvVars::class, map(EnvVars::cases(), static fn (EnvVars $envVar) => $envVar->value)]; + yield EnvVars::class => [ + EnvVars::class, + array_map(static fn (EnvVars $envVar) => $envVar->value, EnvVars::cases()), + ]; yield VisitType::class => [ VisitType::class, - map(VisitType::cases(), static fn (VisitType $envVar) => $envVar->value), + array_map(static fn (VisitType $envVar) => $envVar->value, VisitType::cases()), ]; yield DeviceType::class => [ DeviceType::class, - map(DeviceType::cases(), static fn (DeviceType $envVar) => $envVar->value), + array_map(static fn (DeviceType $envVar) => $envVar->value, DeviceType::cases()), ]; yield OrderableField::class => [ OrderableField::class, - map(OrderableField::cases(), static fn (OrderableField $envVar) => $envVar->value), + array_map(static fn (OrderableField $envVar) => $envVar->value, OrderableField::cases()), ]; } } diff --git a/module/Core/test/ShortUrl/DeleteShortUrlServiceTest.php b/module/Core/test/ShortUrl/DeleteShortUrlServiceTest.php index 65351a93..3ac9897c 100644 --- a/module/Core/test/ShortUrl/DeleteShortUrlServiceTest.php +++ b/module/Core/test/ShortUrl/DeleteShortUrlServiceTest.php @@ -18,7 +18,7 @@ use Shlinkio\Shlink\Core\ShortUrl\ShortUrlResolverInterface; use Shlinkio\Shlink\Core\Visit\Entity\Visit; use Shlinkio\Shlink\Core\Visit\Model\Visitor; -use function Functional\map; +use function array_map; use function range; use function sprintf; @@ -31,7 +31,7 @@ class DeleteShortUrlServiceTest extends TestCase protected function setUp(): void { $shortUrl = ShortUrl::createFake()->setVisits(new ArrayCollection( - map(range(0, 10), fn () => Visit::forValidShortUrl(ShortUrl::createFake(), Visitor::emptyInstance())), + array_map(fn () => Visit::forValidShortUrl(ShortUrl::createFake(), Visitor::emptyInstance()), range(0, 10)), )); $this->shortCode = $shortUrl->getShortCode(); diff --git a/module/Core/test/ShortUrl/Entity/ShortUrlTest.php b/module/Core/test/ShortUrl/Entity/ShortUrlTest.php index bd83fd9a..c1d66e61 100644 --- a/module/Core/test/ShortUrl/Entity/ShortUrlTest.php +++ b/module/Core/test/ShortUrl/Entity/ShortUrlTest.php @@ -19,8 +19,8 @@ use Shlinkio\Shlink\Core\ShortUrl\Model\Validation\ShortUrlInputFilter; use Shlinkio\Shlink\Importer\Model\ImportedShlinkUrl; use Shlinkio\Shlink\Importer\Sources\ImportSource; +use function array_map; use function Functional\every; -use function Functional\map; use function range; use function strlen; use function strtolower; @@ -88,7 +88,7 @@ class ShortUrlTest extends TestCase public static function provideLengths(): iterable { yield [null, DEFAULT_SHORT_CODES_LENGTH]; - yield from map(range(4, 10), fn (int $value) => [$value, $value]); + yield from array_map(fn (int $value) => [$value, $value], range(4, 10)); } #[Test] diff --git a/module/Core/test/ShortUrl/ShortUrlResolverTest.php b/module/Core/test/ShortUrl/ShortUrlResolverTest.php index 4057691b..a95426ba 100644 --- a/module/Core/test/ShortUrl/ShortUrlResolverTest.php +++ b/module/Core/test/ShortUrl/ShortUrlResolverTest.php @@ -25,7 +25,7 @@ use Shlinkio\Shlink\Core\Visit\Model\Visitor; use Shlinkio\Shlink\Rest\Entity\ApiKey; use ShlinkioTest\Shlink\Core\Util\ApiKeyDataProviders; -use function Functional\map; +use function array_map; use function range; class ShortUrlResolverTest extends TestCase @@ -113,9 +113,9 @@ class ShortUrlResolverTest extends TestCase $shortUrl = ShortUrl::create( ShortUrlCreation::fromRawData(['maxVisits' => 3, 'longUrl' => 'https://longUrl']), ); - $shortUrl->setVisits(new ArrayCollection(map( - range(0, 4), + $shortUrl->setVisits(new ArrayCollection(array_map( fn () => Visit::forValidShortUrl($shortUrl, Visitor::emptyInstance()), + range(0, 4), ))); return $shortUrl; @@ -132,9 +132,9 @@ class ShortUrlResolverTest extends TestCase 'validUntil' => $now->subMonths(1)->toAtomString(), 'longUrl' => 'https://longUrl', ])); - $shortUrl->setVisits(new ArrayCollection(map( - range(0, 4), + $shortUrl->setVisits(new ArrayCollection(array_map( fn () => Visit::forValidShortUrl($shortUrl, Visitor::emptyInstance()), + range(0, 4), ))); return $shortUrl; diff --git a/module/Core/test/ShortUrl/Transformer/ShortUrlDataTransformerTest.php b/module/Core/test/ShortUrl/Transformer/ShortUrlDataTransformerTest.php index 27916063..349392db 100644 --- a/module/Core/test/ShortUrl/Transformer/ShortUrlDataTransformerTest.php +++ b/module/Core/test/ShortUrl/Transformer/ShortUrlDataTransformerTest.php @@ -84,4 +84,14 @@ class ShortUrlDataTransformerTest extends TestCase ], ]; } + + #[Test] + public function properTagsAreReturned(): void + { + ['tags' => $tags] = $this->transformer->transform(ShortUrl::create(ShortUrlCreation::fromRawData([ + 'longUrl' => 'https://longUrl', + 'tags' => ['foo', 'bar', 'baz'], + ]))); + self::assertEquals(['foo', 'bar', 'baz'], $tags); + } } diff --git a/module/Core/test/Visit/Geolocation/VisitLocatorTest.php b/module/Core/test/Visit/Geolocation/VisitLocatorTest.php index 70fc6243..1d3af228 100644 --- a/module/Core/test/Visit/Geolocation/VisitLocatorTest.php +++ b/module/Core/test/Visit/Geolocation/VisitLocatorTest.php @@ -20,9 +20,9 @@ use Shlinkio\Shlink\Core\Visit\Model\Visitor; use Shlinkio\Shlink\Core\Visit\Repository\VisitLocationRepositoryInterface; use Shlinkio\Shlink\IpGeolocation\Model\Location; +use function array_map; use function count; use function floor; -use function Functional\map; use function range; use function sprintf; @@ -45,12 +45,12 @@ class VisitLocatorTest extends TestCase string $serviceMethodName, string $expectedRepoMethodName, ): void { - $unlocatedVisits = map( - range(1, 200), + $unlocatedVisits = array_map( fn (int $i) => Visit::forValidShortUrl( ShortUrl::withLongUrl(sprintf('https://short_code_%s', $i)), Visitor::emptyInstance(), ), + range(1, 200), ); $this->repo->expects($this->once())->method($expectedRepoMethodName)->willReturn($unlocatedVisits); diff --git a/module/Core/test/Visit/VisitsStatsHelperTest.php b/module/Core/test/Visit/VisitsStatsHelperTest.php index d43efc24..dd11fdef 100644 --- a/module/Core/test/Visit/VisitsStatsHelperTest.php +++ b/module/Core/test/Visit/VisitsStatsHelperTest.php @@ -33,8 +33,8 @@ use Shlinkio\Shlink\Core\Visit\VisitsStatsHelper; use Shlinkio\Shlink\Rest\Entity\ApiKey; use ShlinkioTest\Shlink\Core\Util\ApiKeyDataProviders; +use function array_map; use function count; -use function Functional\map; use function range; class VisitsStatsHelperTest extends TestCase @@ -75,8 +75,8 @@ class VisitsStatsHelperTest extends TestCase public static function provideCounts(): iterable { return [ - ...map(range(0, 50, 5), fn (int $value) => [$value, null]), - ...map(range(0, 18, 3), fn (int $value) => [$value, ApiKey::create()]), + ...array_map(fn (int $value) => [$value, null], range(0, 50, 5)), + ...array_map(fn (int $value) => [$value, ApiKey::create()], range(0, 18, 3)), ]; } @@ -90,7 +90,10 @@ class VisitsStatsHelperTest extends TestCase $repo = $this->createMock(ShortUrlRepositoryInterface::class); $repo->expects($this->once())->method('shortCodeIsInUse')->with($identifier, $spec)->willReturn(true); - $list = map(range(0, 1), fn () => Visit::forValidShortUrl(ShortUrl::createFake(), Visitor::emptyInstance())); + $list = array_map( + static fn () => Visit::forValidShortUrl(ShortUrl::createFake(), Visitor::emptyInstance()), + range(0, 1), + ); $repo2 = $this->createMock(VisitRepository::class); $repo2->method('findVisitsByShortCode')->with( $identifier, @@ -147,7 +150,10 @@ class VisitsStatsHelperTest extends TestCase $repo = $this->createMock(TagRepository::class); $repo->expects($this->once())->method('tagExists')->with($tag, $apiKey)->willReturn(true); - $list = map(range(0, 1), fn () => Visit::forValidShortUrl(ShortUrl::createFake(), Visitor::emptyInstance())); + $list = array_map( + static fn () => Visit::forValidShortUrl(ShortUrl::createFake(), Visitor::emptyInstance()), + range(0, 1), + ); $repo2 = $this->createMock(VisitRepository::class); $repo2->method('findVisitsByTag')->with($tag, $this->isInstanceOf(VisitsListFiltering::class))->willReturn( $list, @@ -185,7 +191,10 @@ class VisitsStatsHelperTest extends TestCase $repo = $this->createMock(DomainRepository::class); $repo->expects($this->once())->method('domainExists')->with($domain, $apiKey)->willReturn(true); - $list = map(range(0, 1), fn () => Visit::forValidShortUrl(ShortUrl::createFake(), Visitor::emptyInstance())); + $list = array_map( + static fn () => Visit::forValidShortUrl(ShortUrl::createFake(), Visitor::emptyInstance()), + range(0, 1), + ); $repo2 = $this->createMock(VisitRepository::class); $repo2->method('findVisitsByDomain')->with( $domain, @@ -212,7 +221,10 @@ class VisitsStatsHelperTest extends TestCase $repo = $this->createMock(DomainRepository::class); $repo->expects($this->never())->method('domainExists'); - $list = map(range(0, 1), fn () => Visit::forValidShortUrl(ShortUrl::createFake(), Visitor::emptyInstance())); + $list = array_map( + static fn () => Visit::forValidShortUrl(ShortUrl::createFake(), Visitor::emptyInstance()), + range(0, 1), + ); $repo2 = $this->createMock(VisitRepository::class); $repo2->method('findVisitsByDomain')->with( 'DEFAULT', @@ -236,7 +248,7 @@ class VisitsStatsHelperTest extends TestCase #[Test] public function orphanVisitsAreReturnedAsExpected(): void { - $list = map(range(0, 3), fn () => Visit::forBasePath(Visitor::emptyInstance())); + $list = array_map(static fn () => Visit::forBasePath(Visitor::emptyInstance()), range(0, 3)); $repo = $this->createMock(VisitRepository::class); $repo->expects($this->once())->method('countOrphanVisits')->with( $this->isInstanceOf(VisitsCountFiltering::class), @@ -254,7 +266,10 @@ class VisitsStatsHelperTest extends TestCase #[Test] public function nonOrphanVisitsAreReturnedAsExpected(): void { - $list = map(range(0, 3), fn () => Visit::forValidShortUrl(ShortUrl::createFake(), Visitor::emptyInstance())); + $list = array_map( + static fn () => Visit::forValidShortUrl(ShortUrl::createFake(), Visitor::emptyInstance()), + range(0, 3), + ); $repo = $this->createMock(VisitRepository::class); $repo->expects($this->once())->method('countNonOrphanVisits')->with( $this->isInstanceOf(VisitsCountFiltering::class), diff --git a/module/Rest/config/access-logs.config.php b/module/Rest/config/access-logs.config.php index 1f0dd0e8..def1a93a 100644 --- a/module/Rest/config/access-logs.config.php +++ b/module/Rest/config/access-logs.config.php @@ -11,7 +11,7 @@ use Shlinkio\Shlink\Common\Middleware\AccessLogMiddleware; return [ 'access_logs' => [ - 'ignored_paths' => [ + 'ignored_path_prefixes' => [ Action\HealthAction::ROUTE_PATH, ], ], @@ -20,7 +20,7 @@ return [ ConfigAbstractFactory::class => [ // Use MergeReplaceKey to overwrite what was defined in shlink-common, instead of merging it AccessLogMiddleware::class => new MergeReplaceKey( - [AccessLogMiddleware::LOGGER_SERVICE_NAME, 'config.access_logs.ignored_paths'], + [AccessLogMiddleware::LOGGER_SERVICE_NAME, 'config.access_logs.ignored_path_prefixes'], ), ], diff --git a/module/Rest/src/Action/Tag/ListTagsAction.php b/module/Rest/src/Action/Tag/ListTagsAction.php index 34f44475..9674d5bc 100644 --- a/module/Rest/src/Action/Tag/ListTagsAction.php +++ b/module/Rest/src/Action/Tag/ListTagsAction.php @@ -14,7 +14,7 @@ use Shlinkio\Shlink\Core\Tag\TagServiceInterface; use Shlinkio\Shlink\Rest\Action\AbstractRestAction; use Shlinkio\Shlink\Rest\Middleware\AuthenticationMiddleware; -use function Functional\map; +use function array_map; class ListTagsAction extends AbstractRestAction { @@ -41,7 +41,7 @@ class ListTagsAction extends AbstractRestAction // This part is deprecated. To get tags with stats, the /tags/stats endpoint should be used instead $tagsInfo = $this->tagService->tagsInfo($params, $apiKey); $rawTags = $this->serializePaginator($tagsInfo, dataProp: 'stats'); - $rawTags['data'] = map($tagsInfo, static fn (TagInfo $info) => $info->tag); + $rawTags['data'] = array_map(static fn (TagInfo $info) => $info->tag, [...$tagsInfo]); return new JsonResponse(['tags' => $rawTags]); } diff --git a/module/Rest/src/ConfigProvider.php b/module/Rest/src/ConfigProvider.php index 215a4d6e..7c57d8b1 100644 --- a/module/Rest/src/ConfigProvider.php +++ b/module/Rest/src/ConfigProvider.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Rest; +use function array_map; use function Functional\first; -use function Functional\map; use function Shlinkio\Shlink\Config\loadConfigFromGlob; use function sprintf; @@ -23,11 +23,11 @@ class ConfigProvider public static function applyRoutesPrefix(array $routes): array { $healthRoute = self::buildUnversionedHealthRouteFromExistingRoutes($routes); - $prefixedRoutes = map($routes, static function (array $route) { + $prefixedRoutes = array_map(static function (array $route) { ['path' => $path] = $route; $route['path'] = sprintf('%s%s', self::ROUTES_PREFIX, $path); return $route; - }); + }, $routes); return $healthRoute !== null ? [...$prefixedRoutes, $healthRoute] : $prefixedRoutes; } diff --git a/module/Rest/test-api/Action/CreateShortUrlTest.php b/module/Rest/test-api/Action/CreateShortUrlTest.php index 78f738a3..01592129 100644 --- a/module/Rest/test-api/Action/CreateShortUrlTest.php +++ b/module/Rest/test-api/Action/CreateShortUrlTest.php @@ -10,7 +10,7 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase; -use function Functional\map; +use function array_map; use function range; use function sprintf; @@ -108,7 +108,7 @@ class CreateShortUrlTest extends ApiTestCase public static function provideMaxVisits(): array { - return map(range(10, 15), fn(int $i) => [$i]); + return array_map(static fn (int $i) => [$i], range(10, 15)); } #[Test]