Passed
Push — master ( 0b75f0...6b8772 )
by Fernando
17:35
created

DefaultController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 42
c 1
b 0
f 0
dl 0
loc 73
ccs 41
cts 41
cp 1
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getHelp() 0 19 1
A getDbStats() 0 10 1
A checkRedisConnection() 0 11 2
A getStatus() 0 12 1
A checkLoggerConnection() 0 8 2
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.6.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
        $app = $this->container->get('settings')['app'];
17 1
        $url = $app['domain'];
18
        $endpoints = [
19 1
            'tasks' => $url . '/api/v1/tasks',
20 1
            'users' => $url . '/api/v1/users',
21 1
            'notes' => $url . '/api/v1/notes',
22 1
            'docs' => $url . '/docs/index.html',
23 1
            'status' => $url . '/status',
24 1
            'this help' => $url . '',
25
        ];
26
        $message = [
27 1
            'endpoints' => $endpoints,
28 1
            'version' => self::API_VERSION,
29 1
            'timestamp' => time(),
30
        ];
31
32 1
        return $this->jsonResponse($response, 'success', $message, 200);
33
    }
34
35 1
    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

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