Total Complexity | 7 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Coverage | 80% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | abstract class AbstractMoneyType extends IntegerType |
||
12 | { |
||
13 | /** |
||
14 | * @param string $value |
||
15 | * |
||
16 | * @return Money |
||
17 | */ |
||
18 | abstract protected function createMoney(string $value): Money; |
||
19 | |||
20 | public function getName() |
||
21 | { |
||
22 | return 'Money'; |
||
23 | } |
||
24 | |||
25 | 2 | public function convertToPHPValue($value, AbstractPlatform $platform) |
|
26 | { |
||
27 | 2 | if ($value === null) { |
|
28 | 1 | return $value; |
|
29 | } |
||
30 | |||
31 | 2 | $val = $this->createMoney((string) $value); |
|
32 | |||
33 | 1 | return $val; |
|
34 | } |
||
35 | |||
36 | 2 | public function convertToDatabaseValue($value, AbstractPlatform $platform) |
|
37 | { |
||
38 | 2 | if ($value instanceof Money) { |
|
39 | return $value->getAmount(); |
||
40 | } |
||
41 | |||
42 | 2 | if ($value === null) { |
|
43 | 1 | return $value; |
|
44 | } |
||
45 | |||
46 | 1 | throw new \InvalidArgumentException('Cannot convert to dababase value: ' . var_export($value, true)); |
|
47 | } |
||
48 | |||
49 | 1 | public function requiresSQLCommentHint(AbstractPlatform $platform) |
|
52 | } |
||
53 | } |
||
54 |