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
        // PHP internally might use ISO-8859-1, so we have to tell the xml parser to give us back data in the expected charset.
265
        // What if internal encoding is not in one of the 3 allowed? We use the broadest one, ie. utf8

src/Encoder.php 1 location

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

src/Server.php 1 location

@@ 477-494 (lines=18) @@
474
    {
475
        // decompose incoming XML into request structure
476
477
        if ($reqEncoding != '') {
478
            // Since parsing will fail if charset is not specified in the xml prologue,
479
            // the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that...
480
            // The following code might be better for mb_string enabled installs, but
481
            // makes the lib about 200% slower...
482
            //if (!is_valid_charset($reqEncoding, array('UTF-8')))
483
            if (!in_array($reqEncoding, array('UTF-8', 'US-ASCII')) && !XMLParser::hasEncoding($data)) {
484
                if ($reqEncoding == 'ISO-8859-1') {
485
                    $data = utf8_encode($data);
486
                } else {
487
                    if (extension_loaded('mbstring')) {
488
                        $data = mb_convert_encoding($data, 'UTF-8', $reqEncoding);
489
                    } else {
490
                        error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $reqEncoding);
491
                    }
492
                }
493
            }
494
        }
495
496
        // PHP internally might use ISO-8859-1, so we have to tell the xml parser to give us back data in the expected charset.
497
        // What if internal encoding is not in one of the 3 allowed? We use the broadest one, ie. utf8