Passed
Push — master ( afe3e5...ae5e1d )
by mcfog
01:36
created

AbstractConditionMiddleware   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A main() 0 10 2
shouldRun() 0 1 ?
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nimo\Middlewares;
6
7
use Interop\Http\Server\RequestHandlerInterface;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
11
/**
12
 * User: mcfog
13
 * Date: 15/9/4
14
 */
15
abstract class AbstractConditionMiddleware extends AbstractWrapperMiddleware
16
{
17 2
    protected function main(): ResponseInterface
18
    {
19 2
        if ($this->invokeCallback([$this, 'shouldRun'])) {
20 1
            $response = $this->innerMiddleware->process($this->request, $this->handler);
21
        } else {
22 1
            $response = $this->delegate();
23
        }
24
25 2
        return $response;
26
    }
27
28
    abstract public function shouldRun(ServerRequestInterface $request, RequestHandlerInterface $handler): bool;
29
}
30