RoutesDelegator::__invoke()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 73

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 27
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 73
ccs 27
cts 27
cp 1
rs 8.589
c 0
b 0
f 0
cc 1
nc 1
nop 4
crap 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DataFlowServer\Authentication\Factory;
5
6
use Interop\Container\ContainerInterface;
7
use SlayerBirden\DataFlowServer\Authentication\Controller\CreatePasswordAction;
8
use SlayerBirden\DataFlowServer\Authentication\Controller\GenerateTemporaryTokenAction;
9
use SlayerBirden\DataFlowServer\Authentication\Controller\GetTokenAction;
10
use SlayerBirden\DataFlowServer\Authentication\Controller\InvalidateTokenAction;
11
use SlayerBirden\DataFlowServer\Authentication\Controller\InvalidateTokensAction;
12
use SlayerBirden\DataFlowServer\Authentication\Controller\UpdatePasswordAction;
13
use SlayerBirden\DataFlowServer\Authentication\Middleware\ActivePasswordMiddleware;
14
use SlayerBirden\DataFlowServer\Authentication\Middleware\PasswordConfirmationMiddleware;
15
use SlayerBirden\DataFlowServer\Authentication\Middleware\TokenMiddleware;
16
use SlayerBirden\DataFlowServer\Domain\Middleware\SetOwnerMiddleware;
17
use SlayerBirden\DataFlowServer\Domain\Middleware\ValidateOwnerMiddleware;
18
use Zend\Expressive\Application;
19
use Zend\Expressive\Helper\BodyParams\BodyParamsMiddleware;
20
use Zend\ServiceManager\Factory\DelegatorFactoryInterface;
21
22
final class RoutesDelegator implements DelegatorFactoryInterface
0 ignored issues
show
Complexity introduced by
The class RoutesDelegator has a coupling between objects value of 13. Consider to reduce the number of dependencies under 13.
Loading history...
23
{
24
    /**
25
     * @inheritdoc
26
     */
27 144
    public function __invoke(ContainerInterface $container, $name, callable $callback, array $options = null)
28
    {
29
        /** @var $app Application */
30 144
        $app = $callback();
31
32 144
        $app->post(
33 144
            '/gettmptoken/{id:\d+}',
34
            [
35 144
                TokenMiddleware::class,
36
                'UserResourceMiddleware',
37
                BodyParamsMiddleware::class,
38
                GenerateTemporaryTokenAction::class,
39
            ],
40 144
            'get_tmp_token'
41
        );
42
43 144
        $app->post(
44 144
            '/password',
45
            [
46 144
                TokenMiddleware::class,
47
                BodyParamsMiddleware::class,
48
                ActivePasswordMiddleware::class,
49
                SetOwnerMiddleware::class,
50
                CreatePasswordAction::class,
51
            ],
52 144
            'create_password'
53
        );
54
55 144
        $app->post(
56 144
            '/gettoken',
57
            [
58 144
                BodyParamsMiddleware::class,
59
                GetTokenAction::class,
60
            ],
61 144
            'get_token'
62
        );
63
64 144
        $app->put(
65 144
            '/invalidatetoken/{id:\d+}',
66
            [
67 144
                TokenMiddleware::class,
68
                'TokenResourceMiddleware',
69
                ValidateOwnerMiddleware::class,
70
                InvalidateTokenAction::class,
71
            ],
72 144
            'invalidate_token'
73
        );
74
75 144
        $app->post(
76 144
            '/invalidatetokens',
77
            [
78 144
                TokenMiddleware::class,
79
                BodyParamsMiddleware::class,
80
                InvalidateTokensAction::class,
81
            ],
82 144
            'invalidate_tokens'
83
        );
84
85 144
        $app->post(
86 144
            '/updatepassword',
87
            [
88 144
                TokenMiddleware::class,
89
                BodyParamsMiddleware::class,
90
                ValidateOwnerMiddleware::class,
91
                PasswordConfirmationMiddleware::class,
92
                SetOwnerMiddleware::class,
93
                UpdatePasswordAction::class,
94
            ],
95 144
            'update_password'
96
        );
97
98 144
        return $app;
99
    }
100
}
101