Completed
Push — master ( e903e9...7757ee )
by Michael
01:54
created

getDisplayControllerCreateService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 9
loc 9
ccs 0
cts 5
cp 0
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * Joomla! Statistics Server
4
 *
5
 * @copyright  Copyright (C) 2013 - 2017 Open Source Matters, Inc. All rights reserved.
6
 * @license    http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License Version 2 or Later
7
 */
8
9
namespace Joomla\StatsServer\Providers;
10
11
use Joomla\Application as JoomlaApplication;
12
use Joomla\Database\DatabaseDriver;
13
use Joomla\DI\{
14
	Container, ServiceProviderInterface
15
};
16
use Joomla\Input\{
17
	Cli, Input
18
};
19
use Joomla\StatsServer\{
20
	CliApplication, Console, Router, WebApplication
21
};
22
use Joomla\StatsServer\Commands as AppCommands;
23
use Joomla\StatsServer\Controllers\{
24
	DisplayControllerCreate, DisplayControllerGet, SubmitControllerCreate, SubmitControllerGet
25
};
26
use Joomla\StatsServer\Database\Migrations;
27
use Joomla\StatsServer\GitHub\GitHub;
28
use Joomla\StatsServer\Models\StatsModel;
29
use Joomla\StatsServer\Views\Stats\StatsJsonView;
30
use Psr\Cache\CacheItemPoolInterface;
31
use Psr\Log\LoggerInterface;
32
use TheIconic\Tracking\GoogleAnalytics\Analytics;
33
34
/**
35
 * Application service provider
36
 */
37
class ApplicationServiceProvider implements ServiceProviderInterface
38
{
39
	/**
40
	 * Registers the service provider with a DI container.
41
	 *
42
	 * @param   Container  $container  The DI container.
43
	 *
44
	 * @return  void
45
	 */
46 1
	public function register(Container $container)
47
	{
48
		/*
49
		 * Application Classes
50
		 */
51
52 1
		$container->alias(CliApplication::class, JoomlaApplication\AbstractCliApplication::class)
53 1
			->share(JoomlaApplication\AbstractCliApplication::class, [$this, 'getCliApplicationService'], true);
54
55 1
		$container->alias(WebApplication::class, JoomlaApplication\AbstractWebApplication::class)
56 1
			->share(JoomlaApplication\AbstractWebApplication::class, [$this, 'getWebApplicationService'], true);
57
58
		/*
59
		 * Application Class Dependencies
60
		 */
61
62 1
		$container->share(Analytics::class, [$this, 'getAnalyticsService'], true);
63 1
		$container->share(Cli::class, [$this, 'getInputCliService'], true);
64 1
		$container->share(Console::class, [$this, 'getConsoleService'], true);
65 1
		$container->share(Input::class, [$this, 'getInputService'], true);
66 1
		$container->share(JoomlaApplication\Cli\Output\Processor\ColorProcessor::class, [$this, 'getColorProcessorService'], true);
67 1
		$container->share(JoomlaApplication\Cli\CliInput::class, [$this, 'getCliInputService'], true);
68 1
		$container->share(Router::class, [$this, 'getRouterService'], true);
69
70 1
		$container->alias(JoomlaApplication\Cli\CliOutput::class, JoomlaApplication\Cli\Output\Stdout::class)
71 1
			->share(JoomlaApplication\Cli\Output\Stdout::class, [$this, 'getCliOutputService'], true);
72
73
		/*
74
		 * Console Commands
75
		 */
76
77 1
		$container->share(AppCommands\Cache\ClearCommand::class, [$this, 'getCacheClearCommandService'], true);
78 1
		$container->share(AppCommands\HelpCommand::class, [$this, 'getHelpCommandService'], true);
79 1
		$container->share(AppCommands\InstallCommand::class, [$this, 'getInstallCommandService'], true);
80 1
		$container->share(AppCommands\Database\MigrateCommand::class, [$this, 'getDatabaseMigrateCommandService'], true);
81 1
		$container->share(AppCommands\Database\StatusCommand::class, [$this, 'getDatabaseStatusCommandService'], true);
82 1
		$container->share(AppCommands\SnapshotCommand::class, [$this, 'getSnapshotCommandService'], true);
83 1
		$container->share(AppCommands\Tags\JoomlaCommand::class, [$this, 'getTagsJoomlaCommandService'], true);
84 1
		$container->share(AppCommands\Tags\PhpCommand::class, [$this, 'getTagsPhpCommandService'], true);
85 1
		$container->share(AppCommands\UpdateCommand::class, [$this, 'getUpdateCommandService'], true);
86
87
		/*
88
		 * MVC Layer
89
		 */
90
91
		// Controllers
92 1
		$container->share(DisplayControllerCreate::class, [$this, 'getDisplayControllerCreateService'], true);
93 1
		$container->share(DisplayControllerGet::class, [$this, 'getDisplayControllerGetService'], true);
94 1
		$container->share(SubmitControllerCreate::class, [$this, 'getSubmitControllerCreateService'], true);
95 1
		$container->share(SubmitControllerGet::class, [$this, 'getSubmitControllerGetService'], true);
96
97
		// Models
98 1
		$container->share(StatsModel::class, [$this, 'getStatsModelService'], true);
99
100
		// Views
101 1
		$container->share(StatsJsonView::class, [$this, 'getStatsJsonViewService'], true);
102 1
	}
103
104
	/**
105
	 * Get the Analytics class service
106
	 *
107
	 * @param   Container  $container  The DI container.
108
	 *
109
	 * @return  Analytics
110
	 */
111 1
	public function getAnalyticsService(Container $container)
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
112
	{
113 1
		return new Analytics(true);
114
	}
115
116
	/**
117
	 * Get the Cache\ClearCommand class service
118
	 *
119
	 * @param   Container  $container  The DI container.
120
	 *
121
	 * @return  AppCommands\Cache\ClearCommand
122
	 */
123 1 View Code Duplication
	public function getCacheClearCommandService(Container $container) : AppCommands\Cache\ClearCommand
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
124
	{
125 1
		$command = new AppCommands\Cache\ClearCommand($container->get(CacheItemPoolInterface::class));
126
127 1
		$command->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
128 1
		$command->setInput($container->get(Input::class));
129
130 1
		return $command;
131
	}
132
133
	/**
134
	 * Get the CLI application service
135
	 *
136
	 * @param   Container  $container  The DI container.
137
	 *
138
	 * @return  CliApplication
139
	 */
140 1
	public function getCliApplicationService(Container $container) : CliApplication
141
	{
142 1
		$application = new CliApplication(
143 1
			$container->get(Cli::class),
144 1
			$container->get('config'),
145 1
			$container->get(JoomlaApplication\Cli\CliOutput::class),
146 1
			$container->get(JoomlaApplication\Cli\CliInput::class),
147 1
			$container->get(Console::class)
148
		);
149
150
		// Inject extra services
151 1
		$application->setLogger($container->get('monolog.logger.cli'));
152
153 1
		return $application;
154
	}
155
156
	/**
157
	 * Get the CliInput class service
158
	 *
159
	 * @param   Container  $container  The DI container.
160
	 *
161
	 * @return  JoomlaApplication\Cli\CliInput
162
	 */
163 1
	public function getCliInputService(Container $container) : JoomlaApplication\Cli\CliInput
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
164
	{
165 1
		return new JoomlaApplication\Cli\CliInput;
166
	}
167
168
	/**
169
	 * Get the CliOutput class service
170
	 *
171
	 * @param   Container  $container  The DI container.
172
	 *
173
	 * @return  JoomlaApplication\Cli\CliOutput
174
	 */
175 1
	public function getCliOutputService(Container $container) : JoomlaApplication\Cli\Output\Stdout
176
	{
177 1
		return new JoomlaApplication\Cli\Output\Stdout($container->get(JoomlaApplication\Cli\Output\Processor\ColorProcessor::class));
178
	}
179
180
	/**
181
	 * Get the ColorProcessor class service
182
	 *
183
	 * @param   Container  $container  The DI container.
184
	 *
185
	 * @return  JoomlaApplication\Cli\Output\Processor\ColorProcessor
186
	 */
187 1
	public function getColorProcessorService(Container $container) : JoomlaApplication\Cli\Output\Processor\ColorProcessor
188
	{
189 1
		$processor = new JoomlaApplication\Cli\Output\Processor\ColorProcessor;
190
191
		/** @var Input $input */
192 1
		$input = $container->get(Cli::class);
193
194 1
		if ($input->getBool('nocolors', false))
195
		{
196
			$processor->noColors = true;
197
		}
198
199
		// Setup app colors (also required in "nocolors" mode - to strip them).
200 1
		$processor->addStyle('title', new JoomlaApplication\Cli\ColorStyle('yellow', '', ['bold']));
201
202 1
		return $processor;
203
	}
204
205
	/**
206
	 * Get the console service
207
	 *
208
	 * @param   Container  $container  The DI container.
209
	 *
210
	 * @return  Console
211
	 */
212 1
	public function getConsoleService(Container $container) : Console
213
	{
214 1
		$console = new Console;
215 1
		$console->setContainer($container);
216
217 1
		return $console;
218
	}
219
220
	/**
221
	 * Get the Database\MigrateCommand class service
222
	 *
223
	 * @param   Container  $container  The DI container.
224
	 *
225
	 * @return  AppCommands\Database\MigrateCommand
226
	 */
227 1
	public function getDatabaseMigrateCommandService(Container $container) : AppCommands\Database\MigrateCommand
228
	{
229 1
		$command = new AppCommands\Database\MigrateCommand($container->get(Migrations::class));
230
231 1
		$command->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
232 1
		$command->setInput($container->get(Input::class));
233 1
		$command->setLogger($container->get(LoggerInterface::class));
234
235 1
		return $command;
236
	}
237
238
	/**
239
	 * Get the Database\StatusCommand class service
240
	 *
241
	 * @param   Container  $container  The DI container.
242
	 *
243
	 * @return  AppCommands\Database\StatusCommand
244
	 */
245 1 View Code Duplication
	public function getDatabaseStatusCommandService(Container $container) : AppCommands\Database\StatusCommand
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
246
	{
247 1
		$command = new AppCommands\Database\StatusCommand($container->get(Migrations::class));
248
249 1
		$command->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
250 1
		$command->setInput($container->get(Input::class));
251
252 1
		return $command;
253
	}
254
255
	/**
256
	 * Get the DisplayControllerCreate class service
257
	 *
258
	 * @param   Container  $container  The DI container.
259
	 *
260
	 * @return  DisplayControllerCreate
261
	 */
262 View Code Duplication
	public function getDisplayControllerCreateService(Container $container) : DisplayControllerCreate
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
263
	{
264
		$controller = new DisplayControllerCreate;
265
266
		$controller->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
267
		$controller->setInput($container->get(Input::class));
268
269
		return $controller;
270
	}
271
272
	/**
273
	 * Get the DisplayControllerGet class service
274
	 *
275
	 * @param   Container  $container  The DI container.
276
	 *
277
	 * @return  DisplayControllerGet
278
	 */
279 1 View Code Duplication
	public function getDisplayControllerGetService(Container $container) : DisplayControllerGet
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
280
	{
281 1
		$controller = new DisplayControllerGet(
282 1
			$container->get(StatsJsonView::class),
283 1
			$container->get(CacheItemPoolInterface::class)
284
		);
285
286 1
		$controller->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
287 1
		$controller->setInput($container->get(Input::class));
288
289 1
		return $controller;
290
	}
291
292
	/**
293
	 * Get the HelpCommand class service
294
	 *
295
	 * @param   Container  $container  The DI container.
296
	 *
297
	 * @return  AppCommands\HelpCommand
298
	 */
299 1 View Code Duplication
	public function getHelpCommandService(Container $container) : AppCommands\HelpCommand
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
300
	{
301 1
		$command = new AppCommands\HelpCommand;
302
303 1
		$command->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
304 1
		$command->setInput($container->get(Input::class));
305
306 1
		return $command;
307
	}
308
309
	/**
310
	 * Get the Input\Cli class service
311
	 *
312
	 * @param   Container  $container  The DI container.
313
	 *
314
	 * @return  Cli
315
	 */
316 1
	public function getInputCliService(Container $container) : Cli
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
317
	{
318 1
		return new Cli;
319
	}
320
321
	/**
322
	 * Get the Input class service
323
	 *
324
	 * @param   Container  $container  The DI container.
325
	 *
326
	 * @return  Input
327
	 */
328 1
	public function getInputService(Container $container) : Input
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
329
	{
330 1
		return new Input($_REQUEST);
331
	}
332
333
	/**
334
	 * Get the InstallCommand class service
335
	 *
336
	 * @param   Container  $container  The DI container.
337
	 *
338
	 * @return  AppCommands\InstallCommand
339
	 */
340 1 View Code Duplication
	public function getInstallCommandService(Container $container) : AppCommands\InstallCommand
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
341
	{
342 1
		$command = new AppCommands\InstallCommand($container->get(DatabaseDriver::class));
343
344 1
		$command->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
345 1
		$command->setInput($container->get(Input::class));
346
347 1
		return $command;
348
	}
349
350
	/**
351
	 * Get the router service
352
	 *
353
	 * @param   Container  $container  The DI container.
354
	 *
355
	 * @return  Router
356
	 */
357 1
	public function getRouterService(Container $container) : Router
358
	{
359 1
		$router = (new Router($container->get(Input::class)))
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Router\Router::setControllerPrefix() has been deprecated with message: 2.0 Deprecated without replacement

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
Deprecated Code introduced by
The method Joomla\Router\Router::setDefaultController() has been deprecated with message: 2.0 Deprecated without replacement

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
Deprecated Code introduced by
The method Joomla\Router\Router::addMap() has been deprecated with message: 2.0 Deprecated without replacement

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
360 1
			->setControllerPrefix('Joomla\\StatsServer\\Controllers\\')
361 1
			->setDefaultController('DisplayController')
362 1
			->addMap('/submit', 'SubmitController')
363 1
			->addMap('/:source', 'DisplayController');
364
365 1
		$router->setContainer($container);
366
367 1
		return $router;
368
	}
369
370
	/**
371
	 * Get the SnapshotCommand class service
372
	 *
373
	 * @param   Container  $container  The DI container.
374
	 *
375
	 * @return  AppCommands\SnapshotCommand
376
	 */
377 1 View Code Duplication
	public function getSnapshotCommandService(Container $container) : AppCommands\SnapshotCommand
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
378
	{
379 1
		$command = new AppCommands\SnapshotCommand($container->get(StatsJsonView::class));
380
381 1
		$command->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
382 1
		$command->setInput($container->get(Input::class));
383
384 1
		return $command;
385
	}
386
387
	/**
388
	 * Get the StatsJsonView class service
389
	 *
390
	 * @param   Container  $container  The DI container.
391
	 *
392
	 * @return  StatsJsonView
393
	 */
394 1
	public function getStatsJsonViewService(Container $container) : StatsJsonView
395
	{
396 1
		return new StatsJsonView(
397 1
			$container->get(StatsModel::class)
398
		);
399
	}
400
401
	/**
402
	 * Get the StatsModel class service
403
	 *
404
	 * @param   Container  $container  The DI container.
405
	 *
406
	 * @return  StatsModel
407
	 */
408 1
	public function getStatsModelService(Container $container) : StatsModel
409
	{
410 1
		return new StatsModel(
411 1
			$container->get(DatabaseDriver::class)
412
		);
413
	}
414
415
	/**
416
	 * Get the SubmitControllerCreate class service
417
	 *
418
	 * @param   Container  $container  The DI container.
419
	 *
420
	 * @return  SubmitControllerCreate
421
	 */
422 1 View Code Duplication
	public function getSubmitControllerCreateService(Container $container) : SubmitControllerCreate
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
423
	{
424 1
		$controller = new SubmitControllerCreate(
425 1
			$container->get(StatsModel::class)
426
		);
427
428 1
		$controller->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
429 1
		$controller->setInput($container->get(Input::class));
430
431 1
		return $controller;
432
	}
433
434
	/**
435
	 * Get the SubmitControllerGet class service
436
	 *
437
	 * @param   Container  $container  The DI container.
438
	 *
439
	 * @return  SubmitControllerGet
440
	 */
441 1 View Code Duplication
	public function getSubmitControllerGetService(Container $container) : SubmitControllerGet
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
442
	{
443 1
		$controller = new SubmitControllerGet;
444
445 1
		$controller->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
446 1
		$controller->setInput($container->get(Input::class));
447
448 1
		return $controller;
449
	}
450
451
	/**
452
	 * Get the Tags\JoomlaCommand class service
453
	 *
454
	 * @param   Container  $container  The DI container.
455
	 *
456
	 * @return  AppCommands\Tags\JoomlaCommand
457
	 */
458 1 View Code Duplication
	public function getTagsJoomlaCommandService(Container $container) : AppCommands\Tags\JoomlaCommand
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
459
	{
460 1
		$command = new AppCommands\Tags\JoomlaCommand($container->get(GitHub::class));
461
462 1
		$command->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
463 1
		$command->setInput($container->get(Input::class));
464
465 1
		return $command;
466
	}
467
468
	/**
469
	 * Get the Tags\PhpCommand class service
470
	 *
471
	 * @param   Container  $container  The DI container.
472
	 *
473
	 * @return  AppCommands\Tags\PhpCommand
474
	 */
475 1 View Code Duplication
	public function getTagsPhpCommandService(Container $container) : AppCommands\Tags\PhpCommand
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
476
	{
477 1
		$command = new AppCommands\Tags\PhpCommand($container->get(GitHub::class));
478
479 1
		$command->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
480 1
		$command->setInput($container->get(Input::class));
481
482 1
		return $command;
483
	}
484
485
	/**
486
	 * Get the UpdateCommand class service
487
	 *
488
	 * @param   Container  $container  The DI container.
489
	 *
490
	 * @return  AppCommands\UpdateCommand
491
	 */
492 1 View Code Duplication
	public function getUpdateCommandService(Container $container) : AppCommands\UpdateCommand
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
493
	{
494 1
		$command = new AppCommands\UpdateCommand;
495
496 1
		$command->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
497 1
		$command->setInput($container->get(Input::class));
498
499 1
		return $command;
500
	}
501
502
	/**
503
	 * Get the web application service
504
	 *
505
	 * @param   Container  $container  The DI container.
506
	 *
507
	 * @return  WebApplication
508
	 */
509 1
	public function getWebApplicationService(Container $container) : WebApplication
510
	{
511 1
		$application = new WebApplication($container->get(Input::class), $container->get('config'));
512
513
		// Inject extra services
514 1
		$application->setAnalytics($container->get(Analytics::class));
515 1
		$application->setLogger($container->get('monolog.logger.application'));
516 1
		$application->setRouter($container->get(Router::class));
517
518 1
		return $application;
519
	}
520
}
521