@@ -30,34 +30,29 @@ public function __construct(
30
30
DateTime $ activated_at = null
31
31
) {
32
32
if (! is_null ($ arguments ) && $ arguments !== []) {
33
- return $ this ->constructFromArgumentsArray ($ arguments );
34
- }
35
-
36
- if ((! is_null ($ amount ) && ! is_null ($ currency )) && is_null ($ minor )) {
37
- $ amount = Money::of ($ amount , $ currency )->getMinorAmount ()->toInt ();
33
+ return parent ::__construct ($ arguments );
38
34
}
39
35
40
36
parent ::__construct ([
41
- 'amount ' => $ minor ?? $ amount ,
37
+ 'minor ' => $ minor ,
38
+ 'amount ' => $ amount ,
42
39
'currency ' => $ currency ,
43
40
'type ' => $ type ,
44
41
'activated_at ' => $ activated_at
45
42
]);
46
43
}
47
44
48
- private function constructFromArgumentsArray ( $ arguments )
45
+ public function fill ( array $ attributes )
49
46
{
50
- $ amount = $ arguments ['amount ' ] ?? null ;
51
- $ minor = $ arguments ['minor ' ] ?? null ;
52
- $ currency = $ arguments ['currency ' ];
53
-
54
- if (is_null ($ amount ) && is_null ($ minor )) {
55
- throw new PriceValueNotDefinedException ('No value provided for price object. ' );
47
+ if ($ minor = $ attributes ['minor ' ] ?? null ) {
48
+ $ attributes ['amount ' ] = $ minor ;
49
+ } else if (($ amount = $ attributes ['amount ' ] ?? null ) && ($ currency = $ attributes ['currency ' ] ?? null )) {
50
+ $ attributes ['amount ' ] = Money::of ($ amount , $ currency )->getMinorAmount ()->toInt ();
56
51
}
57
52
58
- $ arguments [ ' amount ' ] = $ minor ?? Money:: of ( $ amount , $ currency )-> getMinorAmount ()-> toInt ( );
53
+ unset( $ attributes [ ' minor ' ] );
59
54
60
- return parent ::__construct ( $ arguments );
55
+ return parent ::fill ( $ attributes );
61
56
}
62
57
63
58
public function priceable ()
0 commit comments