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

DefaultLoader::execute()   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 3
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 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