AdminController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 45
c 1
b 0
f 0
dl 0
loc 86
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A registerRoutes() 0 5 1
A serveFavicon() 0 9 1
A serveJs() 0 28 1
A serveCss() 0 14 1
1
<?php
2
3
namespace Jidaikobo\Kontiki\Controllers;
4
5
use Slim\App;
6
use Psr\Http\Message\ResponseInterface as Response;
7
use Psr\Http\Message\ServerRequestInterface as Request;
8
use Slim\Views\PhpRenderer;
9
10
class AdminController
11
{
12
    private PhpRenderer $view;
13
14
    public function __construct(PhpRenderer $view)
15
    {
16
        $this->view = $view;
17
    }
18
19
    public static function registerRoutes(App $app): void
20
    {
21
        $app->get('/kontiki-admin.js', AdminController::class . ':serveJs');
22
        $app->get('/kontiki-admin.css', AdminController::class . ':serveCss');
23
        $app->get('/favicon.ico', AdminController::class . ':serveFavicon');
24
    }
25
26
    /**
27
     * Serve the requested JavaScript file.
28
     *
29
     * @return Response
30
     */
31
    public function serveJs(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

31
    public function serveJs(/** @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...
32
    {
33
        $content = $this->view->fetch(
34
            'js/kontiki-admin.js.php',
35
            [
36
                'skip_to_main_content' => __('skip_to_main_content'),
37
                'skip_to_navigation' => __('skip_to_navigation'),
38
                'publishing' => __('publishing'),
39
                'reserved' => __('reserved'),
40
                'expired' => __('expired'),
41
                'do_publish' => __('do_publish', 'publish'),
42
                'do_reserve' => __('do_reserve', 'reserve'),
43
                'do_save_as_pending' => __('do_save_as_pending', 'save as pending'),
44
                'do_save_as_draft' => __('do_save_as_draft', 'save as draft'),
45
                'published_at' => __('published_at'),
46
                'published_url' => __('published_url'),
47
                'reserved_url' => __('reserved_url'),
48
                'banned_url' => __('banned_url'),
49
                'open_in_new_window' => __('open_in_new_window'),
50
                'open_sidebar' => __('open_sidebar'),
51
                'close_sidebar' => __('close_sidebar'),
52
            ]
53
        );
54
        $response->getBody()->write($content);
55
        return $response->withHeader(
56
            'Content-Type',
57
            'application/javascript; charset=utf-8'
58
        )->withStatus(200);
0 ignored issues
show
Bug introduced by
The method withStatus() does not exist on Psr\Http\Message\MessageInterface. It seems like you code against a sub-type of Psr\Http\Message\MessageInterface such as Psr\Http\Message\ResponseInterface or Slim\Psr7\Response. ( Ignorable by Annotation )

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

58
        )->/** @scrutinizer ignore-call */ withStatus(200);
Loading history...
59
    }
60
61
    /**
62
     * Serve the requested CSS file.
63
     *
64
     * @return Response
65
     */
66
    public function serveCss(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

66
    public function serveCss(/** @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...
67
    {
68
        $content = $this->view->fetch(
69
            'css/kontiki-admin.css.php',
70
            [
71
                'color' => env('ADMIN_THEME_COLOR', '#ffffff'),
72
                'bgcolor' => env('ADMIN_THEME_BGCOLOR', '#343a40')
73
            ]
74
        );
75
        $response->getBody()->write($content);
76
        return $response->withHeader(
77
            'Content-Type',
78
            'text/css; charset=utf-8'
79
        )->withStatus(200);
80
    }
81
82
    /**
83
     * Serve the requested favicon file.
84
     *
85
     * @return Response
86
     */
87
    public function serveFavicon(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

87
    public function serveFavicon(/** @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...
88
    {
89
        $faviconPath = env('PROJECT_PATH', '') . '/src/views/images/favicon.ico';
90
        $content = file_get_contents($faviconPath);
91
        $response->getBody()->write($content);
92
        return $response
93
            ->withHeader('Content-Type', 'image/x-icon')
94
            ->withHeader('Cache-Control', 'public, max-age=86400')
95
            ->withStatus(200);
96
    }
97
}
98