AdminController::serveFavicon()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 2
dl 0
loc 9
rs 10
c 0
b 0
f 0
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('/admin.js', AdminController::class . ':serveJs');
22
        $app->get('/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/admin.js.php',
35
            [
36
                'publishing' => __('publishing'),
37
                'reserved' => __('reserved'),
38
                'expired' => __('expired'),
39
                'do_publish' => __('do_publish', 'publish'),
40
                'do_reserve' => __('do_reserve', 'reserve'),
41
                'do_save_as_pending' => __('do_save_as_pending', 'save as pending'),
42
                'do_save_as_draft' => __('do_save_as_draft', 'save as draft'),
43
                'published_url' => __('published_url'),
44
                'reserved_url' => __('reserved_url'),
45
                'banned_url' => __('banned_url'),
46
                'open_in_new_window' => __('open_in_new_window'),
47
                'open_sidebar' => __('open_sidebar'),
48
                'close_sidebar' => __('close_sidebar'),
49
            ]
50
        );
51
        $response->getBody()->write($content);
52
        return $response->withHeader(
53
            'Content-Type',
54
            'application/javascript; charset=utf-8'
55
        )->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

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

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

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