Passed
Pull Request — master (#18)
by Florian
02:20
created

BaseApiController::returnOrganisations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the vseth-semesterly-reports project.
5
 *
6
 * (c) Florian Moser <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace App\Controller\Base;
13
14
use App\Entity\Organisation;
15
use Symfony\Component\HttpFoundation\JsonResponse;
16
use Symfony\Component\Serializer\SerializerInterface;
17
18
class BaseApiController extends BaseDoctrineController
19
{
20
    public static function getSubscribedServices()
21
    {
22
        return parent::getSubscribedServices() +
23
            [
24
                'serializer' => SerializerInterface::class,
25
            ];
26
    }
27
28
    /**
29
     * @return SerializerInterface
30
     */
31
    private function getSerializer()
32
    {
33
        return $this->get('serializer');
34
    }
35
36
    /**
37
     * @param Organisation[] $organisations
38
     *
39
     * @return JsonResponse
40
     */
41
    protected function returnOrganisations($organisations)
42
    {
43
        return new JsonResponse(
44
            $this->getSerializer()->serialize(
45
                $organisations,
46
                'json',
47
                ['attributes' => ['name', 'email']]
48
            ),
49
            200,
50
            [],
51
            true
52
        );
53
    }
54
}
55