AddonInfo::get_name()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
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
	protected $name;
17
	protected $code;
18
	protected $version;
19
	protected $author = 'Sudar Muthu';
20
	protected $root_file;
21
22
	/**
23
	 * Construct AddonInfo from an array.
24
	 *
25
	 * @param array $details Details about the add-on.
26
	 */
27
	public function __construct( $details = array() ) {
28
		if ( ! is_array( $details ) ) {
0 ignored issues
show
introduced by
The condition is_array($details) is always true.
Loading history...
29
			return;
30
		}
31
32
		$keys = array(
33
			'name',
34
			'code',
35
			'version',
36
			'author',
37
			'root_file',
38
		);
39
40
		foreach ( $keys as $key ) {
41
			if ( array_key_exists( $key, $details ) ) {
42
				$this->{$key} = $details[ $key ];
43
			}
44
		}
45
	}
46
47
	public function get_name() {
48
		return $this->name;
49
	}
50
51
	public function get_code() {
52
		return $this->code;
53
	}
54
55
	public function get_version() {
56
		return $this->version;
57
	}
58
59
	public function get_author() {
60
		return $this->author;
61
	}
62
63
	public function get_root_file() {
64
		return $this->root_file;
65
	}
66
67
	/**
68
	 * Return add-on slug.
69
	 *
70
	 * Add-on slug is the name of the root file without file extension.
71
	 *
72
	 * @since 6.0.1
73
	 *
74
	 * @return string Add-on slug.
75
	 */
76
	public function get_addon_slug() {
77
		return basename( $this->root_file, '.php' );
78
	}
79
80
	public function get_addon_directory() {
81
		return plugin_dir_path( $this->root_file );
82
	}
83
84
	public function get_addon_directory_url() {
85
		return plugin_dir_url( $this->root_file );
86
	}
87
}
88