Completed
Push — request ( a963ff )
by Hari
04:26
created

Allows::__invoke()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
cc 3
eloc 5
nc 3
nop 2
crap 3
1
<?php
2
/**
3
 *
4
 * This file is part of Aura for PHP.
5
 *
6
 * @license http://opensource.org/licenses/bsd-license.php BSD
7
 *
8
 */
9
namespace Aura\Router\Rule;
10
11
use Aura\Router\Route;
12
use Psr\Http\Message\ServerRequestInterface;
13
14
/**
15
 *
16
 * A rule for HTTP methods.
17
 *
18
 * @package Aura.Router
19
 *
20
 */
21
class Allows implements RuleInterface
22
{
23
    /**
24
     *
25
     * Does the server request method match an allowed route method?
26
     *
27
     * @param ServerRequestInterface $request The HTTP request.
28
     *
29
     * @param Route $route The route.
30
     *
31
     * @return bool True on success, false on failure.
32
     *
33
     */
34 6
    public function __invoke(ServerRequestInterface $request, Route $route)
35
    {
36 6
        if (! $route->allows) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $route->allows of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
37 2
            return true;
38
        }
39
40 4
        $requestMethod = $request->getMethod() ?: 'GET';
41 4
        return in_array($requestMethod, $route->allows);
42
    }
43
}
44