Passed
Push — develop ( be6ef3...d18f97 )
by Stone
04:12
created

TagSerializer::serializeTag()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Serializer;
4
5
use App\Entity\Trick;
6
use App\Repository\TagRepository;
7
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
8
use Symfony\Component\Serializer\Serializer;
9
10
class TagSerializer
11
{
12
13
    /**
14
     * @var TagRepository $tagRepository
15
     */
16
    private $tagRepository;
17
18
    public function trickTagsJson(Trick $trick)
19
    {
20
        return $this->serializeTag($trick->getTags());
21
    }
22
23
    public function allTagsJson()
24
    {
25
        return $this->serializeTag($this->tagRepository->findAll());
26
    }
27
28
    /**
29
     * @required
30
     * @param TagRepository $tagRepository
31
     */
32
    public function setTagRepository(TagRepository $tagRepository): void
33
    {
34
        $this->tagRepository = $tagRepository;
35
    }
36
37
    private function serializeTag($tags){
38
        $serializer = new Serializer([new ObjectNormalizer()]);
39
        return json_encode($serializer->normalize($tags, null, ['attributes' => ['name']]));
40
    }
41
42
}