Passed
Push — develop ( dde0ba...cb4af5 )
by Stone
04:20
created

TagSerializer::trickTagsJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
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
        $serializer = new Serializer([new ObjectNormalizer()]);
21
22
        return json_encode($serializer->normalize($trick->getTags(), null, ['attributes' => ['name']]));
23
    }
24
25
    public function allTagsJson()
26
    {
27
        $serializer = new Serializer([new ObjectNormalizer()]);
28
29
        return json_encode($serializer->normalize($this->tagRepository->findAll(), null, ['attributes' => ['name']]));
30
    }
31
32
    /**
33
     * @required
34
     * @param TagRepository $tagRepository
35
     */
36
    public function setTagRepository(TagRepository $tagRepository): void
37
    {
38
        $this->tagRepository = $tagRepository;
39
    }
40
41
42
}