1 | <?php |
||
8 | class Conversion |
||
9 | { |
||
10 | |||
11 | /** |
||
12 | * Encodes UTF-8 characters to HTML entities |
||
13 | * |
||
14 | * @author Tom N Harris <[email protected]> |
||
15 | * @author <vpribish at shopping dot com> |
||
16 | * @link http://php.net/manual/en/function.utf8-decode.php |
||
17 | * |
||
18 | * @param string $str |
||
19 | * @param bool $all Encode non-utf8 char to HTML as well |
||
20 | * @return string |
||
21 | */ |
||
22 | public static function toHtml($str, $all = false) |
||
36 | |||
37 | /** |
||
38 | * Decodes HTML entities to UTF-8 characters |
||
39 | * |
||
40 | * Convert any &#..; entity to a codepoint, |
||
41 | * The entities flag defaults to only decoding numeric entities. |
||
42 | * Pass HTML_ENTITIES and named entities, including & < etc. |
||
43 | * are handled as well. Avoids the problem that would occur if you |
||
44 | * had to decode "&#38;&amp;#38;" |
||
45 | * |
||
46 | * unhtmlspecialchars(\dokuwiki\Utf8\Conversion::fromHtml($s)) -> "&&" |
||
47 | * \dokuwiki\Utf8\Conversion::fromHtml(unhtmlspecialchars($s)) -> "&&#38;" |
||
48 | * what it should be -> "&&#38;" |
||
49 | * |
||
50 | * @author Tom N Harris <[email protected]> |
||
51 | * |
||
52 | * @param string $str UTF-8 encoded string |
||
53 | * @param boolean $entities decode name entities in addtition to numeric ones |
||
54 | * @return string UTF-8 encoded string with numeric (and named) entities replaced. |
||
55 | */ |
||
56 | public static function fromHtml($str, $entities = false) |
||
72 | |||
73 | /** |
||
74 | * Decodes any HTML entity to it's correct UTF-8 char equivalent |
||
75 | * |
||
76 | * @param string $ent An entity |
||
77 | * @return string |
||
78 | */ |
||
79 | protected static function decodeAnyEntity($ent) |
||
104 | |||
105 | /** |
||
106 | * Decodes numeric HTML entities to their correct UTF-8 characters |
||
107 | * |
||
108 | * @param $ent string A numeric entity |
||
109 | * @return string|false |
||
110 | */ |
||
111 | protected static function decodeNumericEntity($ent) |
||
124 | |||
125 | /** |
||
126 | * UTF-8 to UTF-16BE conversion. |
||
127 | * |
||
128 | * Maybe really UCS-2 without mb_string due to utf8_to_unicode limits |
||
129 | * |
||
130 | * @param string $str |
||
131 | * @param bool $bom |
||
132 | * @return string |
||
133 | */ |
||
134 | public static function toUtf16be($str, $bom = false) |
||
147 | |||
148 | /** |
||
149 | * UTF-8 to UTF-16BE conversion. |
||
150 | * |
||
151 | * Maybe really UCS-2 without mb_string due to utf8_to_unicode limits |
||
152 | * |
||
153 | * @param string $str |
||
154 | * @return false|string |
||
155 | */ |
||
156 | public static function fromUtf16be($str) |
||
161 | |||
162 | } |
||
163 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.