diff --git a/reports/clover/coverage.xml b/reports/clover/coverage.xml index cfc4713..1908e5e 100644 --- a/reports/clover/coverage.xml +++ b/reports/clover/coverage.xml @@ -1,103 +1,111 @@ - - + + - + - - - - - - - - - + + + + + + + + + - - - + + + - + - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/reports/html/Converter/ASCIIConverter.php.html b/reports/html/Converter/ASCIIConverter.php.html index b1be5e0..971881d 100644 --- a/reports/html/Converter/ASCIIConverter.php.html +++ b/reports/html/Converter/ASCIIConverter.php.html @@ -43,24 +43,24 @@ - Total -
-
- 60.00% covered (warning) + Total +
+
+ 90.00% covered (success)
-
60.00%
-
6 / 10
-
-
- 0.00% covered (danger) +
90.00%
+
9 / 10
+
+
+ 50.00% covered (warning)
-
0.00%
-
0 / 2
- CRAP +
50.00%
+
1 / 2
+ CRAP
0.00% covered (danger) @@ -72,24 +72,24 @@ - ASCIIConverter -
-
- 60.00% covered (warning) + ASCIIConverter +
+
+ 90.00% covered (success)
-
60.00%
-
6 / 10
-
-
- 0.00% covered (danger) +
90.00%
+
9 / 10
+
+
+ 50.00% covered (warning)
-
0.00%
-
0 / 2
- 5.02 +
50.00%
+
1 / 2
+ 4.02
0.00% covered (danger) @@ -101,15 +101,15 @@ -  convert -
-
- 66.67% covered (warning) +  convert +
+
+ 88.89% covered (success)
-
66.67%
-
6 / 9
+
88.89%
+
8 / 9
0.00% covered (danger) @@ -118,30 +118,30 @@
0.00%
0 / 1
- 3.33 + 3.01 -  check -
-
- 0.00% covered (danger) +  check +
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
-
-
- 0.00% covered (danger) +
100.00%
+
1 / 1
+
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
- 2 - +
100.00%
+
1 / 1
+ 1 + @@ -166,17 +166,17 @@ 14     */ 15    public static function convert($keyword, $options) 16    { - 17        $transitionalProcessing = ConverterFactory::transitionalProcessing($keyword, $options); + 17        $transitionalProcessing = ConverterFactory::transitionalProcessing($keyword, $options); 18 19        // Convert domain to Punycode - 20        $punycode = idn_to_ascii( - 21            $keyword, - 22            $transitionalProcessing ? IDNA_NONTRANSITIONAL_TO_ASCII : IDNA_DEFAULT, - 23            INTL_IDNA_VARIANT_UTS46 - 24        ); + 20        $punycode = idn_to_ascii( + 21            $keyword, + 22            $transitionalProcessing ? IDNA_NONTRANSITIONAL_TO_ASCII : IDNA_DEFAULT, + 23            INTL_IDNA_VARIANT_UTS46 + 24        ); 25 - 26        if ($punycode !== false) { - 27            return $punycode; // If successful, return the Punycode representation + 26        if ($punycode !== false) { + 27            return $punycode; // If successful, return the Punycode representation 28        } 29        return $keyword; // If conversion fails, return the normalized keyword 30    } @@ -189,7 +189,7 @@ 37     */ 38    public static function check($keyword) 39    { - 40        return mb_ereg('^xn--', $keyword) !== false; // Check if keyword starts with "xn--" + 40        return mb_ereg('^xn--', $keyword) !== false; // Check if keyword starts with "xn--" 41    } 42} @@ -202,7 +202,7 @@

Legend

Covered by small (and larger) testsCovered by medium (and large) testsCovered by large tests (and tests of unknown size)Not coveredNot coverable

- Generated by php-code-coverage 10.1.14 using PHP 8.1.27 and PHPUnit 10.5.14 at Fri Mar 22 12:35:54 UTC 2024. + Generated by php-code-coverage 10.1.14 using PHP 8.1.27 and PHPUnit 10.5.14 at Mon Mar 25 10:17:46 UTC 2024.

diff --git a/reports/html/Converter/ConversionInterface.php.html b/reports/html/Converter/ConversionInterface.php.html index 31edc06..042e18c 100644 --- a/reports/html/Converter/ConversionInterface.php.html +++ b/reports/html/Converter/ConversionInterface.php.html @@ -81,7 +81,7 @@

Legend

Covered by small (and larger) testsCovered by medium (and large) testsCovered by large tests (and tests of unknown size)Not coveredNot coverable

- Generated by php-code-coverage 10.1.14 using PHP 8.1.27 and PHPUnit 10.5.14 at Fri Mar 22 12:35:54 UTC 2024. + Generated by php-code-coverage 10.1.14 using PHP 8.1.27 and PHPUnit 10.5.14 at Mon Mar 25 10:17:46 UTC 2024.

diff --git a/reports/html/Converter/UnicodeConverter.php.html b/reports/html/Converter/UnicodeConverter.php.html index 2f11101..620eacc 100644 --- a/reports/html/Converter/UnicodeConverter.php.html +++ b/reports/html/Converter/UnicodeConverter.php.html @@ -43,24 +43,24 @@ - Total -
-
- 35.71% covered (warning) + Total +
+
+ 93.33% covered (success)
-
35.71%
-
5 / 14
-
-
- 66.67% covered (warning) +
93.33%
+
14 / 15
+
+
+ 75.00% covered (success)
-
66.67%
-
2 / 3
- CRAP +
75.00%
+
3 / 4
+ CRAP
0.00% covered (danger) @@ -72,24 +72,24 @@ - UnicodeConverter -
-
- 35.71% covered (warning) + UnicodeConverter +
+
+ 93.33% covered (success)
-
35.71%
-
5 / 14
-
-
- 66.67% covered (warning) +
93.33%
+
14 / 15
+
+
+ 75.00% covered (success)
-
66.67%
-
2 / 3
- 11.64 +
75.00%
+
3 / 4
+ 6.01
0.00% covered (danger) @@ -101,15 +101,15 @@ -  convert -
-
- 0.00% covered (danger) +  convert +
+
+ 88.89% covered (success)
-
0.00%
-
0 / 9
+
88.89%
+
8 / 9
0.00% covered (danger) @@ -118,7 +118,7 @@
0.00%
0 / 1
- 12 + 3.01 @@ -145,7 +145,29 @@ -  decode +  containsUnicodeCharacters +
+
+ 100.00% covered (success) +
+
+ +
100.00%
+
1 / 1
+
+
+ 100.00% covered (success) +
+
+ +
100.00%
+
1 / 1
+ 1 + + + + +  decode
100.00% covered (success) @@ -188,15 +210,15 @@ 14     */ 15    public static function convert($keyword, $options) 16    { - 17        $transitionalProcessing = ConverterFactory::transitionalProcessing($keyword, $options); + 17        $transitionalProcessing = ConverterFactory::transitionalProcessing($keyword, $options); 18 - 19        $idn = idn_to_utf8( - 20            self::decode($keyword), - 21            $transitionalProcessing ? IDNA_NONTRANSITIONAL_TO_UNICODE : IDNA_DEFAULT, - 22            INTL_IDNA_VARIANT_UTS46 - 23        ); - 24        if ($idn !== false) { - 25            return $idn; // If successful, return the IDN representation + 19        $idn = idn_to_utf8( + 20            self::decode($keyword), + 21            $transitionalProcessing ? IDNA_NONTRANSITIONAL_TO_UNICODE : IDNA_DEFAULT, + 22            INTL_IDNA_VARIANT_UTS46 + 23        ); + 24        if ($idn !== false) { + 25            return $idn; // If successful, return the IDN representation 26        } 27        return $keyword; // If conversion fails, return the normalized keyword 28    } @@ -209,24 +231,39 @@ 35     */ 36    public static function check($keyword) 37    { - 38        return mb_ereg( - 39            '[^\x00-\x7F\x{FF00}-\x{FFFF}]|\\\\u[0-9A-Fa-f]{4}', - 40            $keyword - 41        ) !== false; // Check if keyword contains non-ASCII characters + 38        return mb_ereg( + 39            '[^\x00-\x7F\x{FF00}-\x{FFFF}]', + 40            $keyword + 41        ) !== false; // Check if keyword contains non-ASCII characters 42    } 43 44    /** - 45     * Convert Unicode escape sequences to their corresponding characters. + 45     * Check if a string contains Unicode characters represented by escape sequences. 46     * - 47     * @param string $unicodeString String with Unicode escape sequences - 48     * @return string Converted string with actual Unicode characters - 49     */ - 50    public static function decode($unicodeString) - 51    { - 52        // Decode Unicode escape sequences - 53        return mb_strtolower(json_decode('"' . $unicodeString . '"', true, 512, JSON_UNESCAPED_UNICODE)); - 54    } - 55} + 47     * Unicode characters can be represented in PHP strings using escape sequences like \uXXXX. + 48     * This function checks if the input string contains any Unicode characters. + 49     * + 50     * @param string $str The input string to check. + 51     * @return bool Returns true if the string contains Unicode characters, false otherwise. + 52     */ + 53    public static function containsUnicodeCharacters($str) + 54    { + 55        // Check for Unicode characters + 56        return preg_match('/[\x{0080}-\x{10FFFF}]/u', self::decode($str)) !== false; + 57    } + 58 + 59    /** + 60     * Convert Unicode escape sequences to their corresponding characters. + 61     * + 62     * @param string $unicodeString String with Unicode escape sequences + 63     * @return string Converted string with actual Unicode characters + 64     */ + 65    public static function decode($unicodeString) + 66    { + 67        // Decode Unicode escape sequences + 68        return mb_strtolower(json_decode('"' . $unicodeString . '"', true, 512, JSON_UNESCAPED_UNICODE)); + 69    } + 70} @@ -237,7 +274,7 @@

Legend

Covered by small (and larger) testsCovered by medium (and large) testsCovered by large tests (and tests of unknown size)Not coveredNot coverable

- Generated by php-code-coverage 10.1.14 using PHP 8.1.27 and PHPUnit 10.5.14 at Fri Mar 22 12:35:54 UTC 2024. + Generated by php-code-coverage 10.1.14 using PHP 8.1.27 and PHPUnit 10.5.14 at Mon Mar 25 10:17:46 UTC 2024.

diff --git a/reports/html/Converter/dashboard.html b/reports/html/Converter/dashboard.html index d8fc33f..fe84a2d 100644 --- a/reports/html/Converter/dashboard.html +++ b/reports/html/Converter/dashboard.html @@ -58,8 +58,6 @@

Insufficient Coverage

-
CNIC\IDNA\Converter\UnicodeConverter35% - CNIC\IDNA\Converter\ASCIIConverter60% @@ -76,8 +74,6 @@

Project Risks

- CNIC\IDNA\Converter\UnicodeConverter11 - CNIC\IDNA\Converter\ASCIIConverter5 @@ -115,9 +111,6 @@

Insufficient Coverage

- check0% - convert0% - convert66% @@ -134,8 +127,6 @@

Project Risks

- convert12 - convert3 @@ -145,7 +136,7 @@

Project Risks

@@ -164,7 +155,7 @@

Project Risks

.yAxis.tickFormat(d3.format('d')); d3.select('#classCoverageDistribution svg') - .datum(getCoverageDistributionData([0,0,0,0,1,0,0,1,0,0,0,0], "Class Coverage")) + .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,0,2,0], "Class Coverage")) .transition().duration(500).call(chart); nv.utils.windowResize(chart.update); @@ -182,7 +173,7 @@

Project Risks

.yAxis.tickFormat(d3.format('d')); d3.select('#methodCoverageDistribution svg') - .datum(getCoverageDistributionData([2,0,0,0,0,0,0,1,0,0,0,2], "Method Coverage")) + .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,2,0,4], "Method Coverage")) .transition().duration(500).call(chart); nv.utils.windowResize(chart.update); @@ -232,7 +223,7 @@

Project Risks

chart.yAxis.axisLabel('Cyclomatic Complexity'); d3.select('#classComplexity svg') - .datum(getComplexityData([[60,4,"CNIC\\IDNA\\Converter\\ASCIIConverter<\/a>"],[35.714285714285715,5,"CNIC\\IDNA\\Converter\\UnicodeConverter<\/a>"]], 'Class Complexity')) + .datum(getComplexityData([[90,4,"CNIC\\IDNA\\Converter\\ASCIIConverter<\/a>"],[93.33333333333333,6,"CNIC\\IDNA\\Converter\\UnicodeConverter<\/a>"]], 'Class Complexity')) .transition() .duration(500) .call(chart); @@ -256,7 +247,7 @@

Project Risks

chart.yAxis.axisLabel('Method Complexity'); d3.select('#methodComplexity svg') - .datum(getComplexityData([[66.66666666666666,3,"
CNIC\\IDNA\\Converter\\ASCIIConverter::convert<\/a>"],[0,1,"CNIC\\IDNA\\Converter\\ASCIIConverter::check<\/a>"],[0,3,"CNIC\\IDNA\\Converter\\UnicodeConverter::convert<\/a>"],[100,1,"CNIC\\IDNA\\Converter\\UnicodeConverter::check<\/a>"],[100,1,"CNIC\\IDNA\\Converter\\UnicodeConverter::decode<\/a>"]], 'Method Complexity')) + .datum(getComplexityData([[88.88888888888889,3,"CNIC\\IDNA\\Converter\\ASCIIConverter::convert<\/a>"],[100,1,"CNIC\\IDNA\\Converter\\ASCIIConverter::check<\/a>"],[88.88888888888889,3,"CNIC\\IDNA\\Converter\\UnicodeConverter::convert<\/a>"],[100,1,"CNIC\\IDNA\\Converter\\UnicodeConverter::check<\/a>"],[100,1,"CNIC\\IDNA\\Converter\\UnicodeConverter::containsUnicodeCharacters<\/a>"],[100,1,"CNIC\\IDNA\\Converter\\UnicodeConverter::decode<\/a>"]], 'Method Complexity')) .transition() .duration(500) .call(chart); diff --git a/reports/html/Converter/index.html b/reports/html/Converter/index.html index 1665c00..34c888d 100644 --- a/reports/html/Converter/index.html +++ b/reports/html/Converter/index.html @@ -43,23 +43,23 @@ - Total -
-
- 45.83% covered (warning) + Total +
+
+ 92.00% covered (success)
-
45.83%
-
11 / 24
+
92.00%
+
23 / 25
-
- 40.00% covered (warning) +
+ 66.67% covered (warning)
-
40.00%
-
2 / 5
+
66.67%
+
4 / 6
0.00% covered (danger) @@ -71,23 +71,23 @@ - ASCIIConverter.php -
-
- 60.00% covered (warning) + ASCIIConverter.php +
+
+ 90.00% covered (success)
-
60.00%
-
6 / 10
-
-
- 0.00% covered (danger) +
90.00%
+
9 / 10
+
+
+ 50.00% covered (warning)
-
0.00%
-
0 / 2
+
50.00%
+
1 / 2
0.00% covered (danger) @@ -112,23 +112,23 @@ - UnicodeConverter.php -
-
- 35.71% covered (warning) + UnicodeConverter.php +
+
+ 93.33% covered (success)
-
35.71%
-
5 / 14
-
-
- 66.67% covered (warning) +
93.33%
+
14 / 15
+
+
+ 75.00% covered (success)
-
66.67%
-
2 / 3
+
75.00%
+
3 / 4
0.00% covered (danger) @@ -152,7 +152,7 @@

Legend

High: 70% to 100%

- Generated by php-code-coverage 10.1.14 using PHP 8.1.27 and PHPUnit 10.5.14 at Fri Mar 22 12:35:54 UTC 2024. + Generated by php-code-coverage 10.1.14 using PHP 8.1.27 and PHPUnit 10.5.14 at Mon Mar 25 10:17:46 UTC 2024.

diff --git a/reports/html/Factory/ConverterFactory.php.html b/reports/html/Factory/ConverterFactory.php.html index c60d72e..9a63b31 100644 --- a/reports/html/Factory/ConverterFactory.php.html +++ b/reports/html/Factory/ConverterFactory.php.html @@ -43,24 +43,24 @@ - Total -
-
- 28.57% covered (danger) + Total +
+
+ 95.83% covered (success)
-
28.57%
-
12 / 42
-
-
- 0.00% covered (danger) +
95.83%
+
46 / 48
+
+
+ 60.00% covered (warning)
-
0.00%
-
0 / 5
- CRAP +
60.00%
+
3 / 5
+ CRAP
0.00% covered (danger) @@ -72,24 +72,24 @@ - ConverterFactory -
-
- 28.57% covered (danger) + ConverterFactory +
+
+ 95.83% covered (success)
-
28.57%
-
12 / 42
-
-
- 0.00% covered (danger) +
95.83%
+
46 / 48
+
+
+ 60.00% covered (warning)
-
0.00%
-
0 / 5
- 215.78 +
60.00%
+
3 / 5
+ 24
0.00% covered (danger) @@ -101,37 +101,37 @@ -  convert -
-
- 0.00% covered (danger) +  convert +
+
+ 100.00% covered (success)
-
0.00%
-
0 / 11
-
-
- 0.00% covered (danger) +
100.00%
+
7 / 7
+
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
- 20 - +
100.00%
+
1 / 1
+ 3 + -  toUnicode -
-
- 0.00% covered (danger) +  toUnicode +
+
+ 92.31% covered (success)
-
0.00%
-
0 / 10
+
92.31%
+
12 / 13
0.00% covered (danger) @@ -140,42 +140,42 @@
0.00%
0 / 1
- 42 + 6.02 -  toASCII +  toASCII
-
- 90.91% covered (success) +
+ 100.00% covered (success)
-
90.91%
-
10 / 11
-
-
- 0.00% covered (danger) +
100.00%
+
11 / 11
+
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
- 5.02 - +
100.00%
+
1 / 1
+ 5 + -  handleConversion -
-
- 0.00% covered (danger) +  handleConversion +
+
+ 92.86% covered (success)
-
0.00%
-
0 / 7
+
92.86%
+
13 / 14
0.00% covered (danger) @@ -184,30 +184,30 @@
0.00%
0 / 1
- 42 + 8.02 -  transitionalProcessing -
-
- 66.67% covered (warning) +  transitionalProcessing +
+
+ 100.00% covered (success)
-
66.67%
-
2 / 3
-
-
- 0.00% covered (danger) +
100.00%
+
3 / 3
+
+
+ 100.00% covered (success)
-
0.00%
-
0 / 1
- 2.15 - +
100.00%
+
1 / 1
+ 2 + @@ -231,128 +231,135 @@ 13     * @param string|array $keywords The domain string to convert. 14     * @param array $options Additional options for the conversion process. 15     * @return array Returns an associative array containing the converted domain in both IDN and Punycode formats. - 16     * @throws \InvalidArgumentException Throws an exception if the domain string is empty. - 17     */ - 18    public static function convert($keywords, $options = []) - 19    { - 20        if (empty($keywords)) { - 21            throw new \InvalidArgumentException('Input parameters are missing.'); - 22        } - 23 - 24        if (is_array($keywords)) { - 25            $translatedKeywords = []; - 26 - 27            foreach ($keywords as $idx => $keyword) { - 28                $translatedKeywords[$idx]["IDN"] = self::toUnicode($keyword, $options); - 29                $translatedKeywords[$idx]["PUNYCODE"] = self::toASCII($keyword, $options); - 30            } - 31 - 32            return $translatedKeywords; - 33        } - 34 - 35        $translatedKeyword["IDN"] = self::toUnicode($keywords, $options); - 36        $translatedKeyword["PUNYCODE"] = self::toASCII($keywords, $options); - 37 - 38        return $translatedKeyword; - 39    } - 40 - 41    /** - 42     * Convert a domain string to Unicode format. - 43     * - 44     * @param string $keyword The domain string to convert. - 45     * @param array $options Additional options for the conversion process. - 46     * @return string|false Returns the converted domain in Unicode format or false if the keyword is empty. - 47     */ - 48    public static function toUnicode($keyword, $options = []) - 49    { - 50        if (empty($keyword)) { - 51            return false; - 52        } - 53 - 54        if (mb_strpos($keyword, '.') === false) { - 55            return self::handleConversion($keyword, $options, 'toUnicode'); - 56        } else { - 57            $domainArray = explode(".", trim($keyword)); - 58            $options["domain"] = $keyword; - 59            foreach ($domainArray as &$tmpKeyword) { - 60                if (ASCIIConverter::check($tmpKeyword) || UnicodeConverter::check($tmpKeyword)) { - 61                    $tmpKeyword = UnicodeConverter::convert($tmpKeyword, $options); - 62                } - 63            } - 64 - 65            return implode(".", $domainArray); - 66        } - 67    } - 68 - 69    /** - 70     * Convert a domain string to Punycode format. - 71     * - 72     * @param string $keyword The domain string to convert. - 73     * @param array $options Additional options for the conversion process. - 74     * @return string|false Returns the converted domain in Punycode format or false if the keyword is empty. - 75     */ - 76    public static function toASCII($keyword, $options = []) - 77    { - 78        if (empty($keyword)) { - 79            return false; - 80        } - 81 - 82        if (mb_strpos($keyword, '.') === false) { - 83            return self::handleConversion($keyword, $options, 'toASCII'); - 84        } else { - 85            $domainArray = explode(".", trim($keyword)); - 86            $options["domain"] = $keyword; - 87            foreach ($domainArray as &$tmpKeyword) { - 88                $tmpKeyword = UnicodeConverter::decode($tmpKeyword); - 89                if (UnicodeConverter::check($tmpKeyword)) { - 90                    $tmpKeyword = ASCIIConverter::convert($tmpKeyword, $options); - 91                } - 92            } - 93 - 94            return implode(".", $domainArray); - 95        } - 96    } - 97 - 98    /** - 99     * Handle conversion of a keyword between Unicode and Punycode formats. - 100     * - 101     * @param string $keyword The domain string to convert. - 102     * @param array $options Additional options for the conversion process. - 103     * @param string $method The conversion method to use. - 104     * @return string Returns the converted domain string. - 105     */ - 106    private static function handleConversion($keyword, $options, $method) - 107    { - 108        if (!isset($options["retry"]) && UnicodeConverter::check($keyword)) { - 109            $tmpKeyword = UnicodeConverter::convert($keyword, $options); - 110            if (mb_strpos($tmpKeyword, '.') !== false) { - 111                return self::$method($tmpKeyword, array_merge($options, ["retry" => true])); - 112            } - 113        } - 114 - 115        if (ASCIIConverter::check($keyword) || UnicodeConverter::check($keyword)) { - 116            return UnicodeConverter::convert($keyword, $options); - 117        } - 118 - 119        return $keyword; - 120    } - 121 - 122    /** - 123     * Check if the provided top-level domain (TLD) is non-transitional. - 124     * - 125     * @param string $keyword The domain string to check. - 126     * @param array $options Additional options for the conversion process. - 127     * @return bool Returns true if the TLD is non-transitional, false otherwise. - 128     */ - 129    public static function transitionalProcessing($keyword, $options = []) - 130    { - 131        if (isset($options["transitionalProcessing"])) { - 132            return $options["transitionalProcessing"]; - 133        } - 134 - 135        return mb_ereg("\./(be|ca|de|fr|pm|re|swiss|tf|wf|yt)\.?$/i", $options["domain"] ?? $keyword) !== false; - 136    } - 137} + 16     */ + 17    public static function convert($keywords, $options = []) + 18    { + 19        if (!is_array($keywords)) { + 20            $keywords = [$keywords]; + 21        } + 22 + 23        $translatedKeywords = []; + 24 + 25        foreach ($keywords as $idx => $keyword) { + 26            $translatedKeywords[$idx]["IDN"] = self::toUnicode($keyword, $options); + 27            $translatedKeywords[$idx]["PUNYCODE"] = self::toASCII($keyword, $options); + 28        } + 29 + 30        return $translatedKeywords; + 31    } + 32 + 33    /** + 34     * Convert a domain string to Unicode format. + 35     * + 36     * @param string $keyword The domain string to convert. + 37     * @param array $options Additional options for the conversion process. + 38     * @return string|false Returns the converted domain in Unicode format or false if the keyword is empty. + 39     */ + 40    public static function toUnicode($keyword, $options = []) + 41    { + 42        if (empty($keyword)) { + 43            return false; + 44        } + 45 + 46        if (mb_strpos($keyword, '.') === false) { + 47            return self::handleConversion($keyword, $options, 'toUnicode'); + 48        } else { + 49            $domainArray = explode(".", trim($keyword)); + 50            $options["domain"] = $keyword; + 51 + 52            foreach ($domainArray as &$tmpKeyword) { + 53                if (ASCIIConverter::check($tmpKeyword)) { + 54                    $tmpKeyword = UnicodeConverter::convert($tmpKeyword, $options); + 55                } + 56                if (UnicodeConverter::containsUnicodeCharacters($tmpKeyword)) { + 57                    $tmpKeyword = UnicodeConverter::decode($tmpKeyword); + 58                    $tmpKeyword = UnicodeConverter::convert($tmpKeyword, $options); + 59                } + 60            } + 61 + 62            return implode(".", $domainArray); + 63        } + 64    } + 65 + 66    /** + 67     * Convert a domain string to Punycode format. + 68     * + 69     * @param string $keyword The domain string to convert. + 70     * @param array $options Additional options for the conversion process. + 71     * @return string|false Returns the converted domain in Punycode format or false if the keyword is empty. + 72     */ + 73    public static function toASCII($keyword, $options = []) + 74    { + 75        if (empty($keyword)) { + 76            return false; + 77        } + 78 + 79        if (mb_strpos($keyword, '.') === false) { + 80            return self::handleConversion($keyword, $options, 'toASCII'); + 81        } else { + 82            $domainArray = explode(".", trim($keyword)); + 83            $options["domain"] = $keyword; + 84            foreach ($domainArray as &$tmpKeyword) { + 85                $tmpKeyword = UnicodeConverter::decode($tmpKeyword); + 86                if (UnicodeConverter::check($tmpKeyword)) { + 87                    $tmpKeyword = ASCIIConverter::convert($tmpKeyword, $options); + 88                } + 89            } + 90 + 91            return implode(".", $domainArray); + 92        } + 93    } + 94 + 95    /** + 96     * Handle conversion of a keyword between Unicode and Punycode formats. + 97     * + 98     * @param string $keyword The domain string to convert. + 99     * @param array $options Additional options for the conversion process. + 100     * @param string $method The conversion method to use. + 101     * @return string Returns the converted domain string. + 102     */ + 103    private static function handleConversion($keyword, $options, $method) + 104    { + 105        if (!isset($options["retry"]) && UnicodeConverter::check($keyword)) { + 106            $tmpKeyword = UnicodeConverter::convert($keyword, $options); + 107            if (mb_strpos($tmpKeyword, '.') !== false) { + 108                return self::$method($tmpKeyword, array_merge($options, ["retry" => true])); + 109            } + 110        } + 111 + 112        $tmpKeyword = $keyword; + 113        if (UnicodeConverter::containsUnicodeCharacters($tmpKeyword)) { + 114            $tmpKeyword = UnicodeConverter::decode($tmpKeyword); + 115            $tmpKeyword = UnicodeConverter::convert($tmpKeyword, $options); + 116        } + 117        if ($method === "toASCII") { + 118            if (UnicodeConverter::check($tmpKeyword)) { + 119                $tmpKeyword = ASCIIConverter::convert($tmpKeyword, $options); + 120            } + 121        } else { + 122            if (ASCIIConverter::check($tmpKeyword)) { + 123                $tmpKeyword = UnicodeConverter::convert($tmpKeyword, $options); + 124            } + 125        } + 126        return $tmpKeyword; + 127    } + 128 + 129    /** + 130     * Check if the provided top-level domain (TLD) is non-transitional. + 131     * + 132     * @param string $keyword The domain string to check. + 133     * @param array $options Additional options for the conversion process. + 134     * @return bool Returns true if the TLD is non-transitional, false otherwise. + 135     */ + 136    public static function transitionalProcessing($keyword, $options = []) + 137    { + 138        if (isset($options["transitionalProcessing"])) { + 139            return $options["transitionalProcessing"]; + 140        } + 141 + 142        return mb_ereg("\./(be|ca|de|fr|pm|re|swiss|tf|wf|yt)\.?$/i", $options["domain"] ?? $keyword) !== false; + 143    } + 144} @@ -363,7 +370,7 @@

Legend

Covered by small (and larger) testsCovered by medium (and large) testsCovered by large tests (and tests of unknown size)Not coveredNot coverable

- Generated by php-code-coverage 10.1.14 using PHP 8.1.27 and PHPUnit 10.5.14 at Fri Mar 22 12:35:54 UTC 2024. + Generated by php-code-coverage 10.1.14 using PHP 8.1.27 and PHPUnit 10.5.14 at Mon Mar 25 10:17:46 UTC 2024.

diff --git a/reports/html/Factory/dashboard.html b/reports/html/Factory/dashboard.html index f2287eb..01325eb 100644 --- a/reports/html/Factory/dashboard.html +++ b/reports/html/Factory/dashboard.html @@ -58,7 +58,6 @@

Insufficient Coverage

-
CNIC\IDNA\Factory\ConverterFactory28% @@ -75,7 +74,6 @@

Project Risks

- CNIC\IDNA\Factory\ConverterFactory215 @@ -113,10 +111,6 @@

Insufficient Coverage

- convert0% - toUnicode0% - handleConversion0% - transitionalProcessing66% @@ -133,10 +127,6 @@

Project Risks

- toUnicode42 - handleConversion42 - convert20 - transitionalProcessing2 @@ -146,7 +136,7 @@

Project Risks

@@ -165,7 +155,7 @@

Project Risks

.yAxis.tickFormat(d3.format('d')); d3.select('#classCoverageDistribution svg') - .datum(getCoverageDistributionData([0,0,0,1,0,0,0,0,0,0,0,0], "Class Coverage")) + .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,0,1,0], "Class Coverage")) .transition().duration(500).call(chart); nv.utils.windowResize(chart.update); @@ -183,7 +173,7 @@

Project Risks

.yAxis.tickFormat(d3.format('d')); d3.select('#methodCoverageDistribution svg') - .datum(getCoverageDistributionData([3,0,0,0,0,0,0,1,0,0,1,0], "Method Coverage")) + .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,0,2,3], "Method Coverage")) .transition().duration(500).call(chart); nv.utils.windowResize(chart.update); @@ -233,7 +223,7 @@

Project Risks

chart.yAxis.axisLabel('Cyclomatic Complexity'); d3.select('#classComplexity svg') - .datum(getComplexityData([[28.57142857142857,23,"CNIC\\IDNA\\Factory\\ConverterFactory<\/a>"]], 'Class Complexity')) + .datum(getComplexityData([[95.83333333333334,24,"CNIC\\IDNA\\Factory\\ConverterFactory<\/a>"]], 'Class Complexity')) .transition() .duration(500) .call(chart); @@ -257,7 +247,7 @@

Project Risks

chart.yAxis.axisLabel('Method Complexity'); d3.select('#methodComplexity svg') - .datum(getComplexityData([[0,4,"
CNIC\\IDNA\\Factory\\ConverterFactory::convert<\/a>"],[0,6,"CNIC\\IDNA\\Factory\\ConverterFactory::toUnicode<\/a>"],[90.9090909090909,5,"CNIC\\IDNA\\Factory\\ConverterFactory::toASCII<\/a>"],[0,6,"CNIC\\IDNA\\Factory\\ConverterFactory::handleConversion<\/a>"],[66.66666666666666,2,"CNIC\\IDNA\\Factory\\ConverterFactory::transitionalProcessing<\/a>"]], 'Method Complexity')) + .datum(getComplexityData([[100,3,"CNIC\\IDNA\\Factory\\ConverterFactory::convert<\/a>"],[92.3076923076923,6,"CNIC\\IDNA\\Factory\\ConverterFactory::toUnicode<\/a>"],[100,5,"CNIC\\IDNA\\Factory\\ConverterFactory::toASCII<\/a>"],[92.85714285714286,8,"CNIC\\IDNA\\Factory\\ConverterFactory::handleConversion<\/a>"],[100,2,"CNIC\\IDNA\\Factory\\ConverterFactory::transitionalProcessing<\/a>"]], 'Method Complexity')) .transition() .duration(500) .call(chart); diff --git a/reports/html/Factory/index.html b/reports/html/Factory/index.html index 82035ad..1703298 100644 --- a/reports/html/Factory/index.html +++ b/reports/html/Factory/index.html @@ -43,23 +43,23 @@ - Total -
-
- 28.57% covered (danger) + Total +
+
+ 95.83% covered (success)
-
28.57%
-
12 / 42
-
-
- 0.00% covered (danger) +
95.83%
+
46 / 48
+
+
+ 60.00% covered (warning)
-
0.00%
-
0 / 5
+
60.00%
+
3 / 5
0.00% covered (danger) @@ -71,23 +71,23 @@ - ConverterFactory.php -
-
- 28.57% covered (danger) + ConverterFactory.php +
+
+ 95.83% covered (success)
-
28.57%
-
12 / 42
-
-
- 0.00% covered (danger) +
95.83%
+
46 / 48
+
+
+ 60.00% covered (warning)
-
0.00%
-
0 / 5
+
60.00%
+
3 / 5
0.00% covered (danger) @@ -111,7 +111,7 @@

Legend

High: 70% to 100%

- Generated by php-code-coverage 10.1.14 using PHP 8.1.27 and PHPUnit 10.5.14 at Fri Mar 22 12:35:54 UTC 2024. + Generated by php-code-coverage 10.1.14 using PHP 8.1.27 and PHPUnit 10.5.14 at Mon Mar 25 10:17:46 UTC 2024.

diff --git a/reports/html/dashboard.html b/reports/html/dashboard.html index 1dde0ce..6571a67 100644 --- a/reports/html/dashboard.html +++ b/reports/html/dashboard.html @@ -57,9 +57,6 @@

Insufficient Coverage

- CNIC\IDNA\Factory\ConverterFactory28% - CNIC\IDNA\Converter\UnicodeConverter35% - CNIC\IDNA\Converter\ASCIIConverter60% @@ -76,9 +73,6 @@

Project Risks

- CNIC\IDNA\Factory\ConverterFactory215 - CNIC\IDNA\Converter\UnicodeConverter11 - CNIC\IDNA\Converter\ASCIIConverter5 @@ -116,13 +110,6 @@

Insufficient Coverage

- check0% - convert0% - convert0% - toUnicode0% - handleConversion0% - convert66% - transitionalProcessing66% @@ -139,12 +126,6 @@

Project Risks

- toUnicode42 - handleConversion42 - convert20 - convert12 - convert3 - transitionalProcessing2 @@ -154,7 +135,7 @@

Project Risks

@@ -173,7 +154,7 @@

Project Risks

.yAxis.tickFormat(d3.format('d')); d3.select('#classCoverageDistribution svg') - .datum(getCoverageDistributionData([0,0,0,1,1,0,0,1,0,0,0,0], "Class Coverage")) + .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,0,3,0], "Class Coverage")) .transition().duration(500).call(chart); nv.utils.windowResize(chart.update); @@ -191,7 +172,7 @@

Project Risks

.yAxis.tickFormat(d3.format('d')); d3.select('#methodCoverageDistribution svg') - .datum(getCoverageDistributionData([5,0,0,0,0,0,0,2,0,0,1,2], "Method Coverage")) + .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,2,2,7], "Method Coverage")) .transition().duration(500).call(chart); nv.utils.windowResize(chart.update); @@ -241,7 +222,7 @@

Project Risks

chart.yAxis.axisLabel('Cyclomatic Complexity'); d3.select('#classComplexity svg') - .datum(getComplexityData([[60,4,"CNIC\\IDNA\\Converter\\ASCIIConverter<\/a>"],[35.714285714285715,5,"CNIC\\IDNA\\Converter\\UnicodeConverter<\/a>"],[28.57142857142857,23,"CNIC\\IDNA\\Factory\\ConverterFactory<\/a>"]], 'Class Complexity')) + .datum(getComplexityData([[90,4,"CNIC\\IDNA\\Converter\\ASCIIConverter<\/a>"],[93.33333333333333,6,"CNIC\\IDNA\\Converter\\UnicodeConverter<\/a>"],[95.83333333333334,24,"CNIC\\IDNA\\Factory\\ConverterFactory<\/a>"]], 'Class Complexity')) .transition() .duration(500) .call(chart); @@ -265,7 +246,7 @@

Project Risks

chart.yAxis.axisLabel('Method Complexity'); d3.select('#methodComplexity svg') - .datum(getComplexityData([[66.66666666666666,3,"
CNIC\\IDNA\\Converter\\ASCIIConverter::convert<\/a>"],[0,1,"CNIC\\IDNA\\Converter\\ASCIIConverter::check<\/a>"],[0,3,"CNIC\\IDNA\\Converter\\UnicodeConverter::convert<\/a>"],[100,1,"CNIC\\IDNA\\Converter\\UnicodeConverter::check<\/a>"],[100,1,"CNIC\\IDNA\\Converter\\UnicodeConverter::decode<\/a>"],[0,4,"CNIC\\IDNA\\Factory\\ConverterFactory::convert<\/a>"],[0,6,"CNIC\\IDNA\\Factory\\ConverterFactory::toUnicode<\/a>"],[90.9090909090909,5,"CNIC\\IDNA\\Factory\\ConverterFactory::toASCII<\/a>"],[0,6,"CNIC\\IDNA\\Factory\\ConverterFactory::handleConversion<\/a>"],[66.66666666666666,2,"CNIC\\IDNA\\Factory\\ConverterFactory::transitionalProcessing<\/a>"]], 'Method Complexity')) + .datum(getComplexityData([[88.88888888888889,3,"CNIC\\IDNA\\Converter\\ASCIIConverter::convert<\/a>"],[100,1,"CNIC\\IDNA\\Converter\\ASCIIConverter::check<\/a>"],[88.88888888888889,3,"CNIC\\IDNA\\Converter\\UnicodeConverter::convert<\/a>"],[100,1,"CNIC\\IDNA\\Converter\\UnicodeConverter::check<\/a>"],[100,1,"CNIC\\IDNA\\Converter\\UnicodeConverter::containsUnicodeCharacters<\/a>"],[100,1,"CNIC\\IDNA\\Converter\\UnicodeConverter::decode<\/a>"],[100,3,"CNIC\\IDNA\\Factory\\ConverterFactory::convert<\/a>"],[92.3076923076923,6,"CNIC\\IDNA\\Factory\\ConverterFactory::toUnicode<\/a>"],[100,5,"CNIC\\IDNA\\Factory\\ConverterFactory::toASCII<\/a>"],[92.85714285714286,8,"CNIC\\IDNA\\Factory\\ConverterFactory::handleConversion<\/a>"],[100,2,"CNIC\\IDNA\\Factory\\ConverterFactory::transitionalProcessing<\/a>"]], 'Method Complexity')) .transition() .duration(500) .call(chart); diff --git a/reports/html/index.html b/reports/html/index.html index d03f069..63203bf 100644 --- a/reports/html/index.html +++ b/reports/html/index.html @@ -42,23 +42,23 @@ - Total -
-
- 34.85% covered (danger) + Total +
+
+ 94.52% covered (success)
-
34.85%
-
23 / 66
-
-
- 20.00% covered (danger) +
94.52%
+
69 / 73
+
+
+ 63.64% covered (warning)
-
20.00%
-
2 / 10
+
63.64%
+
7 / 11
0.00% covered (danger) @@ -70,23 +70,23 @@ - Converter -
-
- 45.83% covered (warning) + Converter +
+
+ 92.00% covered (success)
-
45.83%
-
11 / 24
+
92.00%
+
23 / 25
-
- 40.00% covered (warning) +
+ 66.67% covered (warning)
-
40.00%
-
2 / 5
+
66.67%
+
4 / 6
0.00% covered (danger) @@ -98,23 +98,23 @@ - Factory -
-
- 28.57% covered (danger) + Factory +
+
+ 95.83% covered (success)
-
28.57%
-
12 / 42
-
-
- 0.00% covered (danger) +
95.83%
+
46 / 48
+
+
+ 60.00% covered (warning)
-
0.00%
-
0 / 5
+
60.00%
+
3 / 5
0.00% covered (danger) @@ -138,7 +138,7 @@

Legend

High: 70% to 100%

- Generated by php-code-coverage 10.1.14 using PHP 8.1.27 and PHPUnit 10.5.14 at Fri Mar 22 12:35:54 UTC 2024. + Generated by php-code-coverage 10.1.14 using PHP 8.1.27 and PHPUnit 10.5.14 at Mon Mar 25 10:17:46 UTC 2024.

diff --git a/reports/logging/logfile.xml b/reports/logging/logfile.xml index 899a040..b85bcb7 100644 --- a/reports/logging/logfile.xml +++ b/reports/logging/logfile.xml @@ -1,67 +1,15 @@ - - - - - CNIC\IDNA\Tests\IDNATranslatorTest::testConvert -Error: Call to undefined function CNIC\IDNA\Converter\idn_to_utf8() - -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/src/IDNA/Converter/UnicodeConverter.php:19 -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/src/IDNA/Factory/ConverterFactory.php:61 -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/src/IDNA/Factory/ConverterFactory.php:35 -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/tests/IDNATranslatorTest.php:111 - - - CNIC\IDNA\Tests\IDNATranslatorTest::testConvertBulk -Error: Call to undefined function CNIC\IDNA\Converter\idn_to_utf8() - -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/src/IDNA/Converter/UnicodeConverter.php:19 -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/src/IDNA/Factory/ConverterFactory.php:61 -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/src/IDNA/Factory/ConverterFactory.php:28 -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/tests/IDNATranslatorTest.php:139 - - - CNIC\IDNA\Tests\IDNATranslatorTest::testIdnToPunycodeConversion -Error: Call to undefined function CNIC\IDNA\Converter\idn_to_utf8() - -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/src/IDNA/Converter/UnicodeConverter.php:19 -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/src/IDNA/Factory/ConverterFactory.php:61 -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/src/IDNA/Factory/ConverterFactory.php:35 -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/tests/IDNATranslatorTest.php:156 - - - CNIC\IDNA\Tests\IDNATranslatorTest::testToASCII -Error: Call to undefined function CNIC\IDNA\Converter\idn_to_ascii() - -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/src/IDNA/Converter/ASCIIConverter.php:20 -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/src/IDNA/Factory/ConverterFactory.php:90 -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/tests/IDNATranslatorTest.php:166 - - - CNIC\IDNA\Tests\IDNATranslatorTest::testToASCIIWithTransitional -Error: Call to undefined function CNIC\IDNA\Converter\idn_to_ascii() - -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/src/IDNA/Converter/ASCIIConverter.php:20 -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/src/IDNA/Factory/ConverterFactory.php:90 -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/tests/IDNATranslatorTest.php:177 - - - CNIC\IDNA\Tests\IDNATranslatorTest::testToASCIIWithoutTransitional -Error: Call to undefined function CNIC\IDNA\Converter\idn_to_ascii() - -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/src/IDNA/Converter/ASCIIConverter.php:20 -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/src/IDNA/Factory/ConverterFactory.php:90 -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/tests/IDNATranslatorTest.php:197 - - - CNIC\IDNA\Tests\IDNATranslatorTest::testToUnicode -Error: Call to undefined function CNIC\IDNA\Converter\idn_to_utf8() - -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/src/IDNA/Converter/UnicodeConverter.php:19 -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/src/IDNA/Factory/ConverterFactory.php:61 -/home/asifnawaz/git/rtldev-middleware-php-idna-translator/tests/IDNATranslatorTest.php:219 - + + + + + + + + + + diff --git a/reports/logging/testdox.html b/reports/logging/testdox.html index 393747f..8428c4c 100644 --- a/reports/logging/testdox.html +++ b/reports/logging/testdox.html @@ -53,13 +53,13 @@

IDNATranslator (CNIC\IDNA\Tests\IDNATranslator)

    -
  • Convert
  • -
  • Convert bulk
  • -
  • Idn to punycode conversion
  • -
  • To a s c i i
  • -
  • To a s c i i with transitional
  • -
  • To a s c i i without transitional
  • -
  • To unicode
  • +
  • Convert
  • +
  • Convert bulk
  • +
  • Idn to punycode conversion
  • +
  • To a s c i i
  • +
  • To a s c i i with transitional
  • +
  • To a s c i i without transitional
  • +
  • To unicode
\ No newline at end of file diff --git a/reports/logging/testdox.txt b/reports/logging/testdox.txt index 2fca801..ff8fc95 100644 --- a/reports/logging/testdox.txt +++ b/reports/logging/testdox.txt @@ -1,9 +1,9 @@ IDNATranslator (CNIC\IDNA\Tests\IDNATranslator) - [ ] Convert - [ ] Convert bulk - [ ] Idn to punycode conversion - [ ] To a s c i i - [ ] To a s c i i with transitional - [ ] To a s c i i without transitional - [ ] To unicode + [x] Convert + [x] Convert bulk + [x] Idn to punycode conversion + [x] To a s c i i + [x] To a s c i i with transitional + [x] To a s c i i without transitional + [x] To unicode diff --git a/src/IDNA/Factory/ConverterFactory.php b/src/IDNA/Factory/ConverterFactory.php index 687de2e..0c023bd 100644 --- a/src/IDNA/Factory/ConverterFactory.php +++ b/src/IDNA/Factory/ConverterFactory.php @@ -13,29 +13,24 @@ class ConverterFactory * @param string|array $keywords The domain string to convert. * @param array $options Additional options for the conversion process. * @return array Returns an associative array containing the converted domain in both IDN and Punycode formats. - * @throws \InvalidArgumentException Throws an exception if the domain string is empty. */ public static function convert($keywords, $options = []) { - if (empty($keywords)) { - throw new \InvalidArgumentException('Input parameters are missing.'); + if (!is_array($keywords)) { + return [ + "idn" => self::toUnicode($keywords, $options), + "punycode" => self::toASCII($keywords, $options) + ]; } - if (is_array($keywords)) { - $translatedKeywords = []; + $translatedKeywords = []; - foreach ($keywords as $idx => $keyword) { - $translatedKeywords[$idx]["IDN"] = self::toUnicode($keyword, $options); - $translatedKeywords[$idx]["PUNYCODE"] = self::toASCII($keyword, $options); - } - - return $translatedKeywords; + foreach ($keywords as $idx => $keyword) { + $translatedKeywords[$idx]["idn"] = self::toUnicode($keyword, $options); + $translatedKeywords[$idx]["punycode"] = self::toASCII($keyword, $options); } - $translatedKeyword["IDN"] = self::toUnicode($keywords, $options); - $translatedKeyword["PUNYCODE"] = self::toASCII($keywords, $options); - - return $translatedKeyword; + return $translatedKeywords; } /** diff --git a/tests/IDNATranslatorTest.php b/tests/IDNATranslatorTest.php index 12f8759..9b88e4d 100644 --- a/tests/IDNATranslatorTest.php +++ b/tests/IDNATranslatorTest.php @@ -109,16 +109,16 @@ class IDNATranslatorTest extends TestCase public function testConvert() { $result = ConverterFactory::convert('münchen.de'); - $this->assertEquals(['IDN' => 'münchen.de', 'PUNYCODE' => 'xn--mnchen-3ya.de'], $result); + $this->assertEquals(['idn' => 'münchen.de', 'punycode' => 'xn--mnchen-3ya.de'], $result); $result = ConverterFactory::convert('xn--mnchen-3ya.de'); - $this->assertEquals(['IDN' => 'münchen.de', 'PUNYCODE' => 'xn--mnchen-3ya.de'], $result); + $this->assertEquals(['idn' => 'münchen.de', 'punycode' => 'xn--mnchen-3ya.de'], $result); $result = ConverterFactory::convert('🌐.ws'); - $this->assertEquals(['IDN' => '🌐.ws', 'PUNYCODE' => 'xn--wg8h.ws'], $result); + $this->assertEquals(['idn' => '🌐.ws', 'punycode' => 'xn--wg8h.ws'], $result); $result = ConverterFactory::convert('xn--wg8h.ws'); - $this->assertEquals(['IDN' => '🌐.ws', 'PUNYCODE' => 'xn--wg8h.ws'], $result); + $this->assertEquals(['idn' => '🌐.ws', 'punycode' => 'xn--wg8h.ws'], $result); } public function testConvertBulk() @@ -139,21 +139,21 @@ public function testConvertBulk() $convertedDomains = ConverterFactory::convert($domains); // Check if the converted domains have the correct values - $this->assertEquals(['IDN' => 'münchen.de', 'PUNYCODE' => 'xn--mnchen-3ya.de'], $convertedDomains[0]); - $this->assertEquals(['IDN' => 'münchen.de', 'PUNYCODE' => 'xn--mnchen-3ya.de'], $convertedDomains[1]); - $this->assertEquals(['IDN' => '🌐.ws', 'PUNYCODE' => 'xn--wg8h.ws'], $convertedDomains[2]); - $this->assertEquals(['IDN' => '🌐.ws', 'PUNYCODE' => 'xn--wg8h.ws'], $convertedDomains[3]); - $this->assertEquals(['IDN' => '😊.com', 'PUNYCODE' => 'xn--o28h.com'], $convertedDomains[4]); - $this->assertEquals(['IDN' => '😊.com', 'PUNYCODE' => 'xn--o28h.com'], $convertedDomains[5]); - $this->assertEquals(['IDN' => '🎉.net', 'PUNYCODE' => 'xn--dk8h.net'], $convertedDomains[6]); - $this->assertEquals(['IDN' => '🎉.net', 'PUNYCODE' => 'xn--dk8h.net'], $convertedDomains[7]); + $this->assertEquals(['idn' => 'münchen.de', 'punycode' => 'xn--mnchen-3ya.de'], $convertedDomains[0]); + $this->assertEquals(['idn' => 'münchen.de', 'punycode' => 'xn--mnchen-3ya.de'], $convertedDomains[1]); + $this->assertEquals(['idn' => '🌐.ws', 'punycode' => 'xn--wg8h.ws'], $convertedDomains[2]); + $this->assertEquals(['idn' => '🌐.ws', 'punycode' => 'xn--wg8h.ws'], $convertedDomains[3]); + $this->assertEquals(['idn' => '😊.com', 'punycode' => 'xn--o28h.com'], $convertedDomains[4]); + $this->assertEquals(['idn' => '😊.com', 'punycode' => 'xn--o28h.com'], $convertedDomains[5]); + $this->assertEquals(['idn' => '🎉.net', 'punycode' => 'xn--dk8h.net'], $convertedDomains[6]); + $this->assertEquals(['idn' => '🎉.net', 'punycode' => 'xn--dk8h.net'], $convertedDomains[7]); } // Test cases for conversion from IDN to Punycode - public function testIdnToPunycodeConversion() + public function testidnToPunycodeConversion() { foreach (self::$data['convert'] as $idn => $punycode) { - $this->assertEquals($punycode, ConverterFactory::convert($idn)['PUNYCODE']); + $this->assertEquals($punycode, ConverterFactory::convert($idn)['punycode']); } }