PluginProbe
Stripe Payment Forms by WP Simple Pay – Accept Credit Card Payments + Subscriptions with Stripe / trunk
Stripe Payment Forms by WP Simple Pay – Accept Credit Card Payments + Subscriptions with Stripe vtrunk
4.17.3 trunk 2.2.0 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 4.10.0 4.11.1 4.12.2 4.14.1 4.14.2 4.14.3 4.15.0 4.16.0 All 59 releases
stripe / src / Report / DateRange.php

DateRange.php in Stripe Payment Forms by WP Simple Pay – Accept Credit Card Payments + Subscriptions with Stripe trunk, at src/Report/DateRange.php

98 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Report: DateRange
4 *
5 * @package SimplePay
6 * @subpackage Core
7 * @copyright Copyright (c) 2023, Sandhills Development, LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 4.6.7
10 */
11
12 namespace SimplePay\Core\Report;
13
14 use DateTimeImmutable;
15 use InvalidArgumentException;
16
17 /**
18 * DateRange class.
19 *
20 * Standardizes the date range for reports.
21 *
22 * @since 4.6.7
23 */
24 class DateRange {
25
26 // Valid range types.
27 const RANGE_TYPES = array(
28 'today',
29 '7days',
30 '4weeks',
31 '3months',
32 '12months',
33 'monthtodate',
34 'yeartodate',
35 'custom',
36 );
37
38 /**
39 * The type of date range.
40 *
41 * @var string
42 */
43 public $type;
44
45 /**
46 * The start of the date range.
47 *
48 * @since 4.6.7
49 *
50 * @var \DateTimeImmutable
51 */
52 public $start;
53
54 /**
55 * The end of the date range.
56 *
57 * @since 4.6.7
58 *
59 * @var \DateTimeImmutable
60 */
61 public $end;
62
63 /**
64 * DateRange.
65 *
66 * @since 4.6.7
67 *
68 * @param string $type The type of date range.
69 * @param string $start The start of the date range.
70 * @param string $end The end of the date range.
71 * @throws \InvalidArgumentException If the date range range is invalid.
72 * @throws \InvalidArgumentException If the date range start is invalid.
73 * @throws \InvalidArgumentException If the date range end is invalid.
74 */
75 public function __construct( $type, $start, $end ) {
76 if ( ! in_array( $type, self::RANGE_TYPES, true ) ) {
77 throw new InvalidArgumentException( 'Invalid date range type.' );
78 }
79
80 $start = new DateTimeImmutable( $start );
81
82 if ( ! $start instanceof DateTimeImmutable ) {
83 throw new InvalidArgumentException( 'Invalid date range start.' );
84 }
85
86 $end = new DateTimeImmutable( $end );
87
88 if ( ! $end instanceof DateTimeImmutable ) {
89 throw new InvalidArgumentException( 'Invalid date range end.' );
90 }
91
92 $this->type = $type;
93 $this->start = $start;
94 $this->end = $end;
95 }
96
97 }
98