GetPaid_REST_Report_Top_Earners_Controller   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
c 0
b 0
f 0
dl 0
loc 43
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A query_report_data() 0 31 1
1
<?php
2
/**
3
 * REST API top earners controller
4
 *
5
 * Handles requests to the reports/top_earners endpoint.
6
 *
7
 * @package GetPaid
8
 * @subpackage REST API
9
 * @since   2.0.0
10
 */
11
12
defined( 'ABSPATH' ) || exit;
13
14
/**
15
 * GetPaid REST top earners controller class.
16
 *
17
 * @package GetPaid
18
 */
19
class GetPaid_REST_Report_Top_Earners_Controller extends GetPaid_REST_Report_Top_Sellers_Controller {
20
21
	/**
22
	 * Route base.
23
	 *
24
	 * @var string
25
	 */
26
	protected $rest_base = 'reports/top_earners';
27
28
	/**
29
	 * Get all data needed for this report and store in the class.
30
	 */
31
	protected function query_report_data() {
32
33
		$this->report_data = GetPaid_Reports_Helper::get_invoice_report_data(
0 ignored issues
show
Documentation Bug introduced by
It seems like GetPaid_Reports_Helper::...> $this->report_range)) can also be of type string. However, the property $report_data is declared as type stdClass. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
34
			array(
35
				'data'         => array(
36
					'quantity'  => array(
37
						'type'     => 'invoice_item',
38
						'function' => 'SUM',
39
						'name'     => 'invoice_item_qty',
40
					),
41
					'item_id'   => array(
42
						'type'     => 'invoice_item',
43
						'function' => '',
44
						'name'     => 'invoice_item_id',
45
					),
46
					'item_name' => array(
47
						'type'     => 'invoice_item',
48
						'function' => '',
49
						'name'     => 'invoice_item_name',
50
					),
51
					'price'     => array(
52
						'type'     => 'invoice_item',
53
						'function' => 'SUM',
54
						'name'     => 'invoice_item_price',
55
					),
56
				),
57
				'group_by'     => 'invoice_item_id',
58
				'order_by'     => 'invoice_item_price DESC',
59
				'query_type'   => 'get_results',
60
				'limit'        => 10,
61
				'filter_range' => $this->report_range,
62
			)
63
		);
64
65
	}
66
67
}
68