From f074cbc6bcff64cf166777e835820543d0c1e2a2 Mon Sep 17 00:00:00 2001 From: abdumu Date: Thu, 16 Nov 2017 00:47:43 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/numberedStringOrder.php | 12 +++++----- tests/numberedStringOrderTest.php | 37 +++++++++++++------------------ 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/src/numberedStringOrder.php b/src/numberedStringOrder.php index 6ff335d..cfcafcd 100644 --- a/src/numberedStringOrder.php +++ b/src/numberedStringOrder.php @@ -36,8 +36,8 @@ public function sort($array) * Words to numbers. * * @param string $str + * @param bool $normalized * - * @param bool $normalized * @return int */ public function wordsToNumbers($str, $normalized = false) @@ -144,14 +144,14 @@ protected function englishWordsToNumbers($str) /** * @param string $str + * @param bool $normalized * - * @param bool $normalized * @return int|mixed */ protected function arabicWordsToNumbers($str, $normalized) { // Normalization phase - if(!$normalized) { + if (!$normalized) { $str = $this->normalizeText($str); } @@ -236,8 +236,6 @@ protected function arabicWordsToNumbers($str, $normalized) 'ثمانمئة' => 800, 'تسعمئة' => 900, - - 'مئة' => 100, 'الف' => 1000, 'الفان' => 2000, @@ -262,7 +260,7 @@ protected function arabicWordsToNumbers($str, $normalized) foreach ($complications as $complication => $by) { $subTotal = 0; - if (preg_match("/(.*)\s*{$complication}/", $str, $result) !== false && isset($result[1])) { + if (preg_match("/(.*)\s*{$complication}/", $str, $result) !== false && isset($result[1])) { $result = " {$result[1]} "; foreach ($spell as $word => $value) { @@ -333,7 +331,7 @@ protected function compile($array) if (is_numeric(trim($needle))) { $result[$string] = (int) trim($needle); } elseif (preg_match('/(\d+)\s+$/', $needle, $num)) { - $sort = (int) trim($num[0]); + $sort = (int) trim($num[0]); $result[$string] = $sort; } else { $ar_int = $this->wordsToNumbers($needle, true); diff --git a/tests/numberedStringOrderTest.php b/tests/numberedStringOrderTest.php index f24d39e..18cf7f1 100644 --- a/tests/numberedStringOrderTest.php +++ b/tests/numberedStringOrderTest.php @@ -18,7 +18,7 @@ protected function setUp() /** @test */ public function english_words() { - $orderdArray = $this->numberedStringOrder->sort([ + $orderdArray = $this->numberedStringOrder->sort([ '30 hundreds', '30 millions, 24 thousands, 20 hundreds', '30 millions, 25 thousands, 20 hundreds', @@ -31,8 +31,6 @@ public function english_words() '14 hundreds', ]); - - $expected = [ 14, 20, @@ -43,10 +41,9 @@ public function english_words() '30 millions, 24 thousands, 20 hundreds', '30 millions, 25 thousands, 20 hundreds', '30 millions, 25 thousands, 21 hundreds', - '14 billions' + '14 billions', ]; - $this->assertEquals($expected, $orderdArray); } @@ -62,11 +59,11 @@ public function readme_examples() 'episode one', 'episode two', 'episode eleven', - 'episode three' + 'episode three', ]); - $this->assertEquals(["episode1","episode one","episode two","episode three","episode 5","episode eleven","episode50","episode two hundred", - 499], $orderedArray); + $this->assertEquals(['episode1', 'episode one', 'episode two', 'episode three', 'episode 5', 'episode eleven', 'episode50', 'episode two hundred', + 499, ], $orderedArray); $orderedArray = $this->numberedStringOrder->sort([ 'حلقة 30', @@ -85,8 +82,7 @@ public function readme_examples() ]); $this->assertEquals( - ["حلقة واحد جديدة","حلقه الأولى جديدة","حلقتنا اليوم 1","حلقه 2 جديدة", "حلقة الثانية جديدة","حلقة ثلاثة جديدة",4,"episode 24","حلقة 30","حلقة33", "حلقة3٤", "حلقة ٥٥ ", "حلقة الاخيرة"] - , $orderedArray); + ['حلقة واحد جديدة', 'حلقه الأولى جديدة', 'حلقتنا اليوم 1', 'حلقه 2 جديدة', 'حلقة الثانية جديدة', 'حلقة ثلاثة جديدة', 4, 'episode 24', 'حلقة 30', 'حلقة33', 'حلقة3٤', 'حلقة ٥٥ ', 'حلقة الاخيرة'], $orderedArray); } /** @test */ @@ -145,7 +141,6 @@ public function it_sort_arabic_words_well() $this->assertEquals('١', $orderedArray[0]); } - /** @test */ public function arabic_words() { @@ -168,16 +163,16 @@ public function arabic_words() $expected = [ - 0 => '١', - 1 => '٢ ', - 2 => ' 24', - 3 => '١٠٠', - 4 => '١٠ ألاف', - 5 => '٥٥ ألف', - 6 => '٣ ملايين', - 7 => '١٠ ملايين و5 ألاف', - 8 => '١٠ ملايين وتسع مئة ألف', - 9 => '١٠ ملايين وتسع مئة ألف وخمس مئة', + 0 => '١', + 1 => '٢ ', + 2 => ' 24', + 3 => '١٠٠', + 4 => '١٠ ألاف', + 5 => '٥٥ ألف', + 6 => '٣ ملايين', + 7 => '١٠ ملايين و5 ألاف', + 8 => '١٠ ملايين وتسع مئة ألف', + 9 => '١٠ ملايين وتسع مئة ألف وخمس مئة', 10 => '٣٠ مليون', 11 => '4 مليارات', 12 => '30 مليار',