Completed
Push — master ( 5903bb...3f3351 )
by Michael
06:31
created

EventServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 15.38 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 8
loc 52
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 8 8 1
A getDispatcherService() 0 11 2
A getErrorSubscriberService() 0 7 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
 * 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\DI\Container;
12
use Joomla\DI\ServiceProviderInterface;
13
use Joomla\Event\Dispatcher;
14
use Joomla\Event\DispatcherInterface;
15
use Joomla\StatsServer\EventListener\ErrorSubscriber;
16
use Psr\Log\LoggerInterface;
17
18
/**
19
 * Event service provider
20
 */
21
class EventServiceProvider implements ServiceProviderInterface
22
{
23
	/**
24
	 * Registers the service provider with a DI container.
25
	 *
26
	 * @param   Container  $container  The DI container.
27
	 *
28
	 * @return  void
29
	 */
30 View Code Duplication
	public function register(Container $container): void
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...
31
	{
32 12
		$container->alias(Dispatcher::class, DispatcherInterface::class)
33
			->share(DispatcherInterface::class, [$this, 'getDispatcherService']);
34 12
35 12
		$container->share(ErrorSubscriber::class, [$this, 'getErrorSubscriberService'])
36
			->tag('event.subscriber', [ErrorSubscriber::class]);
37 12
	}
38 12
39
	/**
40 12
	 * Get the DispatcherInterface service
41 12
	 *
42 12
	 * @param   Container  $container  The DI container.
43
	 *
44
	 * @return  DispatcherInterface
45
	 */
46
	public function getDispatcherService(Container $container): DispatcherInterface
47
	{
48
		$dispatcher = new Dispatcher;
49
50
		foreach ($container->getTagged('event.subscriber') as $subscriber)
51 10
		{
52
			$dispatcher->addSubscriber($subscriber);
53 10
		}
54 10
55
		return $dispatcher;
56 10
	}
57
58
	/**
59
	 * Get the ErrorSubscriber service
60
	 *
61
	 * @param   Container  $container  The DI container.
62
	 *
63
	 * @return  ErrorSubscriber
64
	 */
65
	public function getErrorSubscriberService(Container $container): ErrorSubscriber
66 10
	{
67
		$subscriber = new ErrorSubscriber;
68 10
		$subscriber->setLogger($container->get(LoggerInterface::class));
69
70 10
		return $subscriber;
71
	}
72
}
73