DefaultController::checkLoggerConnection()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Controller;
6
7
use Slim\Http\Request;
8
use Slim\Http\Response;
9
10
final class DefaultController extends BaseController
11
{
12
    public const API_VERSION = '1.9.0';
13
14 1
    public function getHelp(Request $request, Response $response): Response
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

14
    public function getHelp(/** @scrutinizer ignore-unused */ Request $request, Response $response): Response

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
15
    {
16 1
        $url = $this->container->get('settings')['app']['domain'];
17 1
        $endpoints = [
18
            'tasks' => $url . '/api/v1/tasks',
19 1
            'users' => $url . '/api/v1/users',
20 1
            'notes' => $url . '/api/v1/notes',
21 1
            'docs' => $url . '/docs/index.html',
22 1
            'status' => $url . '/status',
23 1
            'this help' => $url . '',
24 1
        ];
25
        $message = [
26
            'endpoints' => $endpoints,
27 1
            'version' => self::API_VERSION,
28 1
            'timestamp' => time(),
29 1
        ];
30
31
        return $this->jsonResponse($response, 'success', $message, 200);
32 1
    }
33
34
    public function getStatus(Request $request, Response $response): Response
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

34
    public function getStatus(/** @scrutinizer ignore-unused */ Request $request, Response $response): Response

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
35 1
    {
36
        $status = [
37
            'stats' => $this->getDbStats(),
38 1
            'MySQL' => 'OK',
39 1
            'Redis' => $this->checkRedisConnection(),
40 1
            'Logger' => $this->checkLoggerConnection(),
41 1
            'version' => self::API_VERSION,
42 1
            'timestamp' => time(),
43 1
        ];
44
45
        return $this->jsonResponse($response, 'success', $status, 200);
46 1
    }
47
48
    private function getDbStats(): array
49 1
    {
50
        $userService = $this->container->get('find_user_service');
51 1
        $taskService = $this->container->get('task_service');
52 1
        $noteService = $this->container->get('find_note_service');
53 1
54
        return [
55
            'users' => count($userService->getAll()),
56 1
            'tasks' => count($taskService->getAllTasks()),
57 1
            'notes' => count($noteService->getAll()),
58 1
        ];
59
    }
60
61
    private function checkRedisConnection(): string
62 1
    {
63
        $redis = 'Disabled';
64 1
        if (self::isRedisEnabled() === true) {
65 1
            $redisService = $this->container->get('redis_service');
66 1
            $key = $redisService->generateKey('test:status');
67 1
            $redisService->set($key, new \stdClass());
68 1
            $redis = 'OK';
69 1
        }
70
71
        return $redis;
72 1
    }
73
74
    private function checkLoggerConnection(): string
75 1
    {
76
        $logger = 'Disabled';
77 1
        if (self::isLoggerEnabled() === true) {
78 1
            $logger = 'Enabled';
79 1
        }
80
81
        return $logger;
82 1
    }
83
}
84