Passed
Push — master ( 682c69...a1e956 )
by Iman
04:15
created

Responder::stream()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\HeyMan;
4
5
use Illuminate\Auth\Access\AuthorizationException;
6
7
class Responder
8
{
9
    private $response;
10
11
    private $exception;
12
13
    /**
14
     * Create a new redirect response to the given path.
15
     *
16
     * @param string    $path
17
     * @param int       $status
18
     * @param array     $headers
19
     * @param bool|null $secure
20
     */
21 3
    public function redirectTo($path, $status = 302, $headers = [], $secure = null)
22
    {
23 3
        $this->response = [__FUNCTION__, func_get_args()];
24 3
    }
25
26
    /**
27
     * Return a new response from the application.
28
     *
29
     * @param string $content
30
     * @param int    $status
31
     * @param array  $headers
32
     */
33
    public function make($content = '', $status = 200, array $headers = [])
34
    {
35
        $this->response = [__FUNCTION__, func_get_args()];
36
    }
37
38
    /**
39
     * Return a new view response from the application.
40
     *
41
     * @param string $view
42
     * @param array  $data
43
     * @param int    $status
44
     * @param array  $headers
45
     */
46
    public function view($view, $data = [], $status = 200, array $headers = [])
47
    {
48
        $this->response = [__FUNCTION__, func_get_args()];
49
    }
50
51
    /**
52
     * Return a new JSON response from the application.
53
     *
54
     * @param string|array $data
55
     * @param int          $status
56
     * @param array        $headers
57
     * @param int          $options
58
     */
59 1
    public function json($data = [], $status = 200, array $headers = [], $options = 0)
60
    {
61 1
        $this->response = [__FUNCTION__, func_get_args()];
62 1
    }
63
64
    /**
65
     * Return a new JSONP response from the application.
66
     *
67
     * @param string       $callback
68
     * @param string|array $data
69
     * @param int          $status
70
     * @param array        $headers
71
     * @param int          $options
72
     */
73
    public function jsonp($callback, $data = [], $status = 200, array $headers = [], $options = 0)
74
    {
75
        $this->response = [__FUNCTION__, func_get_args()];
76
    }
77
78
    /**
79
     * Return a new streamed response from the application.
80
     *
81
     * @param \Closure $callback
82
     * @param int      $status
83
     * @param array    $headers
84
     */
85
    public function stream($callback, $status = 200, array $headers = [])
86
    {
87
        $this->response = [__FUNCTION__, func_get_args()];
88
    }
89
90
    /**
91
     * Return a new streamed response as a file download from the application.
92
     *
93
     * @param \Closure    $callback
94
     * @param string|null $name
95
     * @param array       $headers
96
     * @param string|null $disposition
97
     */
98
    public function streamDownload($callback, $name = null, array $headers = [], $disposition = 'attachment')
99
    {
100
        $this->response = [__FUNCTION__, func_get_args()];
101
    }
102
103
    /**
104
     * Create a new file download response.
105
     *
106
     * @param \SplFileInfo|string $file
107
     * @param string|null         $name
108
     * @param array               $headers
109
     * @param string|null         $disposition
110
     */
111
    public function download($file, $name = null, array $headers = [], $disposition = 'attachment')
112
    {
113
        $this->response = [__FUNCTION__, func_get_args()];
114
    }
115
116
    /**
117
     * Create a new redirect response to a named route.
118
     *
119
     * @param string $route
120
     * @param array  $parameters
121
     * @param int    $status
122
     * @param array  $headers
123
     */
124
    public function redirectToRoute($route, $parameters = [], $status = 302, $headers = [])
125
    {
126
        $this->response = [__FUNCTION__, func_get_args()];
127
    }
128
129
    /**
130
     * Create a new redirect response to a controller action.
131
     *
132
     * @param string $action
133
     * @param array  $parameters
134
     * @param int    $status
135
     * @param array  $headers
136
     */
137
    public function redirectToAction($action, $parameters = [], $status = 302, $headers = [])
138
    {
139
        $this->response = [__FUNCTION__, func_get_args()];
140
    }
141
142
    /**
143
     * Create a new redirect response, while putting the current URL in the session.
144
     *
145
     * @param string    $path
146
     * @param int       $status
147
     * @param array     $headers
148
     * @param bool|null $secure
149
     */
150
    public function redirectGuest($path, $status = 302, $headers = [], $secure = null)
151
    {
152
        $this->response = [__FUNCTION__, func_get_args()];
153
    }
154
155
    /**
156
     * Create a new redirect response to the previously intended location.
157
     *
158
     * @param string    $default
159
     * @param int       $status
160
     * @param array     $headers
161
     * @param bool|null $secure
162
     */
163
    public function redirectToIntended($default = '/', $status = 302, $headers = [], $secure = null)
164
    {
165
        $this->response = [__FUNCTION__, func_get_args()];
166
    }
167
168 1
    public function weThrowNew($exception, $message = '')
169
    {
170 1
        $this->exception = new $exception($message);
171 1
    }
172
173 2
    public function abort($code, $message = '', array $headers = [])
174
    {
175
        try {
176 2
            abort($code, $message, $headers);
177 2
        } catch (\Exception $e) {
178 2
            $this->exception = $e;
179
        }
180 2
    }
181
182 51
    public function weDenyAccess($msg = '')
183
    {
184 51
        $this->exception = new AuthorizationException($msg);
185 51
    }
186
187 2
    public function afterCalling($callback, array $parameters = [])
188
    {
189 2
        app()->call($callback, $parameters);
190
191 1
        return $this;
192
    }
193
194 57
    public function __destruct()
195
    {
196 57
        app(HeyMan::class)->startListening($this->response, $this->exception);
197 57
    }
198
199
    public function afterFiringEvent(...$args)
200
    {
201
        app('events')->dispatch(...$args);
0 ignored issues
show
Bug introduced by
$args is expanded, but the parameter $event of Illuminate\Events\Dispatcher::dispatch() does not expect variable arguments. ( Ignorable by Annotation )

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

201
        app('events')->dispatch(/** @scrutinizer ignore-type */ ...$args);
Loading history...
202
203
        return $this;
204
    }
205
}
206