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

FrmInstallPlugin::get_activate_link()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 0
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
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