Completed
Push — master ( c29e8f...68ea4d )
by Alexpts
02:33
created

CheckMethodGroup   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

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

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace PTS\Routing\Middlewares;
3
4
use Psr\Http\Message\RequestInterface;
5
use PTS\Routing\Route;
6
7
class CheckMethodGroup
8
{
9
    /**
10
     * @param RequestInterface $request
11
     * @param Route $route
12
     * @return mixed
13
     */
14
    public function __invoke(RequestInterface $request, Route $route)
15
    {
16
        $supports = $route->getGroup()->getMethods();
17
        if (count($supports) > 0 && !in_array($request->getMethod(), $supports, true)) {
18
            return null;
19
        }
20
21
        return $route($request);
22
    }
23
}
24