Completed
Push — master ( 186893...053e09 )
by Sudar
02:09
created

EDDUpdater::get_slug()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php namespace EmailLog\Addon\API;
2
3
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
4
5
if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) {
6
	$email_log = email_log();
7
	require_once $email_log->get_plugin_path() . 'include/libraries/EDD_SL_Plugin_Updater.php';
8
}
9
10
/**
11
 * Update add-on using EDD API.
12
 *
13
 * @since 2.0.0
14
 */
15
class EDDUpdater extends \EDD_SL_Plugin_Updater {
16
17
	/**
18
	 * Add-on slug.
19
	 * The base class already has a slug property but it is private.
20
	 * So we have to create a duplicate to handle that.
21
	 *
22
	 * @var string
23
	 */
24
	protected $addon_slug;
25
26
	/**
27
	 * Extract add-on slug alone and then pass everything to parent.
28
	 *
29
	 * @param string $_api_url     The URL pointing to the custom API endpoint.
30
	 * @param string $_plugin_file Path to the plugin file.
31
	 * @param array  $_api_data    Optional data to send with API calls.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $_api_data not be array|null? Also, consider making the array more specific, something like array<String>, or String[].

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type array and suggests a stricter type like array<String>.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
32
	 */
33
	public function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
34
		$this->addon_slug = basename( $_plugin_file, '.php' );
35
36
		parent::__construct( $_api_url, $_plugin_file, $_api_data );
37
	}
38
39
	/**
40
	 * Get add-on slug.
41
	 *
42
	 * @return string Add-on slug.
43
	 */
44
	public function get_slug() {
45
		return $this->addon_slug;
46
	}
47
48
	/**
49
	 * Get Download URL.
50
	 * We can't call `api_request` method directly since it is declared as private in parent class.
51
	 * So we call the `plugins_api_filter` method instead.
52
	 *
53
	 * @return string Download url.
54
	 */
55
	public function get_download_url() {
56
		$args = new \stdClass();
57
		$args->slug = $this->addon_slug;
58
59
		$response = $this->plugins_api_filter( null, 'plugin_information', $args );
60
61
		if ( ! $response instanceof \stdClass || ! property_exists( $response, 'package' ) ) {
62
			return '';
63
		}
64
65
		return $response->package;
66
	}
67
}
68