Passed
Push — master ( d5e16d...c62e96 )
by Alexpts
02:25
created

DynamicPoint::getAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace PTS\EndPoint;
5
6
use Psr\Http\Message\ServerRequestInterface;
7
8
class DynamicPoint extends EndPoint
9
{
10
    protected $prefix = '';
11
12 3
    protected function getControllerClass(ServerRequestInterface $request): string
13
    {
14 3
        $route = $this->getRoute($request);
15 3
        $matches = $route->getMatchesParams();
16
17 3
        if (!array_key_exists('_controller', $matches)) {
18 1
            throw new \BadMethodCallException('Not found controller name for dynamic controller point');
19
        }
20
21 2
        return $this->prefix . $this->normalizeClassFromUrl($matches['_controller']);
22
    }
23
24 3
    protected function normalizeClassFromUrl(string $class): string
25
    {
26
        return array_reduce(explode('-', $class), function ($prev, $item) {
27 3
            return $prev . ucfirst($item);
28 3
        });
29
    }
30
31 4
    protected function getAction(ServerRequestInterface $request): ?string
32
    {
33 4
        return parent::getAction($request) ?? strtolower($request->getMethod());
34
    }
35
}
36