RoutesDelegator::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 12
cts 12
cp 1
rs 9.456
c 0
b 0
f 0
cc 1
nc 1
nop 4
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DataFlowServer\Authorization\Factory;
5
6
use Interop\Container\ContainerInterface;
7
use SlayerBirden\DataFlowServer\Authentication\Middleware\TokenMiddleware;
8
use SlayerBirden\DataFlowServer\Authorization\Controller\GetPermissionHistoryAction;
9
use SlayerBirden\DataFlowServer\Authorization\Controller\GetResourcesAction;
10
use SlayerBirden\DataFlowServer\Authorization\Controller\SavePermissionsAction;
11
use SlayerBirden\DataFlowServer\Domain\Middleware\SetOwnerMiddleware;
12
use Zend\Expressive\Application;
13
use Zend\Expressive\Helper\BodyParams\BodyParamsMiddleware;
14
use Zend\ServiceManager\Factory\DelegatorFactoryInterface;
15
16
final class RoutesDelegator implements DelegatorFactoryInterface
17
{
18
    /**
19
     * @inheritdoc
20
     */
21 144
    public function __invoke(
22
        ContainerInterface $container,
23
        $name,
24
        callable $callback,
25
        array $options = null
26
    ): Application {
27
        /** @var $app Application */
28 144
        $app = $callback();
29
30 144
        $app->get('/resources', [
31 144
            TokenMiddleware::class,
32
            GetResourcesAction::class
33 144
        ], 'get_resources');
34
35 144
        $app->put('/permissions/{id:\d+}', [
36 144
            TokenMiddleware::class,
37
            'UserResourceMiddleware',
38
            BodyParamsMiddleware::class,
39
            SetOwnerMiddleware::class,
40
            SavePermissionsAction::class
41 144
        ], 'save_permissions');
42
43 144
        $app->get('/history', [
44 144
            TokenMiddleware::class,
45
            GetPermissionHistoryAction::class
46 144
        ], 'get_permission_history');
47
48 144
        return $app;
49
    }
50
}
51