Completed
Push — master ( 49679a...617b2a )
by Sudar
02:03
created

OverridePluginAPI   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 41
rs 10
c 1
b 0
f 0
wmc 5
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 3 1
A inject_addon_install_resource() 0 20 4
1
<?php namespace EmailLog\Core\Request;
2
3
use EmailLog\Addon\AddonList;
4
use EmailLog\Core\Loadie;
5
6
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
7
8
/**
9
 * Override WordPress Plugin API and inject add-on urls.
10
 *
11
 * @since 2.0.0
12
 */
13
class OverridePluginAPI implements Loadie {
14
15
	/**
16
	 * Setup actions.
17
	 *
18
	 * @inheritdoc
19
	 */
20
	public function load() {
21
		add_filter( 'plugins_api', array( $this, 'inject_addon_install_resource' ), 10, 3 );
22
	}
23
24
	/**
25
	 * Inject add-on install resource into WordPress plugin API.
26
	 *
27
	 * @param  object|bool $res    Plugin resource object or boolean false.
28
	 * @param  string      $action The API call being performed.
29
	 * @param  object      $args   Arguments for the API call being performed.
30
	 *
31
	 * @return \stdClass Processed resource.
32
	 */
33
	public function inject_addon_install_resource( $res, $action, $args ) {
34
		if ( 'plugin_information' !== $action || empty( $args->slug ) ) {
35
			return $res;
36
		}
37
38
		$addon_list = new AddonList();
39
		$addon = $addon_list->get_addon_by_slug( $args->slug );
40
41
		if ( ! $addon ) {
42
			return $res;
43
		}
44
45
		$res                = new stdClass();
46
		$res->name          = 'Email Log - ' . $addon->name;
0 ignored issues
show
Documentation introduced by
The property $name is declared private in EmailLog\Addon\Addon. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
47
		$res->version       = ''; // TODO: Implement Version.
48
		$res->download_link = $addon->get_download_url();
49
		$res->tested        = false; // TODO: Implement tested up to.
50
51
		return $res;
52
	}
53
}
54