wsl.components.help.setup.php ➔ wsl_component_components_setup()   F
last analyzed

Complexity

Conditions 14
Paths 434

Size

Total Lines 112

Duplication

Lines 8
Ratio 7.14 %

Importance

Changes 0
Metric Value
cc 14
nc 434
nop 0
dl 8
loc 112
rs 2.3088
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*!
3
* WordPress Social Login
4
*
5
* https://miled.github.io/wordpress-social-login/ | https://github.com/miled/wordpress-social-login
6
*   (c) 2011-2020 Mohamed Mrassi and contributors | https://wordpress.org/plugins/wordpress-social-login/
7
*/
8
9
/**
10
* Components Manager 
11
*/
12
13
// Exit if accessed directly
14
if ( !defined( 'ABSPATH' ) ) exit; 
15
16
// --------------------------------------------------------------------
17
18
function wsl_component_components_setup()
19
{
20
	// HOOKABLE: 
21
	do_action( "wsl_component_components_setup_start" );
22
23
	GLOBAL $WORDPRESS_SOCIAL_LOGIN_COMPONENTS;
24
?>
25
<div style="padding: 15px; margin-bottom: 8px; border: 1px solid #ddd; background-color: #fff;box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);">
26
	<?php _wsl_e( "By default, only the three WSL core components are enabled. You can selectively enable or disable any of the non-core components by using the form below. Your WSL installation will continue to function. However, the features of the disabled components will no longer be accessible", 'wordpress-social-login' ) ?>.
27
</div>
28
29
<form action="" method="post">
30
	<table class="widefat fixed plugins" cellspacing="0">
31
		<thead>
32
			<tr>
33
				<th scope="col" class="manage-column column-label" style="width: 190px;"><?php _wsl_e( "Component", 'wordpress-social-login' ) ?></th>
34
				<th scope="col" class="manage-column column-description"><?php _wsl_e( "Description", 'wordpress-social-login' ) ?></th>
35
				<th scope="col" class="manage-column column-action" style="width: 140px;">&nbsp;</th>
36
			</tr>
37
		</thead>
38
39
		<tfoot>
40
			<tr>
41
				<th scope="col" class="manage-column column-label" style="width: 190px;"><?php _wsl_e( "Component", 'wordpress-social-login' ) ?></th>
42
				<th scope="col" class="manage-column column-description"><?php _wsl_e( "Description", 'wordpress-social-login' ) ?></th>
43
				<th scope="col" class="manage-column column-action" style="width: 140px;">&nbsp;</th>
44
			</tr>
45
		</tfoot>
46
47
		<tbody id="the-list"> 
48
			<?php
49
				foreach( $WORDPRESS_SOCIAL_LOGIN_COMPONENTS as $name => $settings )
50
				{ 
51
					$plugin_tr_class  = '';
0 ignored issues
show
Unused Code introduced by
$plugin_tr_class is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
52
					$plugin_notices   = '';
0 ignored issues
show
Unused Code introduced by
$plugin_notices is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
53
					$plugin_enablable = true;
54
55
					if( $name == "core" )
56
					{
57
						continue;
58
					}
59
60
					$plugin_tr_class = $settings["enabled"] ? "active" : "inactive"; 
61
			?>
62
				<tr id="<?php echo $name ?>" class="<?php echo $name ?> <?php echo $plugin_tr_class ?>"> 
63
					<td class="component-label" style="width: 190px;"> &nbsp;
64
						<?php if( $settings["type"] == "core" ): ?>
65
							<div class="icon16 icon-generic"></div>
66
						<?php elseif( $settings["type"] == "addon" ): ?>
67
							<div class="icon16 icon-plugins"></div>
68
						<?php else: ?>
69
							<div class="icon16 icon-appearance"></div>
70
						<?php endif; ?>
71
						
72
						<strong><?php _wsl_e( $settings["label"], 'wordpress-social-login' ) ?></strong> 
73
					</td>
74
					<td class="column-description">
75
						<p><?php _wsl_e( $settings["description"], 'wordpress-social-login' ) ?></p>
76
						<?php
77
							$meta = array();
78
79 View Code Duplication
							if( isset( $settings["version"] ) )
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
80
							{
81
								$meta[] = sprintf( _wsl__( "Version %s", 'wordpress-social-login' ), $settings["version"] );
82
							}
83
84
							if( isset( $settings["author"] ) )
85
							{
86
								if( isset( $settings["author_url"] ) )
87
								{
88
									$meta[] = sprintf( _wsl__( 'By <a href="%s" target="_blank">%s</a>', 'wordpress-social-login' ), $settings["author_url"], $settings["author"] );
89
								}
90
								else
91
								{
92
									$meta[] = sprintf( _wsl__( 'By %s', 'wordpress-social-login' ), $settings["author"] );
93
								}
94
							}
95
96 View Code Duplication
							if( isset( $settings["component_url"] ) )
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
97
							{
98
								$meta[] = sprintf( _wsl__( '<a href="%s" target="_blank">Visit component site</a>', 'wordpress-social-login' ), $settings["component_url"] );
99
							}
100
101
							if( ! empty($meta) )
102
							{
103
								?><p><?php echo implode( ' | ', $meta  ); ?></p><?php 
104
							}
105
						?>
106
					</td>
107
					<td class="column-action" align="right" style="width: 120px;">
108
						<p>
109
							<?php if( $plugin_enablable && $settings["type"] != "core" ): ?>
110
								<?php if( $settings["enabled"] ): ?> 
111
									<a class="button-secondary" href="options-general.php?page=wordpress-social-login&wslp=components&disable=<?php echo $name ?>"><?php _wsl_e( "Disable", 'wordpress-social-login' ) ?></a>
112
								<?php else: ?>
113
									<a class="button-primary" style="color:#ffffff" href="options-general.php?page=wordpress-social-login&wslp=components&enable=<?php echo $name ?>"><?php _wsl_e( "Enable", 'wordpress-social-login' ) ?>&nbsp;</a>
114
								<?php endif; ?>
115
							<?php endif; ?>
116
							&nbsp;
117
						</p>
118
					</td>
119
				</tr>
120
			<?php
121
				} 
122
			?>
123
		</tbody>
124
	</table>
125
</form> 
126
<?php
127
	// HOOKABLE: 
128
	do_action( "wsl_component_components_setup_end" );
129
}
130
131
// --------------------------------------------------------------------	
132