Completed
Push — master ( 2ef37c...52cad6 )
by Oleg
02:13
created

RoutesDelegator   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 38
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 29 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DataFlowServer\Db\Factory;
5
6
use Psr\Container\ContainerInterface;
7
use SlayerBirden\DataFlowServer\Db\Controller\AddConfigAction;
8
use SlayerBirden\DataFlowServer\Db\Controller\DeleteConfigAction;
9
use SlayerBirden\DataFlowServer\Db\Controller\GetConfigAction;
10
use SlayerBirden\DataFlowServer\Db\Controller\GetConfigsAction;
11
use SlayerBirden\DataFlowServer\Db\Controller\UpdateConfigAction;
12
use Zend\Expressive\Application;
13
use Zend\Expressive\Helper\BodyParams\BodyParamsMiddleware;
14
15
class RoutesDelegator
16
{
17
    /**
18
     * @param ContainerInterface $container
19
     * @param string $serviceName
20
     * @param callable $callback
21
     * @return Application
22
     */
23 32
    public function __invoke(ContainerInterface $container, string $serviceName, callable $callback)
24
    {
25
        /** @var $app Application */
26 32
        $app = $callback();
27
28 32
        $app->get('/config/{id:\d+}', [
29 32
            GetConfigAction::class
30 32
        ], 'get_config');
31
32 32
        $app->get('/configs', [
33 32
            GetConfigsAction::class
34 32
        ], 'get_configs');
35
36 32
        $app->post('/config', [
37 32
            BodyParamsMiddleware::class,
38
            AddConfigAction::class
39 32
        ], 'add_config');
40
41 32
        $app->put('/config/{id:\d+}', [
42 32
            BodyParamsMiddleware::class,
43
            UpdateConfigAction::class
44 32
        ], 'update_config');
45
46 32
        $app->delete('/config/{id:\d+}', [
47 32
            DeleteConfigAction::class
48 32
        ], 'delete_config');
49
50 32
        return $app;
51
    }
52
}
53