Completed
Push — master ( 495169...b31514 )
by Changwan
10:11
created

SimpleLoader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A middleware() 0 7 2
A execute() 0 7 3
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 SimpleLoader implements LoaderInterface
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14 6
    public function middleware(string $className, ServerRequestInterface $request): MiddlewareInterface
15
    {
16 6
        if (!class_exists($className)) {
17 1
            throw new HandlerNotFoundException($className);
18
        }
19 5
        return new $className;
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 19
    public function execute(string $className, string $methodName, ServerRequestInterface $request)
26
    {
27 19
        if (!method_exists($className, $methodName) && !method_exists($className, '__callStatic')) {
28 2
            throw new HandlerNotFoundException($className, $methodName);
29
        }
30 18
        return call_user_func([$className, $methodName], $request);
31
    }
32
}
33