Replaced some array_map by Functional\map

This commit is contained in:
Alejandro Celaya 2018-11-02 12:05:01 +01:00
parent 664dc333ac
commit f64920e510
4 changed files with 12 additions and 18 deletions

View file

@ -10,7 +10,7 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Zend\I18n\Translator\TranslatorInterface;
use function array_map;
use function Functional\map;
class ListTagsCommand extends Command
{
@ -45,15 +45,15 @@ class ListTagsCommand extends Command
$io->table([$this->translator->translate('Name')], $this->getTagsRows());
}
private function getTagsRows()
private function getTagsRows(): array
{
$tags = $this->tagService->listTags();
if (empty($tags)) {
return [[$this->translator->translate('No tags yet')]];
}
return array_map(function (Tag $tag) {
return map($tags, function (Tag $tag) {
return [(string) $tag];
}, $tags);
});
}
}

View file

@ -5,9 +5,8 @@ namespace Shlinkio\Shlink\Core\Transformer;
use Shlinkio\Shlink\Common\Rest\DataTransformerInterface;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Entity\Tag;
use Shlinkio\Shlink\Core\Util\ShortUrlBuilderTrait;
use function array_map;
use function Functional\invoke;
class ShortUrlDataTransformer implements DataTransformerInterface
{
@ -38,15 +37,10 @@ class ShortUrlDataTransformer implements DataTransformerInterface
'longUrl' => $longUrl,
'dateCreated' => $dateCreated !== null ? $dateCreated->toAtomString() : null,
'visitsCount' => $value->getVisitsCount(),
'tags' => array_map([$this, 'serializeTag'], $value->getTags()->toArray()),
'tags' => invoke($value->getTags(), '__toString'),
// Deprecated
'originalUrl' => $longUrl,
];
}
private function serializeTag(Tag $tag): string
{
return (string) $tag;
}
}

View file

@ -5,7 +5,7 @@ namespace ShlinkioTest\Shlink\Core\Exception;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Core\Exception\DeleteShortUrlException;
use function array_map;
use function Functional\map;
use function range;
class DeleteShortUrlExceptionTest extends TestCase
@ -56,8 +56,8 @@ class DeleteShortUrlExceptionTest extends TestCase
public function provideThresholds(): array
{
return array_map(function (int $number) {
return map(range(5, 50, 5), function (int $number) {
return [$number];
}, range(5, 50, 5));
});
}
}

View file

@ -15,7 +15,7 @@ use Shlinkio\Shlink\Core\Model\Visitor;
use Shlinkio\Shlink\Core\Options\DeleteShortUrlsOptions;
use Shlinkio\Shlink\Core\Repository\ShortUrlRepositoryInterface;
use Shlinkio\Shlink\Core\Service\ShortUrl\DeleteShortUrlService;
use function array_map;
use function Functional\map;
use function range;
class DeleteShortUrlServiceTest extends TestCase
@ -32,9 +32,9 @@ class DeleteShortUrlServiceTest extends TestCase
public function setUp()
{
$shortUrl = (new ShortUrl(''))->setShortCode('abc123')
->setVisits(new ArrayCollection(array_map(function () {
->setVisits(new ArrayCollection(map(range(0, 10), function () {
return new Visit(new ShortUrl(''), Visitor::emptyInstance());
}, range(0, 10))));
})));
$this->em = $this->prophesize(EntityManagerInterface::class);