Skip to content

Commit 139ef17

Browse files
committed
Added tests
1 parent 4a40e98 commit 139ef17

File tree

7 files changed

+170
-240
lines changed

7 files changed

+170
-240
lines changed

Format/DateTime.php

Lines changed: 0 additions & 175 deletions
This file was deleted.

Format/Dom.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
namespace MaplePHP\DTO\Format;
1111

1212
use MaplePHP\Output\Dom\Document;
13-
use MaplePHP\DTO\Format\FormatInterface;
1413
use InvalidArgumentException;
1514

1615
final class Dom extends FormatAbstract
@@ -20,16 +19,15 @@ final class Dom extends FormatAbstract
2019
protected $str;
2120

2221
/**
23-
* Input is mixed data type in the interface becouse I do not know the type before the class
24-
* The class constructor MUST handle the input validation
22+
* Input is mixed data type in the interface becouse I do not know the type before the class * constructor MUST handle the input validation
2523
* @param string $value
2624
*/
2725
public function __construct(mixed $value)
2826
{
2927
if (is_array($value) || is_object($value)) {
3028
throw new InvalidArgumentException("Is expecting a string or a convertable string value.", 1);
3129
}
32-
$this->value = (string)$value;
30+
parent::__construct($value);
3331
}
3432

3533
/**

Format/Local.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ final class Local
1717
protected static $prefix;
1818
protected static $dir;
1919
protected static $data = [];
20-
2120
protected $value;
2221
protected $sprint = [];
2322

2423
/**
2524
* Init format by adding data to modify/format/traverse
26-
* @param mixed $data
25+
* @param mixed $data
2726
* @return self
27+
* @throws Exception
2828
*/
2929
public static function value(mixed $data)
3030
{

Format/Num.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
namespace MaplePHP\DTO\Format;
1212

13+
use NumberFormatter;
14+
1315
final class Num extends FormatAbstract implements FormatInterface
1416
{
1517
private static $numFormatter;
@@ -22,14 +24,17 @@ final class Num extends FormatAbstract implements FormatInterface
2224
*/
2325
public static function value(mixed $value): FormatInterface
2426
{
25-
$inst = new static($value);
26-
return $inst;
27+
return new static($value);
2728
}
2829

29-
public static function numFormatter()
30+
/**
31+
* Add number format for currency
32+
* @return NumberFormatter
33+
*/
34+
public static function numFormatter(): NumberFormatter
3035
{
3136
if (is_null(self::$numFormatter)) {
32-
self::$numFormatter = new \NumberFormatter("sv_SE", \NumberFormatter::CURRENCY);
37+
self::$numFormatter = new NumberFormatter("sv_SE", NumberFormatter::CURRENCY);
3338
}
3439
return self::$numFormatter;
3540
}
@@ -148,7 +153,7 @@ public function toBytes(): self
148153
}
149154

150155
/**
151-
* Convert number to a currence (e.g. 1000 = 1.000,00 kr)
156+
* Convert number to a currency (e.g. 1000 = 1.000,00 kr)
152157
* @param string $currency SEK, EUR
153158
* @param int|integer $decimals
154159
* @return FormatInterface
@@ -157,7 +162,6 @@ public function currency(string $currency, int $decimals = 2): FormatInterface
157162
{
158163
self::numFormatter()->setAttribute(self::$numFormatter::ROUNDING_MODE, $decimals);
159164
self::numFormatter()->setAttribute(self::$numFormatter::FRACTION_DIGITS, $decimals);
160-
161165
// Traverse back to string
162166
return Str::value(self::numFormatter()->formatCurrency($this->float()->get(), $currency));
163167
}

Format/Str.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
final class Str extends FormatAbstract implements FormatInterface
1717
{
18-
//protected $value;
19-
2018
/**
2119
* Input is mixed data type in the interface because I do not know the type before
2220
* The class constructor MUST handle the input validation

0 commit comments

Comments
 (0)