AddonListPage   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 5
Bugs 0 Features 1
Metric Value
eloc 34
c 5
b 0
f 1
dl 0
loc 66
ccs 0
cts 26
cp 0
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A enqueue_assets() 0 5 1
A register_page() 0 12 1
A render_page() 0 29 2
1
<?php namespace EmailLog\Core\UI\Page;
2
3
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
4
5
/**
6
 * Addon List Page.
7
 *
8
 * @since 2.0
9
 */
10
class AddonListPage extends BasePage {
11
12
	/**
13
	 * Page slug.
14
	 */
15
	const PAGE_SLUG = 'email-log-addons';
16
17
	/**
18
	 * Register page.
19
	 */
20
	public function register_page() {
21
		$this->page = add_submenu_page(
0 ignored issues
show
Documentation Bug introduced by
It seems like add_submenu_page(EmailLo...($this, 'render_page')) can also be of type false. However, the property $page is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
22
			LogListPage::PAGE_SLUG,
23
			__( 'Add-ons', 'email-log' ),
24
			__( 'Add-ons', 'email-log' ),
25
			'manage_options',
26
			self::PAGE_SLUG,
27
			array( $this, 'render_page' )
28
		);
29
30
		add_action( "load-{$this->page}", array( $this, 'render_help_tab' ) );
31
		add_action( "load-{$this->page}", array( $this, 'enqueue_assets' ) );
32
	}
33
34
	/**
35
	 * Render the list of add-on in the page.
36
	 */
37
	public function render_page() {
38
		?>
39
		<div class="wrap">
40
			<h1><?php _e( 'Email Log Add-ons', 'email-log' ); ?></h1>
41
			<?php settings_errors(); ?>
42
43
			<p>
44
				<?php _e( 'These add-ons provide additional functionality to Email Log plugin and are available for purchase.', 'email-log' ); ?>
45
				<?php _e( 'If your license includes the add-ons below, you will be able to install them from here with one-click.', 'email-log' ); ?>
46
			</p>
47
48
			<?php
49
			/**
50
			 * Before add-ons are listed in the add-on list page.
51
			 *
52
			 * @since 2.0.0
53
			 */
54
			do_action( 'el_before_addon_list' );
55
56
			$email_log = email_log();
57
			$licenser  = $email_log->get_licenser();
58
			if ( ! is_null( $licenser ) ) {
59
				$licenser->get_addon_list()->render();
60
			}
61
			?>
62
		</div>
63
		<?php
64
65
		$this->render_page_footer();
66
	}
67
68
	/**
69
	 * Enqueue static assets needed for this page.
70
	 */
71
	public function enqueue_assets() {
72
		$email_log = email_log();
73
74
		wp_enqueue_style( 'el_addon_list', plugins_url( 'assets/css/admin/addon-list.css', $email_log->get_plugin_file() ), array(), $email_log->get_version() );
75
		wp_enqueue_script( 'el_addon_list', plugins_url( 'assets/js/admin/addon-list.js', $email_log->get_plugin_file() ), array( 'jquery' ), $email_log->get_version(), true );
76
	}
77
}
78