mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Remove usage of Functional\map function
This commit is contained in:
@@ -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())
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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] ?? []);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
@@ -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<string, Lock> $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 = [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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()),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user