1 | <?php namespace EmailLog\Core\UI\Component; |
||
13 | class AddonController { |
||
14 | |||
15 | /** |
||
16 | * @var string Plugin basename. |
||
17 | */ |
||
18 | protected $plugin_dir_url; |
||
19 | |||
20 | /** |
||
21 | * @var string Error message. |
||
22 | */ |
||
23 | protected $addon_error_message; |
||
24 | |||
25 | /** |
||
26 | * @var const Cache expiration in hours. |
||
27 | */ |
||
28 | const CACHE_EXPIRE_IN_HRS = 12; |
||
29 | |||
30 | /** |
||
31 | * Initialize the plugin. |
||
32 | */ |
||
33 | public function __construct( $file ) { |
||
36 | |||
37 | /** |
||
38 | * Retrieves and outputs the Addon list HTML. |
||
39 | * |
||
40 | * return array If API call fails, the array is empty, else contains the addons info. |
||
41 | */ |
||
42 | protected function get_addons() { |
||
43 | $addons_result_array = array(); |
||
|
|||
44 | |||
45 | // Get Addons result array from Cache if available. |
||
46 | if ( false === ( $addons_result_array = get_transient( 'el_addons_result_array' ) ) ) { |
||
47 | |||
48 | // The products endpoint does not need a key or token to render published products. |
||
49 | // @todo: Change the API Url to get the actual addons. |
||
50 | $response = wp_remote_get( 'http://local.wordpress.dev/edd-api/products/' ); |
||
51 | |||
52 | if ( is_wp_error( $response ) ) { |
||
53 | /* |
||
54 | * @todo: The same error message is used twice in the class. |
||
55 | * Should we change this to a different one? |
||
56 | */ |
||
57 | $this->addon_error_message = __( 'We are not able to retrieve the add-on list now. Visit add-on page link to view the add-ons.', 'email-log' ); |
||
58 | } elseif ( is_array( $response ) ) { |
||
59 | $body = wp_remote_retrieve_body( $response ); |
||
60 | // Convert the JSON response to array |
||
61 | $addons_result_array = json_decode( $body, true ); |
||
62 | |||
63 | /* |
||
64 | * Cache Addons result for speed. |
||
65 | * Transient data other than string type are automatically serialized and deserialized. |
||
66 | * @link http://wordpress.stackexchange.com/a/123031/83739 |
||
67 | */ |
||
68 | set_transient( 'el_addons_result_array', $addons_result_array, self::CACHE_EXPIRE_IN_HRS * HOUR_IN_SECONDS ); |
||
69 | } |
||
70 | } |
||
71 | return $addons_result_array; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Checks Addons result and handles errors. |
||
76 | * |
||
77 | * Invokes `render_addon()` if no errors. |
||
78 | * |
||
79 | * return void |
||
80 | */ |
||
81 | public function render_addons() { |
||
98 | |||
99 | /** |
||
100 | * Renders HTML of individual addon. |
||
101 | * |
||
102 | * return void |
||
103 | */ |
||
104 | public function render_addon( $addon ) { |
||
127 | |||
128 | /** |
||
129 | * Render error in Addon page if any. |
||
130 | * |
||
131 | * return void |
||
132 | */ |
||
133 | public function render_addon_error() { |
||
143 | |||
144 | /** |
||
145 | * Renders the HTML for the Addons page. |
||
146 | */ |
||
147 | public function render_page() { |
||
163 | } |
||
164 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.