DynamicPoint   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 28
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getControllerClass() 0 11 2
A normalizeClassFromUrl() 0 6 1
A getAction() 0 4 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