Passed
Push — 252-fix/delete-post-revision-t... ( 2d4c2c...2c79ef )
by Sudar
08:04 queued 03:02
created

AddonInfo   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 97
rs 10
c 0
b 0
f 0
wmc 14

8 Methods

Rating   Name   Duplication   Size   Complexity  
A get_upsell_title() 0 6 2
A get_buy_url() 0 6 2
A get_upsell_message() 0 6 2
A get_name() 0 2 1
A get_url() 0 2 1
A get_description() 0 2 1
A get_slug() 0 2 1
A __construct() 0 18 4
1
<?php
2
3
namespace BulkWP\BulkDelete\Core\Addon;
4
5
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
6
7
/**
8
 * Data about an add-on.
9
 *
10
 * This is a `Record` class that only contains data about a particular add-on.
11
 * `Info` suffix is generally considered bad, but this is an exception since the suffix makes sense here.
12
 *
13
 * @since 6.0.0
14
 */
15
class AddonInfo {
16
17
	protected $name;
18
	protected $description;
19
	protected $slug;
20
	protected $url;
21
	protected $buy_url;
22
	protected $upsell_title;
23
	protected $upsell_message;
24
25
	/**
26
	 * Construct AddonInfo from an array.
27
	 *
28
	 * @param array $details Details about the add-on.
29
	 */
30
	public function __construct( $details = array() ) {
31
		if ( ! is_array( $details ) ) {
0 ignored issues
show
introduced by
The condition is_array($details) is always true.
Loading history...
32
			return;
33
		}
34
35
		$keys = array(
36
			'name',
37
			'description',
38
			'slug',
39
			'url',
40
			'buy_url',
41
			'upsell_title',
42
			'upsell_message',
43
		);
44
45
		foreach ( $keys as $key ) {
46
			if ( array_key_exists( $key, $details ) ) {
47
				$this->{$key} = $details[ $key ];
48
			}
49
		}
50
	}
51
52
	public function get_name() {
53
		return $this->name;
54
	}
55
56
	public function get_description() {
57
		return $this->description;
58
	}
59
60
	public function get_slug() {
61
		return $this->slug;
62
	}
63
64
	public function get_url() {
65
		return $this->url;
66
	}
67
68
	/**
69
	 * Get the url where users can buy the add-on.
70
	 *
71
	 * This url might include GA campaign parameters.
72
	 * Addon url is used if buy url is not explicitly set.
73
	 *
74
	 * @return string Url from where the add-on could be bought or just url if it not set.
75
	 */
76
	public function get_buy_url() {
77
		if ( empty( $this->buy_url ) ) {
78
			return $this->url;
79
		}
80
81
		return $this->buy_url;
82
	}
83
84
	/**
85
	 * Get upsell title for the addon.
86
	 *
87
	 * Name is used if title is not explicitly set.
88
	 *
89
	 * @return string Upsell title for addon or Name if it not set.
90
	 */
91
	public function get_upsell_title() {
92
		if ( empty( $this->upsell_title ) ) {
93
			return $this->name;
94
		}
95
96
		return $this->upsell_title;
97
	}
98
99
	/**
100
	 * Get upsell message for the addon.
101
	 *
102
	 * Description is used if title is not explicitly set.
103
	 *
104
	 * @return string Upsell description for addon or Description if it not set.
105
	 */
106
	public function get_upsell_message() {
107
		if ( empty( $this->upsell_message ) ) {
108
			return $this->description;
109
		}
110
111
		return $this->upsell_message;
112
	}
113
}
114