Passed
Push — master ( c1d5ad...2deeb6 )
by Justin
03:10
created

Response::error429()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Fermi;
4
5
use Psr\Http\Message\RequestInterface;
6
use Zend\Diactoros\Response\HtmlResponse;
7
use Zend\Diactoros\Response\JsonResponse;
8
use Zend\Diactoros\Response\TextResponse;
9
10
class Response
11
{
12
    /**
13
     * Returns a response with a particular view loaded.
14
     *
15
     * @param  string $view name of the view to load
16
     * @param  array  $data data to expose to the view
17
     * @return \Psr\Http\Message\ResponseInterface
18
     */
19
    public static function view($view, $data)
20
    {
21
        return new HtmlResponse(Framework::render($view, $data));
22
    }
23
24
    /**
25
     * Returns a response with a particular view loaded.
26
     *
27
     * @param  string $view name of the view to load
0 ignored issues
show
Bug introduced by
There is no parameter named $view. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
28
     * @param  array  $data data to expose to the view
29
     * @return \Psr\Http\Message\ResponseInterface
30
     */
31 3
    public static function json($data, $flags = 79)
32
    {
33 3
        return new JsonResponse($data, 200, [], $flags);
34
    }
35
36
    /**
37
     * Create a new basic string response.
38
     *
39
     * @param  string $name name of the view to load
0 ignored issues
show
Bug introduced by
There is no parameter named $name. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
40
     * @return \Psr\Http\Message\ResponseInterface
41
     */
42 4
    public static function string($string)
43
    {
44 4
        return new TextResponse($string);
45
    }
46
47
    /**
48
     * Respond with a 400 bad request error json message.
49
     *
50
     * @return \Psr\Http\Message\ResponseInterface
51
     */
52 1
    public static function error400(RequestInterface $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request 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...
53
    {
54 1
        return static::json(["message" => "Bad Request"])->withStatus(400);
55
    }
56
57
    /**
58
     * Respond with a 403 error message.
59
     *
60
     * @return \Psr\Http\Message\ResponseInterface
61
     */
62 1
    public static function error403(RequestInterface $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request 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...
63
    {
64 1
        return static::string("Not Authorized")->withStatus(403);
65
    }
66
67
    /**
68
     * Respond with a 404 error message.
69
     *
70
     * @return \Psr\Http\Message\ResponseInterface
71
     */
72 1
    public static function error404(RequestInterface $request)
73
    {
74 1
        return static::string($request->getUri() . " was not found.")->withStatus(404);
75
    }
76
77
    /**
78
     * Respond with a 405 error message.
79
     *
80
     * @return \Psr\Http\Message\ResponseInterface
81
     */
82 1
    public static function error405(RequestInterface $request)
83
    {
84 1
        return static::string("Method " . $request->getMethod() . " not allowed")->withStatus(405);
85
    }
86
87
    /**
88
     * Respond with a 429 error message.
89
     *
90
     * @return \Psr\Http\Message\ResponseInterface
91
     */
92 1
    public static function error429(RequestInterface $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request 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...
93
    {
94 1
        return static::json(["message" => "Too Many Requests"])->withStatus(429);
95
    }
96
}
97