Completed
Push — master ( bd97eb...77fdab )
by Sudar
08:35
created

BundleLicense::get_addon_license_key()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 11
ccs 0
cts 6
cp 0
crap 12
rs 9.4285
c 0
b 0
f 0
1
<?php namespace EmailLog\Addon\License;
2
3
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
4
5
/**
6
 * BundleLicense Object.
7
 * There can be only one BundleLicence for all the add-ons.
8
 *
9
 * @since 2.0.0
10
 */
11
class BundleLicense extends BaseLicense {
12
13
	/**
14
	 * For Bundle the add-on name is hardcoded.
15
	 *
16
	 * @var string Add-on name.
17
	 */
18
	protected $addon_name = 'Email Log Bundle';
19
20
	/**
21
	 * Is the license valid?
22
	 *
23
	 * @return bool True if valid, False otherwise.
24
	 */
25
	public function is_valid() {
26
		if ( empty( $this->license_data ) ) {
27
			return false;
28
		}
29
30
		return ( 'valid' === $this->license_data->license );
31
	}
32
33
	/**
34
	 * Return bundle license key.
35
	 *
36
	 * @return string Bundle License key, if found.
37
	 */
38
	public function get_license_key() {
39
		if ( empty( $this->license_data ) ) {
40
			return parent::get_license_key();
41
		}
42
43
		return $this->license_data->bundle_license_key;
44
	}
45
46
	/**
47
	 * The option name in which the bundle license data will be stored.
48
	 *
49
	 * @return string Option name.
50
	 */
51
	protected function get_option_name() {
52
		return 'el_bundle_license';
53
	}
54
55
	/**
56
	 * Get the license key of an add-on from Bundle.
57
	 *
58
	 * @param string $addon_name Add-on name.
59
	 *
60
	 * @return bool|string False if no license key is found, otherwise license key.
61
	 */
62
	public function get_addon_license_key( $addon_name ) {
63
		if ( empty( $this->license_data ) ) {
64
			return false;
65
		}
66
67
		if ( ! isset( $this->license_data->bundled_licenses->{$addon_name} ) ) {
68
			return false;
69
		}
70
71
		return $this->license_data->bundled_licenses->{$addon_name}->license_key;
72
	}
73
}
74