Completed
Pull Request — master (#38)
by Sam
03:11
created

Subscription   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 62.5 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 30
loc 48
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parseMux() 15 15 3
A parseNetwork() 15 15 3

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 Jalle19\StatusManager\Database;
4
5
use Jalle19\StatusManager\Database\Base\Subscription as BaseSubscription;
6
use Jalle19\tvheadend\model\multiplex\Multiplex;
7
use Jalle19\tvheadend\model\network\Network;
8
use Jalle19\tvheadend\model\SubscriptionStatus;
9
10
/**
11
 * @package   Jalle19\StatusManager\Database
12
 * @copyright Copyright &copy; Sam Stenvall 2015-
13
 * @license   https://www.gnu.org/licenses/gpl.html The GNU General Public License v2.0
14
 */
15
class Subscription extends BaseSubscription
16
{
17
18
	/**
19
	 * @param SubscriptionStatus $subscriptionStatus
20
	 * @param Multiplex[]        $availableMuxes
21
	 *
22
	 * @return string
23
	 */
24 View Code Duplication
	public static function parseMux(SubscriptionStatus $subscriptionStatus, array $availableMuxes)
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...
25
	{
26
		$service = $subscriptionStatus->service;
27
28
		// Check if the service string contains /$mux/
29
		foreach ($availableMuxes as $mux)
30
		{
31
			if (strpos($service, '/' . $mux->name . '/') !== false)
32
			{
33
				return $mux->name;
34
			}
35
		}
36
37
		return null;
38
	}
39
40
41
	/**
42
	 * @param SubscriptionStatus $subscriptionStatus
43
	 * @param Network[]          $availableNetworks
44
	 *
45
	 * @return string
46
	 */
47 View Code Duplication
	public static function parseNetwork(SubscriptionStatus $subscriptionStatus, array $availableNetworks)
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...
48
	{
49
		$service = $subscriptionStatus->service;
50
51
		// Check if the service string contains /$network/
52
		foreach ($availableNetworks as $network)
53
		{
54
			if (strpos($service, '/' . $network->networkname . '/') !== false)
55
			{
56
				return $network->networkname;
57
			}
58
		}
59
60
		return null;
61
	}
62
}
63