Completed
Push — master ( 298ac7...0024da )
by Oleg
12:58
created

GetConfigAction   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 71.43%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A process() 0 22 2
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DataFlowServer\Db\Controller;
5
6
use Psr\Http\Message\ResponseInterface;
7
use Psr\Http\Message\ServerRequestInterface;
8
use Psr\Http\Server\MiddlewareInterface;
9
use Psr\Http\Server\RequestHandlerInterface;
10
use SlayerBirden\DataFlowServer\Doctrine\Middleware\ResourceMiddlewareInterface;
11
use SlayerBirden\DataFlowServer\Notification\DangerMessage;
12
use Zend\Diactoros\Response\JsonResponse;
13
use Zend\Hydrator\ExtractionInterface;
14
15
class GetConfigAction implements MiddlewareInterface
16
{
17
    /**
18
     * @var ExtractionInterface
19
     */
20
    private $extraction;
21
22 1
    public function __construct(
23
        ExtractionInterface $extraction
24
    ) {
25 1
        $this->extraction = $extraction;
26 1
    }
27
28
    /**
29
     * @inheritdoc
30
     */
31 1
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
32
    {
33 1
        $dbConfig = $request->getAttribute(ResourceMiddlewareInterface::DATA_RESOURCE);
34
35 1
        if (!$dbConfig) {
36
            return new JsonResponse([
37
                'data' => [
38
                    'configuration' => null,
39
                ],
40
                'success' => false,
41
                'msg' => new DangerMessage('Could not load DB Configuration.'),
42
            ], 400);
43
        }
44
45 1
        return new JsonResponse([
46 1
            'data' => [
47 1
                'configuration' => $this->extraction->extract($dbConfig),
48
            ],
49
            'success' => true,
50
            'msg' => null,
51 1
        ], 200);
52
    }
53
}
54