Completed
Push — master ( 413e31...6028d7 )
by Changwan
06:35
created

DefaultLoader   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A middleware() 0 7 2
A execute() 0 7 2
1
<?php
2
namespace Wandu\Router\Loader;
3
4
use Psr\Http\Message\ServerRequestInterface;
5
use Wandu\Router\Contracts\LoaderInterface;
6
use Wandu\Router\Contracts\MiddlewareInterface;
7
use Wandu\Router\Exception\HandlerNotFoundException;
8
9
class DefaultLoader implements LoaderInterface
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14 8
    public function middleware($className): MiddlewareInterface
15
    {
16 8
        if (!class_exists($className)) {
17
            throw new HandlerNotFoundException($className);
18
        }
19 8
        return new $className;
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 23
    public function execute($className, $methodName, ServerRequestInterface $request)
26
    {
27 23
        if (!method_exists($className, $methodName)) {
28 1
            throw new HandlerNotFoundException($className, $methodName);
29
        }
30 22
        return call_user_func([$className, $methodName], $request);
31
    }
32
}
33