Completed
Push — master ( 3eb757...3bc7c8 )
by Oleg
03:46
created

GetResourcesAction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DataFlowServer\Authorization\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\Authorization\Service\ResourceManager;
11
use SlayerBirden\DataFlowServer\Stdlib\Validation\GeneralSuccessResponseFactory;
12
13
final class GetResourcesAction implements MiddlewareInterface
14
{
15
    /**
16
     * @var ResourceManager
17
     */
18
    private $resourceManager;
19
20 2
    public function __construct(ResourceManager $resourceManager)
21
    {
22 2
        $this->resourceManager = $resourceManager;
23 2
    }
24
25
    /**
26
     * @inheritdoc
27
     */
28 2
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
29
    {
30 2
        $resources = $this->resourceManager->getAllResources();
31 2
        $count = count($resources);
32 2
        return (new GeneralSuccessResponseFactory())('Success', 'resources', $resources, 200, $count);
33
    }
34
}
35