Code Duplication    Length = 18-18 lines in 3 locations

src/Encoder.php 1 location

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

src/Request.php 1 location

@@ 244-261 (lines=18) @@
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 makes the lib about 200% slower...
249
            //if (!is_valid_charset($respEncoding, array('UTF-8')))
250
            if (!in_array($respEncoding, array('UTF-8', 'US-ASCII')) && !XMLParser::hasEncoding($data)) {
251
                if ($respEncoding == 'ISO-8859-1') {
252
                    $data = utf8_encode($data);
253
                } else {
254
                    if (extension_loaded('mbstring')) {
255
                        $data = mb_convert_encoding($data, 'UTF-8', $respEncoding);
256
                    } else {
257
                        Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received response: ' . $respEncoding);
258
                    }
259
                }
260
            }
261
        }
262
263
        // PHP internally might use ISO-8859-1, so we have to tell the xml parser to give us back data in the expected charset.
264
        // What if internal encoding is not in one of the 3 allowed? We use the broadest one, ie. utf8

src/Server.php 1 location

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