diff --git a/src/Concerns/TripletTransformer.php b/src/Concerns/TripletTransformer.php index d4006d5..69a0c4f 100644 --- a/src/Concerns/TripletTransformer.php +++ b/src/Concerns/TripletTransformer.php @@ -15,7 +15,6 @@ */ trait TripletTransformer { - /** * Trả về từ điển hổ trợ cho việc chuyển đổi. * @@ -37,13 +36,12 @@ protected function tripletToWords(int $triplet, bool $isFirst, int $exponent): s [$hundred, $ten, $unit] = $this->splitTriplet($triplet); $dictionary = $this->getDictionary(); - if (0 < $hundred || !$isFirst) { + if (0 < $hundred || ! $isFirst) { $words[] = $dictionary->getTripletHundred($hundred); if (0 === $ten && 0 < $unit) { $words[] = $dictionary->tripletTenSeparator(); } - } if (0 < $ten) { @@ -67,8 +65,8 @@ protected function tripletToWords(int $triplet, bool $isFirst, int $exponent): s */ private function splitTriplet(int $triplet): array { - $hundred = (int)($triplet / 100) % 10; - $ten = (int)($triplet / 10) % 10; + $hundred = (int) ($triplet / 100) % 10; + $ten = (int) ($triplet / 10) % 10; $unit = $triplet % 10; return [$hundred, $ten, $unit]; @@ -101,6 +99,4 @@ private function getTripletUnit(int $unit, int $ten): string return $dictionary->getTripletUnit($unit); } - - } diff --git a/src/Concerns/TripletsConverter.php b/src/Concerns/TripletsConverter.php index eccd7f2..a03660a 100644 --- a/src/Concerns/TripletsConverter.php +++ b/src/Concerns/TripletsConverter.php @@ -13,7 +13,6 @@ */ trait TripletsConverter { - /** * Chia số truyền vào thành các cụm gồm 3 số để hổ trợ cho việc chuyển sang chữ số. * @@ -26,11 +25,9 @@ protected function numberToTriplets(int $number): array while (0 < $number) { array_unshift($result, $number % 1000); - $number = (int)($number / 1000); + $number = (int) ($number / 1000); } return $result; } - - } diff --git a/src/Dictionary.php b/src/Dictionary.php index 2f3fe93..926a85c 100644 --- a/src/Dictionary.php +++ b/src/Dictionary.php @@ -30,7 +30,7 @@ class Dictionary implements DictionaryInterface 'sáu', 'bảy', 'tám', - 'chín' + 'chín', ]; /** @@ -48,7 +48,7 @@ class Dictionary implements DictionaryInterface 'sáu mươi', 'bảy mươi', 'tám mươi', - 'chín mươi' + 'chín mươi', ]; /** @@ -69,11 +69,11 @@ class Dictionary implements DictionaryInterface 'triệu', 'tỷ', 'nghìn tỷ', - 'triệu tỷ' + 'triệu tỷ', ]; /** - * @inheritDoc + * {@inheritdoc} */ public function zero(): string { @@ -81,7 +81,7 @@ public function zero(): string } /** - * @inheritDoc + * {@inheritdoc} */ public function minus(): string { @@ -89,7 +89,7 @@ public function minus(): string } /** - * @inheritDoc + * {@inheritdoc} */ public function separator(): string { @@ -97,7 +97,7 @@ public function separator(): string } /** - * @inheritDoc + * {@inheritdoc} */ public function tripletTenSeparator(): string { @@ -105,7 +105,7 @@ public function tripletTenSeparator(): string } /** - * @inheritDoc + * {@inheritdoc} */ public function specialTripletUnitOne(): string { @@ -113,7 +113,7 @@ public function specialTripletUnitOne(): string } /** - * @inheritDoc + * {@inheritdoc} */ public function specialTripletUnitFour(): string { @@ -121,7 +121,7 @@ public function specialTripletUnitFour(): string } /** - * @inheritDoc + * {@inheritdoc} */ public function specialTripletUnitFive(): string { @@ -129,7 +129,7 @@ public function specialTripletUnitFive(): string } /** - * @inheritDoc + * {@inheritdoc} */ public function fraction(): string { @@ -137,11 +137,11 @@ public function fraction(): string } /** - * @inheritDoc + * {@inheritdoc} */ public function getTripletUnit(int $unit): string { - if (!isset(static::$tripletUnits[$unit])) { + if (! isset(static::$tripletUnits[$unit])) { throw new InvalidArgumentException(sprintf('Unit arg (`%s`) must be in 0-9 range!', $unit)); } @@ -149,11 +149,11 @@ public function getTripletUnit(int $unit): string } /** - * @inheritDoc + * {@inheritdoc} */ public function getTripletTen(int $ten): string { - if (!isset(static::$tripletTens[$ten])) { + if (! isset(static::$tripletTens[$ten])) { throw new InvalidArgumentException(sprintf('Ten arg (`%s`) must be in 0-9 range!', $ten)); } @@ -161,23 +161,23 @@ public function getTripletTen(int $ten): string } /** - * @inheritDoc + * {@inheritdoc} */ public function getTripletHundred(int $hundred): string { - if (!isset(static::$tripletUnits[$hundred])) { + if (! isset(static::$tripletUnits[$hundred])) { throw new InvalidArgumentException(sprintf('Hundred arg (`%s`) must be in 0-9 range!', $hundred)); } - return static::$tripletUnits[$hundred] . $this->separator() . static::$hundred; + return static::$tripletUnits[$hundred].$this->separator().static::$hundred; } /** - * @inheritDoc + * {@inheritdoc} */ public function getExponent(int $power): string { - if (!isset(static::$exponents[$power])) { + if (! isset(static::$exponents[$power])) { throw new InvalidArgumentException(sprintf('Power arg (`%s`) not exist in vietnamese dictionary!', $power)); } diff --git a/src/DictionaryInterface.php b/src/DictionaryInterface.php index 003118a..3b76243 100644 --- a/src/DictionaryInterface.php +++ b/src/DictionaryInterface.php @@ -100,5 +100,4 @@ public function getTripletHundred(int $hundred): string; * @return string */ public function getExponent(int $power): string; - } diff --git a/src/SouthDictionary.php b/src/SouthDictionary.php index 1dead9b..cdfa1b4 100644 --- a/src/SouthDictionary.php +++ b/src/SouthDictionary.php @@ -13,7 +13,6 @@ */ class SouthDictionary extends Dictionary { - /** * Thay nghìn => ngàn. * @@ -25,11 +24,11 @@ class SouthDictionary extends Dictionary 'triệu', 'tỷ', 'nghìn tỷ', - 'triệu tỷ' + 'triệu tỷ', ]; /** - * @inheritDoc + * {@inheritdoc} */ public function tripletTenSeparator(): string { @@ -37,11 +36,10 @@ public function tripletTenSeparator(): string } /** - * @inheritDoc + * {@inheritdoc} */ public function specialTripletUnitFour(): string { return 'bốn'; } - } diff --git a/src/Transformer.php b/src/Transformer.php index 2685e1e..fc88112 100644 --- a/src/Transformer.php +++ b/src/Transformer.php @@ -17,7 +17,6 @@ */ class Transformer { - use TripletsConverter; use TripletTransformer; @@ -48,7 +47,7 @@ public function __construct(?DictionaryInterface $dictionary = null) */ public function toWords($number): string { - if (!is_numeric($number)) { + if (! is_numeric($number)) { throw new InvalidArgumentException(sprintf('Number arg (`%s`) must be numeric!', $number)); } @@ -67,11 +66,9 @@ public function toWords($number): string $triplets = $this->numberToTriplets($number); foreach ($triplets as $pos => $triplet) { - if (0 < $triplet) { $words[] = $this->tripletToWords($triplet, 0 === $pos, count($triplets) - $pos - 1); } - } if (0 < $decimal) { @@ -118,7 +115,7 @@ public function toCurrency($number, $unit = 'đồng'): string protected function resolve($number): array { $number += 0; // trick xóa các số 0 lẻ sau cùng của phân số - $number = (string)$number; + $number = (string) $number; if (false !== strpos($number, '.')) { $result = explode('.', $number, 2); @@ -130,12 +127,10 @@ protected function resolve($number): array } /** - * @inheritDoc + * {@inheritdoc} */ protected function getDictionary(): DictionaryInterface { return $this->dictionary; } - } - diff --git a/tests/CurrencyTest.php b/tests/CurrencyTest.php index 5c75fb9..27b49db 100644 --- a/tests/CurrencyTest.php +++ b/tests/CurrencyTest.php @@ -13,7 +13,6 @@ */ class CurrencyTest extends TestCase { - /** * @dataProvider dataProvider */ @@ -132,11 +131,10 @@ public function usdDataProvider(): array ['bảy nghìn bốn trăm bốn mươi tư đô hai mươi sáu xen', 7444.26], ['một nghìn bốn trăm bảy mươi tư đô sáu xen', 1474.60], ['bảy nghìn bảy trăm bảy mươi đô', 7770], - ['ba nghìn bảy trăm chín mươi hai đô', 3792] + ['ba nghìn bảy trăm chín mươi hai đô', 3792], ]; } - public function dataProvider(): array { return [ @@ -238,7 +236,7 @@ public function dataProvider(): array ['năm triệu sáu trăm chín mươi nghìn bảy trăm đồng', 5690700], ['chín trăm mười bảy triệu bảy trăm đồng', 917000700], ['năm trăm nghìn bảy trăm đồng', 500700], - ['mười bảy triệu bảy trăm nghìn một trăm đồng', 17700100] + ['mười bảy triệu bảy trăm nghìn một trăm đồng', 17700100], ]; } } diff --git a/tests/NumberTest.php b/tests/NumberTest.php index 84fec26..167c9ea 100644 --- a/tests/NumberTest.php +++ b/tests/NumberTest.php @@ -13,7 +13,6 @@ */ class NumberTest extends TestCase { - /** * @dataProvider dataProvider */ @@ -140,7 +139,7 @@ public function fractionDataProvider(): array ['năm trăm ba mươi phẩy tám trăm ba mươi sáu', 530.836], ['năm mươi lăm phẩy mười chín', 55.190], ['hai trăm tám mươi chín phẩy sáu trăm ba mươi mốt', 289.631], - ['năm trăm linh một phẩy bảy trăm mười bốn', 501.714] + ['năm trăm linh một phẩy bảy trăm mười bốn', 501.714], ]; } @@ -246,7 +245,7 @@ public function minusDataProvider(): array ['âm ba', -3], ['âm hai', -2], ['âm một', -1], - ['không', 0] + ['không', 0], ]; } @@ -375,7 +374,7 @@ public function dataProvider(): array ['một tỷ không trăm bảy mươi sáu', 1000000076], ['một tỷ không trăm bảy mươi bảy', 1000000077], ['một tỷ không trăm bảy mươi tám', 1000000078], - ['một tỷ không trăm bảy mươi chín', 1000000079] + ['một tỷ không trăm bảy mươi chín', 1000000079], ]; } } diff --git a/tests/SouthDictionaryTest.php b/tests/SouthDictionaryTest.php index cba4f1f..bff1b1f 100644 --- a/tests/SouthDictionaryTest.php +++ b/tests/SouthDictionaryTest.php @@ -17,7 +17,6 @@ */ class SouthDictionaryTest extends BaseTestCase { - /** * @dataProvider dataProvider */ @@ -129,7 +128,7 @@ public function dataProvider() ['sáu mươi ngàn năm trăm lẻ ba', 60503], ['ba mươi lăm ngàn hai trăm chín mươi bốn', 35294], ['tám mươi tám ngàn bốn trăm hai mươi bảy', 88427], - ['sáu trăm năm mươi ngàn sáu trăm bảy mươi ba', 650673] + ['sáu trăm năm mươi ngàn sáu trăm bảy mươi ba', 650673], ]; } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 549c356..20d906b 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -16,7 +16,6 @@ */ class TestCase extends BaseTestCase { - /** * @var \PHPViet\NumberToWords\DictionaryInterface */ @@ -31,5 +30,4 @@ public function setUp() { $this->transformer = new Transformer($this->dictionary); } - }