Passed
Push — master ( 897bc8...5aa273 )
by Derek Stephen
02:48
created

ClientController::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Controller;
4
5
use Del\Common\ContainerService;
6
use OAuth\Client;
7
use OAuth\Exception\OAuthException;
8
use OAuth\Repository\ClientRepository;
9
10
class ClientController extends ResourceServerController
11
{
12
    /** @var ClientRepository $clientRepository */
13
    private $clientRepository;
14
15
    /**
16
     * Fetch client information - admin clients only
17
     *
18
     * @OA\Get(
19
     *     path="/client/{id}",
20
     *     tags={"client"},
21
     *     @OA\Parameter(
22
     *         name="id",
23
     *         in="path",
24
     *         type="integer",
25
     *         description="the type of response",
26
     *         required=false,
27
     *         default=1
28
     *     ),
29
     *     @OA\Response(response="200", description="Sends client details"),
30
     *     security={
31
     *      {"clientCredentials": {"admin"}}
32
     *     }
33
     * )
34
     *
35
     * @throws OAuthException
36
     *
37
     * @return array|void
38
     */
39 1
    public function indexAction()
40
    {
41 1
        $this->scopeCheck(['admin']);
42 1
        $clients = $this->clientRepository->findAll();
43
44 1
        if (count($clients) == 0) {
45
            $this->sendJsonResponse(['No clients found']);
46
        }
47
48 1
        $this->sendJsonObjectResponse($clients);
49 1
    }
50
51 1
    public function init()
52
    {
53 1
        parent::init();
54 1
        $container = ContainerService::getInstance()->getContainer();
55 1
        $this->clientRepository = $container['repository.Client'];
56
    }
57
}