RouteProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 232
Duplicated Lines 33.19 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 9
dl 77
loc 232
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 5 1
B registerRoutes() 77 196 1
A registerControllers() 0 26 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace XHGui\ServiceProvider;
4
5
use Exception;
6
use Pimple\Container;
7
use Pimple\ServiceProviderInterface;
8
use Slim\Slim as App;
9
use Slim\Views\Twig;
10
use XHGui\Controller;
11
use XHGui\Twig\TwigExtension;
12
13
class RouteProvider implements ServiceProviderInterface
14
{
15
    public function register(Container $di): void
16
    {
17
        $this->registerRoutes($di, $di['app']);
18
        $this->registerControllers($di);
19
    }
20
21
    private function registerRoutes(Container $di, App $app): void
22
    {
23
        $app->error(static function (Exception $e) use ($di, $app): void {
24
            /** @var Twig $view */
25
            $view = $di['view'];
26
            $view->parserOptions['cache'] = false;
27
            $view->parserExtensions = [
0 ignored issues
show
Documentation Bug introduced by
It seems like array(new \XHGui\Twig\TwigExtension($app)) of type array<integer,object<XHG...Twig\\TwigExtension>"}> is incompatible with the declared type object<Slim\Views\TwigExtension> of property $parserExtensions.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
28
                new TwigExtension($app),
29
            ];
30
31
            $app->view($view);
32
            $app->render('error/view.twig', [
33
                'message' => $e->getMessage(),
34
                'stack_trace' => $e->getTraceAsString(),
35
            ]);
36
        });
37
38
        // Profile Runs routes
39 View Code Duplication
        $app->get('/', static function () use ($di, $app): void {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
            /** @var Controller\RunController $controller */
41
            $controller = $di[Controller\RunController::class];
42
            $request = $app->request();
43
            $response = $app->response();
44
45
            $controller->index($request, $response);
46
        })->setName('home');
47
48 View Code Duplication
        $app->get('/run/view', static function () use ($di, $app): void {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
            /** @var Controller\RunController $controller */
50
            $controller = $di[Controller\RunController::class];
51
            $request = $app->request();
52
            $response = $app->response();
53
54
            $controller->view($request, $response);
55
        })->setName('run.view');
56
57
        $app->get('/run/delete', static function () use ($di, $app): void {
58
            /** @var Controller\RunController $controller */
59
            $controller = $di[Controller\RunController::class];
60
            $request = $app->request();
61
62
            $controller->deleteForm($request);
63
        })->setName('run.delete.form');
64
65
        $app->post('/run/delete', static function () use ($di, $app): void {
66
            /** @var Controller\RunController $controller */
67
            $controller = $di[Controller\RunController::class];
68
            $request = $app->request();
69
70
            $controller->deleteSubmit($request);
71
        })->setName('run.delete.submit');
72
73
        $app->get('/run/delete_all', static function () use ($di): void {
74
            /** @var Controller\RunController $controller */
75
            $controller = $di[Controller\RunController::class];
76
            $controller->deleteAllForm();
77
        })->setName('run.deleteAll.form');
78
79
        $app->post('/run/delete_all', static function () use ($di): void {
80
            /** @var Controller\RunController $controller */
81
            $controller = $di[Controller\RunController::class];
82
            $controller->deleteAllSubmit();
83
        })->setName('run.deleteAll.submit');
84
85 View Code Duplication
        $app->get('/url/view', static function () use ($di, $app): void {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
86
            /** @var Controller\RunController $controller */
87
            $controller = $di[Controller\RunController::class];
88
            $request = $app->request();
89
90
            $controller->url($request);
91
        })->setName('url.view');
92
93
        $app->get('/run/compare', static function () use ($di, $app): void {
94
            /** @var Controller\RunController $controller */
95
            $controller = $di[Controller\RunController::class];
96
            $request = $app->request();
97
98
            $controller->compare($request);
99
        })->setName('run.compare');
100
101
        $app->get('/run/symbol', static function () use ($di, $app): void {
102
            /** @var Controller\RunController $controller */
103
            $controller = $di[Controller\RunController::class];
104
            $request = $app->request();
105
106
            $controller->symbol($request);
107
        })->setName('run.symbol');
108
109
        $app->get('/run/symbol/short', static function () use ($di, $app): void {
110
            /** @var Controller\RunController $controller */
111
            $controller = $di[Controller\RunController::class];
112
            $request = $app->request();
113
114
            $controller->symbolShort($request);
115
        })->setName('run.symbol-short');
116
117
        $app->get('/run/callgraph', static function () use ($di, $app): void {
118
            /** @var Controller\RunController $controller */
119
            $controller = $di[Controller\RunController::class];
120
            $request = $app->request();
121
122
            $controller->callgraph($request);
123
        })->setName('run.callgraph');
124
125 View Code Duplication
        $app->get('/run/callgraph/data', static function () use ($di, $app): void {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
126
            /** @var Controller\RunController $controller */
127
            $controller = $di[Controller\RunController::class];
128
            $request = $app->request();
129
            $response = $app->response();
130
131
            $controller->callgraphData($request, $response);
132
        })->setName('run.callgraph.data');
133
134 View Code Duplication
        $app->get('/run/callgraph/dot', static function () use ($di, $app): void {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
135
            /** @var Controller\RunController $controller */
136
            $controller = $di[Controller\RunController::class];
137
            $request = $app->request();
138
            $response = $app->response();
139
140
            $controller->callgraphDataDot($request, $response);
141
        })->setName('run.callgraph.dot');
142
143
        // Import route
144 View Code Duplication
        $app->post('/run/import', static function () use ($di, $app): void {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
145
            /** @var Controller\ImportController $controller */
146
            $controller = $di[Controller\ImportController::class];
147
            $request = $app->request();
148
            $response = $app->response();
149
150
            $controller->import($request, $response);
151
        })->setName('run.import');
152
153
        // Watch function routes.
154
        $app->get('/watch', static function () use ($di): void {
155
            /** @var Controller\WatchController $controller */
156
            $controller = $di[Controller\WatchController::class];
157
            $controller->get();
158
        })->setName('watch.list');
159
160 View Code Duplication
        $app->post('/watch', static function () use ($di, $app): void {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
161
            /** @var Controller\WatchController $controller */
162
            $controller = $di[Controller\WatchController::class];
163
            $request = $app->request();
164
165
            $controller->post($request);
166
        })->setName('watch.save');
167
168
        // Custom report routes.
169
        $app->get('/custom', static function () use ($di): void {
170
            /** @var Controller\CustomController $controller */
171
            $controller = $di[Controller\CustomController::class];
172
            $controller->get();
173
        })->setName('custom.view');
174
175 View Code Duplication
        $app->get('/custom/help', static function () use ($di, $app): void {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
176
            /** @var Controller\CustomController $controller */
177
            $controller = $di[Controller\CustomController::class];
178
            $request = $app->request();
179
180
            $controller->help($request);
181
        })->setName('custom.help');
182
183 View Code Duplication
        $app->post('/custom/query', static function () use ($di, $app): void {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
184
            /** @var Controller\CustomController $controller */
185
            $controller = $di[Controller\CustomController::class];
186
            $request = $app->request();
187
            $response = $app->response();
188
189
            $controller->query($request, $response);
190
        })->setName('custom.query');
191
192
        // Waterfall routes
193
        $app->get('/waterfall', static function () use ($di): void {
194
            /** @var Controller\WaterfallController $controller */
195
            $controller = $di[Controller\WaterfallController::class];
196
            $controller->index();
197
        })->setName('waterfall.list');
198
199 View Code Duplication
        $app->get('/waterfall/data', static function () use ($di, $app): void {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
200
            /** @var Controller\WaterfallController $controller */
201
            $controller = $di[Controller\WaterfallController::class];
202
            $request = $app->request();
203
            $response = $app->response();
204
205
            $controller->query($request, $response);
206
        })->setName('waterfall.data');
207
208
        // Metrics
209
        $app->get('/metrics', static function () use ($di, $app): void {
210
            /** @var Controller\MetricsController $controller */
211
            $controller = $di[Controller\MetricsController::class];
212
            $response = $app->response();
213
214
            $controller->metrics($response);
215
        })->setName('metrics');
216
    }
217
218
    private function registerControllers(Container $app): void
219
    {
220
        $app[Controller\WatchController::class] = $app->factory(static function ($app) {
221
            return new Controller\WatchController($app['app'], $app['searcher']);
222
        });
223
224
        $app[Controller\RunController::class] = $app->factory(static function ($app) {
225
            return new Controller\RunController($app['app'], $app['searcher']);
226
        });
227
228
        $app[Controller\CustomController::class] = $app->factory(static function ($app) {
229
            return new Controller\CustomController($app['app'], $app['searcher']);
230
        });
231
232
        $app[Controller\WaterfallController::class] = $app->factory(static function ($app) {
233
            return new Controller\WaterfallController($app['app'], $app['searcher']);
234
        });
235
236
        $app[Controller\ImportController::class] = $app->factory(static function ($app) {
237
            return new Controller\ImportController($app['app'], $app['saver'], $app['config']['upload.token']);
238
        });
239
240
        $app[Controller\MetricsController::class] = $app->factory(static function ($app) {
241
            return new Controller\MetricsController($app['app'], $app['searcher']);
242
        });
243
    }
244
}
245