Passed
Push — master ( 6ce97f...1fe2f9 )
by huang
05:13
created

IndexController::welcome()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author    jan huang <[email protected]>
4
 * @copyright 2016
5
 *
6
 * @see      https://www.github.com/janhuang
7
 * @see      https://fastdlabs.com
8
 */
9
10
namespace Controller;
11
12
use FastD\Http\JsonResponse;
13
use FastD\Http\Response;
14
use FastD\Http\ServerRequest;
15
16
/**
17
 * Class IndexController.
18
 */
19
class IndexController
20
{
21
    /**
22
     * @param ServerRequest $request
23
     *
24
     * @return Response
25
     */
26
    public function welcome(ServerRequest $request)
27
    {
28
        return json([
29
                'foo' => $request->getParam('foo', 'bar'),
0 ignored issues
show
Documentation introduced by
'bar' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
30
            ])
31
            ->withCookie('uid', 100, 900)
32
            ->withFileDescriptor(1)
33
            ;
34
    }
35
36
    /**
37
     * @param ServerRequest $request
38
     *
39
     * @return JsonResponse
40
     */
41
    public function sayHello(ServerRequest $request)
42
    {
43
        return json([
44
            'foo' => $request->getAttribute('name'),
45
        ]);
46
    }
47
48
    /**
49
     * @param ServerRequest $serverRequest
50
     *
51
     * @return JsonResponse
52
     */
53
    public function middleware(ServerRequest $serverRequest)
0 ignored issues
show
Unused Code introduced by
The parameter $serverRequest is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
    {
55
        return json([
56
            'foo' => 'bar',
57
        ]);
58
    }
59
60
    /**
61
     * @return JsonResponse
62
     */
63
    public function db()
64
    {
65
        return json(
66
            database()->info()
67
        );
68
    }
69
70
    public function model()
71
    {
72
        $model = model('demo');
73
74
        return json([
75
            'model' => get_class($model),
76
            'db' => $model->getDatabase()->info(),
77
            'list' => $model->select(),
78
        ]);
79
    }
80
81
    public function auth()
82
    {
83
        return json([
84
            'foo' => 'bar',
85
        ]);
86
    }
87
88
    public function abort()
89
    {
90
        abort(400);
91
    }
92
93
    public function queue()
94
    {
95
        queue()->push('demo queue');
96
97
        return json([
98
            'msg' => 'hello queue',
99
        ]);
100
    }
101
}
102