Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
62.50% covered (warning)
62.50%
5 / 8
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
Invoice_Event
62.50% covered (warning)
62.50%
5 / 8
66.67% covered (warning)
66.67%
2 / 3
4.84
0.00% covered (danger)
0.00%
0 / 1
 get_instance
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 created
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 updated
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * Invoice Event.
4 *
5 * @package automattic/jetpack-crm
6 */
7
8namespace Automattic\Jetpack\CRM\Event_Manager;
9
10use Automattic\Jetpack\CRM\Entities\Factories\Invoice_Factory;
11use Automattic\Jetpack\CRM\Entities\Invoice;
12
13/**
14 * Invoice Event class.
15 *
16 * @since 6.2.0
17 */
18class Invoice_Event implements Event {
19
20    /**
21     * The Invoice_Event instance.
22     *
23     * @since 6.2.0
24     * @var Invoice_Event
25     */
26    private static $instance = null;
27
28    /**
29     * Get the singleton instance of this class.
30     *
31     * @since 6.2.0
32     *
33     * @return Invoice_Event The Invoice_Event instance.
34     */
35    public static function get_instance(): Invoice_Event {
36        if ( ! self::$instance ) {
37            self::$instance = new self();
38        }
39
40        return self::$instance;
41    }
42
43    /**
44     * A new invoice was created.
45     *
46     * @since 6.2.0
47     *
48     * @param array $invoice_data The created invoice data.
49     * @return void
50     */
51    public function created( array $invoice_data ): void {
52
53        /** @var Invoice $invoice */
54        $invoice = Invoice_Factory::create( $invoice_data );
55
56        do_action( 'jpcrm_invoice_created', $invoice );
57    }
58
59    /**
60     * The invoice was updated.
61     *
62     * @since 6.2.0
63     *
64     * @param array $invoice_data The updated invoice data.
65     * @param array $previous_invoice_data The previous invoice data.
66     * @return void
67     */
68    public function updated( array $invoice_data, array $previous_invoice_data ): void {
69        $invoice = Invoice_Factory::create( $invoice_data );
70
71        $previous_invoice = Invoice_Factory::create( $previous_invoice_data );
72
73        do_action( 'jpcrm_invoice_updated', $invoice, $previous_invoice );
74    }
75}