mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Replaced regular callbacks by arrow functions when possible
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
|
||||
@@ -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
|
||||
), '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user