Code Duplication    Length = 18-19 lines in 3 locations

src/Request.php 1 location

@@ 244-262 (lines=19) @@
241
            return $r;
242
        }
243
244
        if ($respEncoding != '') {
245
246
            // Since parsing will fail if charset is not specified in the xml prologue,
247
            // the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that...
248
            // The following code might be better for mb_string enabled installs, but
249
            // makes the lib about 200% slower...
250
            //if (!is_valid_charset($respEncoding, array('UTF-8')))
251
            if (!in_array($respEncoding, array('UTF-8', 'US-ASCII')) && !XMLParser::hasEncoding($data)) {
252
                if ($respEncoding == 'ISO-8859-1') {
253
                    $data = utf8_encode($data);
254
                } else {
255
                    if (extension_loaded('mbstring')) {
256
                        $data = mb_convert_encoding($data, 'UTF-8', $respEncoding);
257
                    } else {
258
                        error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received response: ' . $respEncoding);
259
                    }
260
                }
261
            }
262
        }
263
264
        $parser = xml_parser_create();
265
        xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);

src/Encoder.php 1 location

@@ 238-256 (lines=19) @@
235
    {
236
        // 'guestimate' encoding
237
        $valEncoding = XMLParser::guessEncoding('', $xmlVal);
238
        if ($valEncoding != '') {
239
240
            // Since parsing will fail if charset is not specified in the xml prologue,
241
            // the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that...
242
            // The following code might be better for mb_string enabled installs, but
243
            // makes the lib about 200% slower...
244
            //if (!is_valid_charset($valEncoding, array('UTF-8'))
245
            if (!in_array($valEncoding, array('UTF-8', 'US-ASCII')) && !XMLParser::hasEncoding($xmlVal)) {
246
                if ($valEncoding == 'ISO-8859-1') {
247
                    $xmlVal = utf8_encode($xmlVal);
248
                } else {
249
                    if (extension_loaded('mbstring')) {
250
                        $xmlVal = mb_convert_encoding($xmlVal, 'UTF-8', $valEncoding);
251
                    } else {
252
                        error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of xml text: ' . $valEncoding);
253
                    }
254
                }
255
            }
256
        }
257
258
        $parser = xml_parser_create();
259
        xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);

src/Server.php 1 location

@@ 474-491 (lines=18) @@
471
    {
472
        // decompose incoming XML into request structure
473
474
        if ($reqEncoding != '') {
475
            // Since parsing will fail if charset is not specified in the xml prologue,
476
            // the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that...
477
            // The following code might be better for mb_string enabled installs, but
478
            // makes the lib about 200% slower...
479
            //if (!is_valid_charset($reqEncoding, array('UTF-8')))
480
            if (!in_array($reqEncoding, array('UTF-8', 'US-ASCII')) && !XMLParser::hasEncoding($data)) {
481
                if ($reqEncoding == 'ISO-8859-1') {
482
                    $data = utf8_encode($data);
483
                } else {
484
                    if (extension_loaded('mbstring')) {
485
                        $data = mb_convert_encoding($data, 'UTF-8', $reqEncoding);
486
                    } else {
487
                        error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $reqEncoding);
488
                    }
489
                }
490
            }
491
        }
492
493
        $parser = xml_parser_create();
494
        xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);