Passed
Push — main ( 768fac...6b80e0 )
by Nobufumi
02:43
created

AssetTrait::serveJs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 7
c 1
b 1
f 0
nc 1
nop 2
dl 0
loc 12
rs 10
1
<?php
2
3
namespace Jidaikobo\Kontiki\Controllers\FileControllerTraits;
4
5
use Psr\Http\Message\ResponseInterface as Response;
6
use Psr\Http\Message\ServerRequestInterface as Request;
7
8
trait AssetTrait
9
{
10
    /**
11
     * Serve the requested JavaScript file.
12
     *
13
     * @return Response
14
     */
15
    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

15
    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...
16
    {
17
        $content = $this->view->fetch(
18
            'js/kontiki-file.js.php',
19
            [
20
                'basepath' => env('BASEPATH', '')
21
            ]
22
        );
23
        $response->getBody()->write($content);
24
        return $response
25
            ->withHeader('Content-Type', 'application/javascript; charset=utf-8')
26
            ->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

26
            ->/** @scrutinizer ignore-call */ withStatus(200);
Loading history...
27
    }
28
29
    /**
30
     * Serve the requested JavaScript file.
31
     *
32
     * @return Response
33
     */
34
    public function serveIndexJs(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 serveIndexJs(/** @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
    {
36
        $content = $this->view->fetch(
37
            'js/kontiki-file-index.js.php',
38
            [
39
                'get_file_list' => __('get_file_list'),
40
                'confirm_delete_message' => __('confirm_delete_message', 'The item will be permanently deleted. Are you sure you want to delete this item?'),
41
                'couldnt_find_file' => __('couldnt_find_file'),
42
                'couldnt_get_file_list' => __('couldnt_get_file_list'),
43
                'copied' => __('copied'),
44
                'copy_failed' => __('copy_failed'),
45
                'close' => __('close'),
46
                'edit' => __('edit'),
47
                'couldnt_delete_file' => __('couldnt_delete_file'),
48
                'insert_success' => __('insert_success'),
49
            ]
50
        );
51
        $response->getBody()->write($content);
52
53
        return $response
54
            ->withHeader('Content-Type', 'application/javascript; charset=utf-8')
55
            ->withStatus(200);
56
    }
57
58
    /**
59
     * Serve the requested JavaScript file.
60
     *
61
     * @return Response
62
     */
63
    public function serveCsrfJs(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

63
    public function serveCsrfJs(/** @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...
64
    {
65
        $content = $this->view->fetch('js/kontiki-file-csrf.js.php');
66
        $response->getBody()->write($content);
67
        return $response
68
            ->withHeader('Content-Type', 'application/javascript; charset=utf-8')
69
            ->withStatus(200);
70
    }
71
72
    /**
73
     * Serve the requested JavaScript file.
74
     *
75
     * @return Response
76
     */
77
    public function serveLightboxJs(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

77
    public function serveLightboxJs(/** @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...
78
    {
79
        $content = $this->view->fetch('js/kontiki-file-lightbox.js.php');
80
        $response->getBody()->write($content);
81
        return $response
82
            ->withHeader('Content-Type', 'application/javascript; charset=utf-8')
83
            ->withStatus(200);
84
    }
85
86
    /**
87
     * Serve the requested JavaScript file.
88
     *
89
     * @return Response
90
     */
91
    public function serveUtilsJs(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

91
    public function serveUtilsJs(/** @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...
92
    {
93
        $content = $this->view->fetch('js/kontiki-file-utils.js.php');
94
        $response->getBody()->write($content);
95
        return $response
96
            ->withHeader('Content-Type', 'application/javascript; charset=utf-8')
97
            ->withStatus(200);
98
    }
99
100
    /**
101
     * Serve the requested JavaScript file.
102
     *
103
     * @return Response
104
     */
105
    public function serveUploaderJs(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

105
    public function serveUploaderJs(/** @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...
106
    {
107
        $content = $this->view->fetch(
108
            'js/kontiki-file-uploader.js.php',
109
            [
110
                'uploading' => __('uploading'),
111
                'couldnt_upload' => __('couldnt_upload', "Could not upload"),
112
            ]
113
        );
114
        $response->getBody()->write($content);
115
        return $response
116
            ->withHeader('Content-Type', 'application/javascript; charset=utf-8')
117
            ->withStatus(200);
118
    }
119
120
    /**
121
     * Serve the requested Css file.
122
     *
123
     * @return Response
124
     */
125
    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

125
    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...
126
    {
127
        $content = $this->view->fetch('css/kontiki-file.css');
128
        $response->getBody()->write($content);
129
        return $response->withHeader(
130
            'Content-Type',
131
            'text/css; charset=utf-8'
132
        )->withStatus(200);
133
    }
134
}
135