Completed
Push — master ( a1aeda...5cf5b4 )
by Stephanie
02:17
created

FrmInstallPlugin   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A get_activate_link() 0 12 4
A is_installed() 0 3 1
A is_active() 0 3 1
A install_url() 0 3 1
A activate_url() 0 3 1
1
<?php
2
3
/**
4
 * @since 4.04.04
5
 */
6
class FrmInstallPlugin {
7
8
	protected $plugin_file; // format: folder/filename.php
9
	protected $plugin_slug;
10
11
	public function __construct( $atts ) {
12
		$this->plugin_file = $atts['plugin_file'];
13
		list( $slug, $file ) = explode( '/', $this->plugin_file );
0 ignored issues
show
Unused Code introduced by
The assignment to $file is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
14
		$this->plugin_slug = $slug;
15
	}
16
17
	public function get_activate_link() {
18
		if ( $this->is_installed() && $this->is_active() ) {
19
			return '';
20
		}
21
22
		if ( $this->is_installed() ) {
23
			$url = $this->activate_url();
24
		} else {
25
			$url = $this->install_url();
26
		}
27
		return $url;
28
	}
29
30
	public function is_installed() {
31
		return is_dir( WP_PLUGIN_DIR . '/' . $this->plugin_slug );
32
	}
33
34
	public function is_active() {
35
		return is_plugin_active( $this->plugin_file );
36
	}
37
38
	protected function install_url() {
39
		return wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $this->plugin_slug ), 'install-plugin_' . $this->plugin_slug );
40
	}
41
42
	protected function activate_url() {
43
		return wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=' . $this->plugin_file ), 'activate-plugin_' . $this->plugin_file );
44
	}
45
}
46