Completed
Push — mysql_improvements ( 2e95ce...dedbef )
by Michael
03:52
created

ApplicationServiceProvider::getConsoleService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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