Test Failed
Push — master ( 2a2655...121a4e )
by Fabio
07:39
created

TUtf8Converter::fromUTF8()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 8
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * TUtf8Converter class file
4
 *
5
 * @author Fabio Bas <[email protected]>
6
 * @link https://github.com/pradosoft/prado
7
 * @copyright Copyright &copy; 2005-2016 The PRADO Group
8
 * @license https://github.com/pradosoft/prado/blob/master/LICENSE
9
 * @package Prado\Util
10
 */
11
12
namespace Prado\Util;
13
14
/**
15
 * TUtf8Converter class.
16
 *
17
 * TUtf8Converter is a simple wrapper around iconv functions to convert
18
 * strings from and to UTF-8.
19
 *
20
 * @author Fabio Bas <[email protected]>
21
 * @package Prado\Util
22
 * @since 4.0.2
23
 */
24
class TUtf8Converter
25
{
26
27
	/**
28
	 * Convert strings to UTF-8 via iconv. NB, the result may not by UTF-8
29
	 * if the conversion failed.
30
	 * @param string $string string to convert to UTF-8
31
	 * @param string $from source encoding
32
	 * @return string UTF-8 encoded string, original string if iconv failed.
33
	 */
34 View Code Duplication
	public static function toUTF8($string, $from)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
	{
36
		if ($from != 'UTF-8') {
37
			$s = iconv($from, 'UTF-8', $string); //to UTF-8
38
			return $s !== false ? $s : $string; //it could return false
39
		}
40
		return $string;
41
	}
42
43
	/**
44
	 * Convert UTF-8 strings to a different encoding. NB. The result
45
	 * may not have been encoded if iconv fails.
46
	 * @param string $string the UTF-8 string for conversion
47
	 * @param string $to destination encoding
48
	 * @return string encoded string.
49
	 */
50 View Code Duplication
	public static function fromUTF8($string, $to)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
	{
52
		if ($to != 'UTF-8') {
53
			$s = iconv('UTF-8', $to, $string);
54
			return $s !== false ? $s : $string;
55
		}
56
		return $string;
57
	}
58
}
59