Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
33.33% |
3 / 9 |
|
50.00% |
3 / 6 |
CRAP | |
0.00% |
0 / 1 |
BatchPosting | |
33.33% |
3 / 9 |
|
50.00% |
3 / 6 |
21.52 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getPosting | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
removePosting | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
addPosting | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
count | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * Jingga |
4 | * |
5 | * PHP Version 8.1 |
6 | * |
7 | * @package Modules\Accounting\Models |
8 | * @copyright Dennis Eichhorn |
9 | * @license OMS License 2.0 |
10 | * @version 1.0.0 |
11 | * @link https://jingga.app |
12 | */ |
13 | declare(strict_types=1); |
14 | |
15 | namespace Modules\Accounting\Models; |
16 | |
17 | /** |
18 | * BatchPosting class. |
19 | * |
20 | * @package Modules\Accounting\Models |
21 | * @license OMS License 2.0 |
22 | * @link https://jingga.app |
23 | * @since 1.0.0 |
24 | */ |
25 | class BatchPosting implements \Countable |
26 | { |
27 | /** |
28 | * ID. |
29 | * |
30 | * @var int |
31 | * @since 1.0.0 |
32 | */ |
33 | public int $id = 0; |
34 | |
35 | /** |
36 | * Creator. |
37 | * |
38 | * @var int |
39 | * @since 1.0.0 |
40 | */ |
41 | public int $creator = 0; |
42 | |
43 | /** |
44 | * Created. |
45 | * |
46 | * @var \DateTimeImmutable |
47 | * @since 1.0.0 |
48 | */ |
49 | public \DateTimeImmutable $created; |
50 | |
51 | /** |
52 | * Description. |
53 | * |
54 | * @var string |
55 | * @since 1.0.0 |
56 | */ |
57 | public string $description = ''; |
58 | |
59 | /** |
60 | * Postings. |
61 | * |
62 | * @var PostingInterface[] |
63 | * @since 1.0.0 |
64 | */ |
65 | private $postings = []; |
66 | |
67 | /** |
68 | * Constructor. |
69 | * |
70 | * @since 1.0.0 |
71 | */ |
72 | public function __construct() |
73 | { |
74 | $this->created = new \DateTimeImmutable('now'); |
75 | } |
76 | |
77 | /** |
78 | * Get id. |
79 | * |
80 | * @return int |
81 | * |
82 | * @since 1.0.0 |
83 | */ |
84 | public function getId() : int |
85 | { |
86 | return $this->id; |
87 | } |
88 | |
89 | /** |
90 | * Get posting. |
91 | * |
92 | * @param int $id Posting ID |
93 | * |
94 | * @return null|PostingInterface |
95 | * |
96 | * @since 1.0.0 |
97 | */ |
98 | public function getPosting(int $id) : ?PostingInterface |
99 | { |
100 | return $this->postings[$id] ?? null; |
101 | } |
102 | |
103 | /** |
104 | * Remove posting. |
105 | * |
106 | * @param int $id Posting ID |
107 | * |
108 | * @return bool |
109 | * |
110 | * @since 1.0.0 |
111 | */ |
112 | public function removePosting($id) : bool |
113 | { |
114 | if (!isset($this->postings[$id])) { |
115 | return false; |
116 | } |
117 | |
118 | unset($this->postings[$id]); |
119 | |
120 | return true; |
121 | } |
122 | |
123 | /** |
124 | * Add posting. |
125 | * |
126 | * @param PostingInterface $posting Posting |
127 | * |
128 | * @return void |
129 | * |
130 | * @since 1.0.0 |
131 | */ |
132 | public function addPosting(PostingInterface $posting) : void |
133 | { |
134 | $this->postings[] = $posting; |
135 | } |
136 | |
137 | /** |
138 | * {@inheritdoc} |
139 | */ |
140 | public function count() : int |
141 | { |
142 | return \count($this->postings); |
143 | } |
144 | } |