mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Some more refactorings
This commit is contained in:
@@ -60,7 +60,6 @@ $builder->createManyToMany('tags', Entity\Tag::class)
|
||||
->setJoinTable('short_urls_in_tags')
|
||||
->addInverseJoinColumn('tag_id', 'id', true, false, 'CASCADE')
|
||||
->addJoinColumn('short_url_id', 'id', true, false, 'CASCADE')
|
||||
->cascadePersist()
|
||||
->build();
|
||||
|
||||
$builder->createManyToOne('domain', Entity\Domain::class)
|
||||
|
||||
@@ -8,6 +8,7 @@ use Doctrine\Common\Collections;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Shlinkio\Shlink\Core\Entity\Tag;
|
||||
|
||||
use function Functional\map;
|
||||
use function str_replace;
|
||||
use function strtolower;
|
||||
use function trim;
|
||||
@@ -21,18 +22,13 @@ trait TagManagerTrait
|
||||
*/
|
||||
private function tagNamesToEntities(EntityManagerInterface $em, array $tags): Collections\Collection
|
||||
{
|
||||
$entities = [];
|
||||
foreach ($tags as $tagName) {
|
||||
$entities = map($tags, function (string $tagName) use ($em): Tag {
|
||||
$tagName = $this->normalizeTagName($tagName);
|
||||
$tag = $em->getRepository(Tag::class)->findOneBy(['name' => $tagName]) ?? new Tag($tagName);
|
||||
$em->persist($tag);
|
||||
|
||||
// if (! $tag) {
|
||||
// $tag = ;
|
||||
// $em->persist($tag);
|
||||
// }
|
||||
|
||||
$entities[] = $tag;
|
||||
}
|
||||
return $tag;
|
||||
});
|
||||
|
||||
return new Collections\ArrayCollection($entities);
|
||||
}
|
||||
|
||||
@@ -50,10 +50,10 @@ class CreateShortUrlActionTest extends ApiTestCase
|
||||
/** @test */
|
||||
public function createsNewShortUrlWithTags(): void
|
||||
{
|
||||
[$statusCode, $payload] = $this->createShortUrl(['tags' => ['foo', 'bar', 'baz']]);
|
||||
[$statusCode, ['tags' => $tags]] = $this->createShortUrl(['tags' => ['foo', 'bar', 'baz']]);
|
||||
|
||||
$this->assertEquals(self::STATUS_OK, $statusCode);
|
||||
$this->assertEquals(['foo', 'bar', 'baz'], $payload['tags']);
|
||||
$this->assertEquals(['foo', 'bar', 'baz'], $tags);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user