Passed
Push — master ( 2b7ad0...4a69de )
by Derek Stephen
03:04
created

ClientController::indexAction()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 2
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
     * @throws \League\OAuth2\Server\Exception\OAuthServerException
17
     */
18 2
    public function init()
19
    {
20 2
        parent::init();
21 1
        $container = ContainerService::getInstance()->getContainer();
22 1
        $this->clientRepository = $container['repository.Client'];
23 1
    }
24
25
    /**
26
     * Fetch client information - admin clients only
27
     *
28
     * @OA\Get(
29
     *     path="/client/{id}",
30
     *     tags={"client"},
31
     *     @OA\Parameter(
32
     *         name="id",
33
     *         in="path",
34
     *         type="integer",
35
     *         description="the type of response",
36
     *         required=false,
37
     *         default=1
38
     *     ),
39
     *     @OA\Response(response="200", description="Sends client details"),
40
     *     security={
41
     *      {"clientCredentials": {"admin"}}
42
     *     }
43
     * )
44
     *
45
     * @throws OAuthException
46
     *
47
     * @return array|void
48
     */
49 1
    public function indexAction()
50
    {
51 1
        $this->scopeCheck(['admin']);
52 1
        $clients = $this->clientRepository->findAll() ?: ['No clients found'];
53 1
        $this->sendJsonObjectResponse($clients);
54
    }
55
}