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

SimpleLoader::middleware()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
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