Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
WP_Posts_Query_Order
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 to_query_array
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2/**
3 * Criteria for ordering and limiting WP Post queries.
4 *
5 * @package brianhenryie/bh-wp-bitcoin-gateway
6 */
7
8namespace BrianHenryIE\WP_Bitcoin_Gateway\API\Repositories\Queries;
9
10/**
11 * @see get_posts()
12 */
13readonly class WP_Posts_Query_Order {
14
15    /**
16     * Constructor.
17     *
18     * @param ?int    $count The number of posts to return in the query (max 200).
19     * @param ?string $order_by Which field to order the results by.
20     * @param ?string $order_direction Order the results ASC or DESC.
21     */
22    public function __construct(
23        public ?int $count = null,
24        public ?string $order_by = null,
25        public ?string $order_direction = null,
26    ) {
27    }
28
29    /**
30     * @return array{order?:string,numberposts?:int,orderby?:string}
31     */
32    public function to_query_array(): array {
33        $query_args = array();
34
35        if ( ! is_null( $this->count ) ) {
36            $query_args['numberposts'] = $this->count;
37        }
38        if ( ! is_null( $this->order_by ) ) {
39            $query_args['orderby'] = $this->order_by;
40        }
41        if ( ! is_null( $this->order_direction ) ) {
42            $query_args['order'] = $this->order_direction;
43        }
44
45        return $query_args;
46    }
47}