Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Bitcoin_Address_Query
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 4
20
0.00% covered (danger)
0.00%
0 / 1
 get_post_type
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_wp_post_fields
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 get_meta_input
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Strongly typed object for querying Bitcoin_Address in wp_posts table.
4 *
5 * A mapping of domain terms to WP_Post columns + meta fields.
6 *
7 * TODO: Add a WP CLI output of a post here.
8 *
9 * @package brianhenryie/bh-wp-bitcoin-gateway
10 */
11
12namespace BrianHenryIE\WP_Bitcoin_Gateway\API\Repositories\Queries;
13
14use BrianHenryIE\WP_Bitcoin_Gateway\API\Model\Wallet\Bitcoin_Address_Status;
15use BrianHenryIE\WP_Bitcoin_Gateway\API\Model\Wallet\Bitcoin_Address_WP_Post_Interface;
16use BrianHenryIE\WP_Bitcoin_Gateway\Brick\Money\Money;
17use BrianHenryIE\WP_Bitcoin_Gateway\WP_Includes\Post_BH_Bitcoin_Address;
18
19/**
20 * @see Post_BH_Bitcoin_Address
21 */
22readonly class Bitcoin_Address_Query extends WP_Post_Query_Abstract {
23
24    /**
25     * The Bitcoin_Address wp_post post_type.
26     */
27    protected function get_post_type(): string {
28        return Bitcoin_Address_WP_Post_Interface::POST_TYPE;
29    }
30
31    /**
32     *
33     * @return array<string,mixed> $map to:from
34     */
35    #[\Override]
36    protected function get_wp_post_fields(): array {
37        return array(
38            'post_name'   => $this->xpub, // slug.
39            'post_title'  => $this->xpub, // post_title.
40            'post_status' => $this->status,
41            'post_parent' => $this->wallet_wp_post_parent_id,
42        );
43    }
44
45    /**
46     * @return array<string,mixed>
47     */
48    protected function get_meta_input(): array {
49        return array(
50            Bitcoin_Address_WP_Post_Interface::DERIVATION_PATH_SEQUENCE_NUMBER_META_KEY => $this->derivation_path_sequence_index,
51            Bitcoin_Address_WP_Post_Interface::TRANSACTIONS_META_KEY => $this->transactions_post_ids,
52            Bitcoin_Address_WP_Post_Interface::ORDER_ID_META_KEY => $this->associated_order_id,
53            Bitcoin_Address_WP_Post_Interface::INTEGRATION_ID_META_KEY => $this->integration_id,
54            Bitcoin_Address_WP_Post_Interface::TARGET_AMOUNT_META_KEY => $this->target_amount,
55        );
56    }
57
58    /**
59     * Constructor
60     *
61     * Sometimes these fields are used to fetch, but some are only used to update.
62     *
63     * @param ?int                    $wallet_wp_post_parent_id The wp_posts id of the Bitcoin_Wallet this Bitcoin_Address belongs to.
64     * @param ?Bitcoin_Address_Status $status Is the Bitcoin_Address available etc.
65     * @param ?string                 $xpub The public key for the address.
66     * @param ?int                    $derivation_path_sequence_index This Bitcoin Address is the nth one derived from the Bitcoin_Wallet.
67     * @param array<int, string>|null $transactions_post_ids post_id:tx_id.
68     * @param string|class-string     $integration_id The plugin that is using this address.
69     * @param ?int                    $associated_order_id The wp_post ID for the order associated with the address.
70     * @param ?Money                  $target_amount The target amount of bitcoin to receive for the order the address is associated with. Saved in post_meta as `array{amount:string,currency:string}`.
71     */
72    public function __construct(
73        public ?int $wallet_wp_post_parent_id = null,
74        public ?Bitcoin_Address_Status $status = null,
75        public ?string $xpub = null,
76        public ?int $derivation_path_sequence_index = null,
77        public ?array $transactions_post_ids = null,
78        public ?string $integration_id = null,
79        public ?int $associated_order_id = null,
80        public ?Money $target_amount = null,
81    ) {
82        parent::__construct();
83    }
84}