Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Report_Request
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 get_requested_fields
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * One report request.
4 *
5 * @package automattic/jetpack-woocommerce-stats
6 */
7
8namespace Automattic\Jetpack\WooCommerceStats\Report_Execution;
9
10/**
11 * The report, route, params and fields a handler serves.
12 *
13 * @since $$next-version$$
14 */
15class Report_Request {
16
17    /**
18     * The report.
19     *
20     * @var Report_Definition
21     */
22    public $definition;
23
24    /**
25     * The route as requested, trailing slash included.
26     *
27     * @var string
28     */
29    public $route;
30
31    /**
32     * The report's query params, as sent.
33     *
34     * @var array
35     */
36    public $params;
37
38    /**
39     * Summary fields the caller reads, or null when it named none and reads the whole contract.
40     *
41     * @var string[]|null
42     */
43    public $fields;
44
45    /**
46     * Whether to skip caches.
47     *
48     * @var bool
49     */
50    public $force_refresh;
51
52    /**
53     * Constructor.
54     *
55     * @param Report_Definition $definition    The report.
56     * @param string            $route         The route as requested.
57     * @param array             $params        The report's query params, as sent.
58     * @param bool              $force_refresh Whether to skip caches.
59     * @param string[]|null     $fields        Summary fields the caller reads, or null.
60     */
61    public function __construct( Report_Definition $definition, $route, array $params, $force_refresh = false, $fields = null ) {
62        $this->definition    = $definition;
63        $this->route         = $route;
64        $this->params        = $params;
65        $this->force_refresh = $force_refresh;
66        $this->fields        = $fields;
67    }
68
69    /**
70     * The summary fields the request asks for: those named, or every field of the contract.
71     *
72     * @return string[]
73     */
74    public function get_requested_fields() {
75        return $this->fields ?? $this->definition->get_field_names();
76    }
77}