Completed
Push — dev/2.3.0 ( 292df5...fc2871 )
by Sudar
02:51
created

EmailLogSystemInfo::print_email_log_details()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 16
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 15
nc 2
nop 0
dl 0
loc 16
ccs 0
cts 1
cp 0
crap 20
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
namespace EmailLog\Core\UI\Component;
4
5
use EmailLog\Core\DB\TableManager;
6
use EmailLog\Core\EmailLog;
7
use Sudar\WPSystemInfo\SystemInfo;
8
9
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
10
11
/**
12
 * Email Log System Info.
13
 *
14
 * Uses the WPSystemInfo library.
15
 *
16
 * @link https://github.com/sudar/wp-system-info
17
 *
18
 * @since 2.3.0
19
 */
20
class EmailLogSystemInfo extends SystemInfo {
21
22
	/**
23
	 * Setup hooks and filters.
24
	 */
25
	public function load() {
26
		add_action( 'before_system_info_for_email-log', array( $this, 'print_email_log_details' ) );
27
		add_action( 'before_system_info_for_email-log', array( $this, 'print_email_log_license_details' ) );
28
	}
29
30
	/**
31
	 * Print details about Email Log.
32
	 *
33
	 * PHPCS is disabled for this function since alignment will mess up the system info output.
34
	 * phpcs:disable
35
	 */
36
	public function print_email_log_details() {
37
		$email_log = email_log();
38
39
		$email_log_core = get_option( 'email-log-core' );
40
		?>
41
-- Email Log Configuration --
42
43
Email Log Version:                  <?php echo EmailLog::VERSION . "\n"; ?>
44
Number of Logs:                     <?php echo $email_log->table_manager->get_logs_count() . "\n"; ?>
45
Email Log DB Version:               <?php echo get_option( TableManager::DB_OPTION_NAME ) . "\n"; ?>
0 ignored issues
show
Bug introduced by
Are you sure get_option(EmailLog\Core...anager::DB_OPTION_NAME) of type false|mixed can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
Email Log DB Version:               <?php echo /** @scrutinizer ignore-type */ get_option( TableManager::DB_OPTION_NAME ) . "\n"; ?>
Loading history...
46
<?php if ( is_array( $email_log_core ) ) : ?>
47
Allowed Roles for Email Log View:   <?php echo implode( ', ', $email_log_core['allowed_user_roles'] ) . "\n"; ?>
48
Remove All Data on Uninstallation:  <?php echo $email_log_core['remove_on_uninstall'] !== '' ? 'Yes' : 'No' . "\n"; ?>
49
Disable DashBoard Widget:           <?php echo $email_log_core['hide_dashboard_widget'] === 'true' ? 'Yes' : 'No' . "\n"; ?>
50
<?php endif; ?>
51
52
<?php
53
	}
54
	// phpcs:enable
55
56
	/**
57
	 * Print details about Email Log Licenses.
58
	 */
59
	public function print_email_log_license_details() {
60
		$bundle_license = $this->get_bundle_license();
61
62
		if ( ! is_null( $bundle_license ) ) {
63
			$this->print_bundle_license_details( $bundle_license );
64
		} else {
65
			$this->print_individual_addon_license();
66
		}
67
	}
68
69
	/**
70
	 * Get Bundle license.
71
	 *
72
	 * @return \EmailLog\Addon\License\BundleLicense|null Bundle license or null if no bundle license.
73
	 */
74
	protected function get_bundle_license() {
75
		$email_log = email_log();
76
77
		$licenser       = $email_log->get_licenser();
78
		$bundle_license = $licenser->get_bundle_license();
79
80
		$bundle_license_key = $bundle_license->get_license_key();
81
		if ( ! empty( $bundle_license_key ) ) {
82
			return $bundle_license;
83
		}
84
85
		return null;
86
	}
87
88
	/**
89
	 * Print bundle license details.
90
	 *
91
	 * @param \EmailLog\Addon\License\BundleLicense $bundle_license Bundle license.
92
	 *
93
	 * PHPCS is disabled for this function since alignment will mess up the system info output.
94
	 * phpcs:disable
95
	 */
96
	protected function print_bundle_license_details( $bundle_license ) {
97
		?>
98
-- Email Log Bundle License --
99
100
License Key:               <?php echo $bundle_license->get_license_key(), "\n"; ?>
101
License Expiry Date:       <?php echo $bundle_license->get_expiry_date(), "\n"; ?>
0 ignored issues
show
Bug introduced by
Are you sure $bundle_license->get_expiry_date() of type false|string can be used in echo? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

101
License Expiry Date:       <?php echo /** @scrutinizer ignore-type */ $bundle_license->get_expiry_date(), "\n"; ?>
Loading history...
102
<?php if ( $bundle_license->is_valid() ) : ?>
103
License Valid:             <?php echo 'Yes', "\n"; ?>
104
<?php else : ?>
105
License Valid:             <?php echo 'No', "\n"; ?>
106
<?php endif; ?>
107
108
<?php
109
	}
110
	// phpcs:enable
111
112
	/**
113
	 * Print license details of individual add-ons.
114
	 *
115
	 * PHPCS is disabled for this function since alignment will mess up the system info output.
116
	 * phpcs:disable
117
	 */
118
	protected function print_individual_addon_license() {
119
		$email_log = email_log();
120
121
		$licenser = $email_log->get_licenser();
122
		$addons   = $licenser->get_addon_list()->get_addons();
123
		?>
124
-- Email Log Addon License --
125
126
<?php
127
		foreach ( $addons as $addon ) {
128
			echo '- ', $addon->name;
129
130
			$license_key = $addon->get_addon_license_key();
131
132
			if ( ! empty( $license_key ) ) {
133
				$addon_license = $addon->get_license();
134
				echo ' (', $license_key, ' - ', $addon_license->get_expiry_date(), ')';
0 ignored issues
show
Bug introduced by
Are you sure $addon_license->get_expiry_date() of type false|string can be used in echo? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

134
				echo ' (', $license_key, ' - ', /** @scrutinizer ignore-type */ $addon_license->get_expiry_date(), ')';
Loading history...
135
			}
136
137
			echo "\n";
138
		}
139
		echo "\n";
140
	}
141
	// phpcs:enable
142
143
	/**
144
	 * Change the default config.
145
	 *
146
	 * @return array Modified config.
147
	 */
148
	protected function get_default_config() {
149
		$config = parent::get_default_config();
150
151
		$config['show_posts']      = false;
152
		$config['show_taxonomies'] = false;
153
		$config['show_users']      = false;
154
155
		return $config;
156
	}
157
}
158