Completed
Pull Request — 3.x (#127)
by Joschi
02:04
created

Allows   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 23
c 3
b 0
f 1
ccs 5
cts 5
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 9 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