Completed
Push — master ( 9af6b2...4eed4e )
by Michael
02:14
created

getCliApplicationService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 1
crap 1
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\Log\LoggerInterface;
31
use TheIconic\Tracking\GoogleAnalytics\Analytics;
32
33
/**
34
 * Application service provider
35
 */
36
class ApplicationServiceProvider implements ServiceProviderInterface
37
{
38
	/**
39
	 * Registers the service provider with a DI container.
40
	 *
41
	 * @param   Container  $container  The DI container.
42
	 *
43
	 * @return  void
44
	 */
45 1
	public function register(Container $container)
46
	{
47
		/*
48
		 * Application Classes
49
		 */
50
51 1
		$container->alias(CliApplication::class, JoomlaApplication\AbstractCliApplication::class)
52 1
			->share(JoomlaApplication\AbstractCliApplication::class, [$this, 'getCliApplicationService'], true);
53
54 1
		$container->alias(WebApplication::class, JoomlaApplication\AbstractWebApplication::class)
55 1
			->share(JoomlaApplication\AbstractWebApplication::class, [$this, 'getWebApplicationService'], true);
56
57
		/*
58
		 * Application Class Dependencies
59
		 */
60
61 1
		$container->share(Analytics::class, [$this, 'getAnalyticsService'], true);
62 1
		$container->share(Cli::class, [$this, 'getInputCliService'], true);
63 1
		$container->share(Console::class, [$this, 'getConsoleService'], true);
64 1
		$container->share(Input::class, [$this, 'getInputService'], true);
65 1
		$container->share(JoomlaApplication\Cli\Output\Processor\ColorProcessor::class, [$this, 'getColorProcessorService'], true);
66 1
		$container->share(JoomlaApplication\Cli\CliInput::class, [$this, 'getCliInputService'], true);
67 1
		$container->share(Router::class, [$this, 'getRouterService'], true);
68
69 1
		$container->alias(JoomlaApplication\Cli\CliOutput::class, JoomlaApplication\Cli\Output\Stdout::class)
70 1
			->share(JoomlaApplication\Cli\Output\Stdout::class, [$this, 'getCliOutputService'], true);
71
72
		/*
73
		 * Console Commands
74
		 */
75
76 1
		$container->share(AppCommands\HelpCommand::class, [$this, 'getHelpCommandService'], true);
77 1
		$container->share(AppCommands\InstallCommand::class, [$this, 'getInstallCommandService'], true);
78 1
		$container->share(AppCommands\Database\MigrateCommand::class, [$this, 'getDatabaseMigrateCommandService'], true);
79 1
		$container->share(AppCommands\Database\StatusCommand::class, [$this, 'getDatabaseStatusCommandService'], true);
80 1
		$container->share(AppCommands\SnapshotCommand::class, [$this, 'getSnapshotCommandService'], true);
81 1
		$container->share(AppCommands\Tags\JoomlaCommand::class, [$this, 'getTagsJoomlaCommandService'], true);
82 1
		$container->share(AppCommands\Tags\PhpCommand::class, [$this, 'getTagsPhpCommandService'], true);
83 1
		$container->share(AppCommands\UpdateCommand::class, [$this, 'getUpdateCommandService'], true);
84
85
		/*
86
		 * MVC Layer
87
		 */
88
89
		// Controllers
90 1
		$container->share(DisplayControllerCreate::class, [$this, 'getDisplayControllerCreateService'], true);
91 1
		$container->share(DisplayControllerGet::class, [$this, 'getDisplayControllerGetService'], true);
92 1
		$container->share(SubmitControllerCreate::class, [$this, 'getSubmitControllerCreateService'], true);
93 1
		$container->share(SubmitControllerGet::class, [$this, 'getSubmitControllerGetService'], true);
94
95
		// Models
96 1
		$container->share(StatsModel::class, [$this, 'getStatsModelService'], true);
97
98
		// Views
99 1
		$container->share(StatsJsonView::class, [$this, 'getStatsJsonViewService'], true);
100 1
	}
101
102
	/**
103
	 * Get the Analytics class service
104
	 *
105
	 * @param   Container  $container  The DI container.
106
	 *
107
	 * @return  Analytics
108
	 */
109 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...
110
	{
111 1
		return new Analytics(true);
112
	}
113
114
	/**
115
	 * Get the CLI application service
116
	 *
117
	 * @param   Container  $container  The DI container.
118
	 *
119
	 * @return  CliApplication
120
	 */
121 1
	public function getCliApplicationService(Container $container) : CliApplication
122
	{
123 1
		$application = new CliApplication(
124 1
			$container->get(Cli::class),
125 1
			$container->get('config'),
126 1
			$container->get(JoomlaApplication\Cli\CliOutput::class),
127 1
			$container->get(JoomlaApplication\Cli\CliInput::class),
128 1
			$container->get(Console::class)
129
		);
130
131
		// Inject extra services
132 1
		$application->setLogger($container->get('monolog.logger.cli'));
133
134 1
		return $application;
135
	}
136
137
	/**
138
	 * Get the CliInput class service
139
	 *
140
	 * @param   Container  $container  The DI container.
141
	 *
142
	 * @return  JoomlaApplication\Cli\CliInput
143
	 */
144 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...
145
	{
146 1
		return new JoomlaApplication\Cli\CliInput;
147
	}
148
149
	/**
150
	 * Get the CliOutput class service
151
	 *
152
	 * @param   Container  $container  The DI container.
153
	 *
154
	 * @return  JoomlaApplication\Cli\CliOutput
155
	 */
156 1
	public function getCliOutputService(Container $container) : JoomlaApplication\Cli\Output\Stdout
157
	{
158 1
		return new JoomlaApplication\Cli\Output\Stdout($container->get(JoomlaApplication\Cli\Output\Processor\ColorProcessor::class));
159
	}
160
161
	/**
162
	 * Get the ColorProcessor class service
163
	 *
164
	 * @param   Container  $container  The DI container.
165
	 *
166
	 * @return  JoomlaApplication\Cli\Output\Processor\ColorProcessor
167
	 */
168 1
	public function getColorProcessorService(Container $container) : JoomlaApplication\Cli\Output\Processor\ColorProcessor
169
	{
170 1
		$processor = new JoomlaApplication\Cli\Output\Processor\ColorProcessor;
171
172
		/** @var Input $input */
173 1
		$input = $container->get(Cli::class);
174
175 1
		if ($input->getBool('nocolors', false))
176
		{
177
			$processor->noColors = true;
178
		}
179
180
		// Setup app colors (also required in "nocolors" mode - to strip them).
181 1
		$processor->addStyle('title', new JoomlaApplication\Cli\ColorStyle('yellow', '', ['bold']));
182
183 1
		return $processor;
184
	}
185
186
	/**
187
	 * Get the console service
188
	 *
189
	 * @param   Container  $container  The DI container.
190
	 *
191
	 * @return  Console
192
	 */
193 1
	public function getConsoleService(Container $container) : Console
194
	{
195 1
		$console = new Console;
196 1
		$console->setContainer($container);
197
198 1
		return $console;
199
	}
200
201
	/**
202
	 * Get the Database\MigrateCommand class service
203
	 *
204
	 * @param   Container  $container  The DI container.
205
	 *
206
	 * @return  AppCommands\Database\MigrateCommand
207
	 */
208 1
	public function getDatabaseMigrateCommandService(Container $container) : AppCommands\Database\MigrateCommand
209
	{
210 1
		$command = new AppCommands\Database\MigrateCommand($container->get(Migrations::class));
211
212 1
		$command->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
213 1
		$command->setInput($container->get(Input::class));
214 1
		$command->setLogger($container->get(LoggerInterface::class));
215
216 1
		return $command;
217
	}
218
219
	/**
220
	 * Get the Database\StatusCommand class service
221
	 *
222
	 * @param   Container  $container  The DI container.
223
	 *
224
	 * @return  AppCommands\Database\StatusCommand
225
	 */
226 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...
227
	{
228 1
		$command = new AppCommands\Database\StatusCommand($container->get(Migrations::class));
229
230 1
		$command->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
231 1
		$command->setInput($container->get(Input::class));
232
233 1
		return $command;
234
	}
235
236
	/**
237
	 * Get the DisplayControllerCreate class service
238
	 *
239
	 * @param   Container  $container  The DI container.
240
	 *
241
	 * @return  DisplayControllerCreate
242
	 */
243 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...
244
	{
245
		$controller = new DisplayControllerCreate;
246
247
		$controller->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
248
		$controller->setInput($container->get(Input::class));
249
250
		return $controller;
251
	}
252
253
	/**
254
	 * Get the DisplayControllerGet class service
255
	 *
256
	 * @param   Container  $container  The DI container.
257
	 *
258
	 * @return  DisplayControllerGet
259
	 */
260 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...
261
	{
262 1
		$controller = new DisplayControllerGet(
263 1
			$container->get(StatsJsonView::class)
264
		);
265
266 1
		$controller->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
267 1
		$controller->setInput($container->get(Input::class));
268
269 1
		return $controller;
270
	}
271
272
	/**
273
	 * Get the HelpCommand class service
274
	 *
275
	 * @param   Container  $container  The DI container.
276
	 *
277
	 * @return  AppCommands\HelpCommand
278
	 */
279 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...
280
	{
281 1
		$command = new AppCommands\HelpCommand;
282
283 1
		$command->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
284 1
		$command->setInput($container->get(Input::class));
285
286 1
		return $command;
287
	}
288
289
	/**
290
	 * Get the Input\Cli class service
291
	 *
292
	 * @param   Container  $container  The DI container.
293
	 *
294
	 * @return  Cli
295
	 */
296 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...
297
	{
298 1
		return new Cli;
299
	}
300
301
	/**
302
	 * Get the Input class service
303
	 *
304
	 * @param   Container  $container  The DI container.
305
	 *
306
	 * @return  Input
307
	 */
308 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...
309
	{
310 1
		return new Input($_REQUEST);
311
	}
312
313
	/**
314
	 * Get the InstallCommand class service
315
	 *
316
	 * @param   Container  $container  The DI container.
317
	 *
318
	 * @return  AppCommands\InstallCommand
319
	 */
320 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...
321
	{
322 1
		$command = new AppCommands\InstallCommand($container->get(DatabaseDriver::class));
323
324 1
		$command->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
325 1
		$command->setInput($container->get(Input::class));
326
327 1
		return $command;
328
	}
329
330
	/**
331
	 * Get the router service
332
	 *
333
	 * @param   Container  $container  The DI container.
334
	 *
335
	 * @return  Router
336
	 */
337 1
	public function getRouterService(Container $container) : Router
338
	{
339 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...
340 1
			->setControllerPrefix('Joomla\\StatsServer\\Controllers\\')
341 1
			->setDefaultController('DisplayController')
342 1
			->addMap('/submit', 'SubmitController')
343 1
			->addMap('/:source', 'DisplayController');
344
345 1
		$router->setContainer($container);
346
347 1
		return $router;
348
	}
349
350
	/**
351
	 * Get the SnapshotCommand class service
352
	 *
353
	 * @param   Container  $container  The DI container.
354
	 *
355
	 * @return  AppCommands\SnapshotCommand
356
	 */
357 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...
358
	{
359 1
		$command = new AppCommands\SnapshotCommand($container->get(StatsJsonView::class));
360
361 1
		$command->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
362 1
		$command->setInput($container->get(Input::class));
363
364 1
		return $command;
365
	}
366
367
	/**
368
	 * Get the StatsJsonView class service
369
	 *
370
	 * @param   Container  $container  The DI container.
371
	 *
372
	 * @return  StatsJsonView
373
	 */
374 1
	public function getStatsJsonViewService(Container $container) : StatsJsonView
375
	{
376 1
		return new StatsJsonView(
377 1
			$container->get(StatsModel::class)
378
		);
379
	}
380
381
	/**
382
	 * Get the StatsModel class service
383
	 *
384
	 * @param   Container  $container  The DI container.
385
	 *
386
	 * @return  StatsModel
387
	 */
388 1
	public function getStatsModelService(Container $container) : StatsModel
389
	{
390 1
		return new StatsModel(
391 1
			$container->get(DatabaseDriver::class)
392
		);
393
	}
394
395
	/**
396
	 * Get the SubmitControllerCreate class service
397
	 *
398
	 * @param   Container  $container  The DI container.
399
	 *
400
	 * @return  SubmitControllerCreate
401
	 */
402 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...
403
	{
404 1
		$controller = new SubmitControllerCreate(
405 1
			$container->get(StatsModel::class)
406
		);
407
408 1
		$controller->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
409 1
		$controller->setInput($container->get(Input::class));
410
411 1
		return $controller;
412
	}
413
414
	/**
415
	 * Get the SubmitControllerGet class service
416
	 *
417
	 * @param   Container  $container  The DI container.
418
	 *
419
	 * @return  SubmitControllerGet
420
	 */
421 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...
422
	{
423 1
		$controller = new SubmitControllerGet;
424
425 1
		$controller->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
426 1
		$controller->setInput($container->get(Input::class));
427
428 1
		return $controller;
429
	}
430
431
	/**
432
	 * Get the Tags\JoomlaCommand class service
433
	 *
434
	 * @param   Container  $container  The DI container.
435
	 *
436
	 * @return  AppCommands\Tags\JoomlaCommand
437
	 */
438 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...
439
	{
440 1
		$command = new AppCommands\Tags\JoomlaCommand($container->get(GitHub::class));
441
442 1
		$command->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
443 1
		$command->setInput($container->get(Input::class));
444
445 1
		return $command;
446
	}
447
448
	/**
449
	 * Get the Tags\PhpCommand class service
450
	 *
451
	 * @param   Container  $container  The DI container.
452
	 *
453
	 * @return  AppCommands\Tags\PhpCommand
454
	 */
455 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...
456
	{
457 1
		$command = new AppCommands\Tags\PhpCommand($container->get(GitHub::class));
458
459 1
		$command->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
460 1
		$command->setInput($container->get(Input::class));
461
462 1
		return $command;
463
	}
464
465
	/**
466
	 * Get the UpdateCommand class service
467
	 *
468
	 * @param   Container  $container  The DI container.
469
	 *
470
	 * @return  AppCommands\UpdateCommand
471
	 */
472 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...
473
	{
474 1
		$command = new AppCommands\UpdateCommand;
475
476 1
		$command->setApplication($container->get(JoomlaApplication\AbstractApplication::class));
477 1
		$command->setInput($container->get(Input::class));
478
479 1
		return $command;
480
	}
481
482
	/**
483
	 * Get the web application service
484
	 *
485
	 * @param   Container  $container  The DI container.
486
	 *
487
	 * @return  WebApplication
488
	 */
489 1
	public function getWebApplicationService(Container $container) : WebApplication
490
	{
491 1
		$application = new WebApplication($container->get(Input::class), $container->get('config'));
492
493
		// Inject extra services
494 1
		$application->setAnalytics($container->get(Analytics::class));
495 1
		$application->setLogger($container->get('monolog.logger.application'));
496 1
		$application->setRouter($container->get(Router::class));
497
498 1
		return $application;
499
	}
500
}
501