Code Duplication    Length = 39-40 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

@@ 6398-6437 (lines=40) @@
6395
   *
6396
   * @return string str with all alphabetic characters converted to lowercase.
6397
   */
6398
  public static function strtolower($str, string $encoding = 'UTF-8', bool $cleanUtf8 = false, string $lang = null): string
6399
  {
6400
    // init
6401
    $str = (string)$str;
6402
    if (!isset($str[0])) {
6403
      return '';
6404
    }
6405
6406
    if ($cleanUtf8 === true) {
6407
      // "\mb_strpos" and "\iconv_strpos" returns wrong position,
6408
      // if invalid characters are found in $haystack before $needle
6409
      $str = self::clean($str);
6410
    }
6411
6412
    if ($encoding !== 'UTF-8' && $encoding !== 'CP850') {
6413
      $encoding = self::normalize_encoding($encoding, 'UTF-8');
6414
    }
6415
6416
    if ($lang !== null) {
6417
6418
      if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) {
6419
        self::checkForSupport();
6420
      }
6421
6422
      if (self::$SUPPORT['intl'] === true) {
6423
6424
        $langCode = $lang . '-Lower';
6425
        if (!\in_array($langCode, self::$SUPPORT['intl__transliterator_list_ids'], true)) {
6426
          \trigger_error('UTF8::strtolower() without intl for special language: ' . $lang, E_USER_WARNING);
6427
6428
          $langCode = 'Any-Lower';
6429
        }
6430
6431
        return transliterator_transliterate($langCode, $str);
6432
      }
6433
6434
      \trigger_error('UTF8::strtolower() without intl + PHP >= 5.4 cannot handle the "lang"-parameter: ' . $lang, E_USER_WARNING);
6435
    }
6436
6437
    return \mb_strtolower($str, $encoding);
6438
  }
6439
6440
  /**
@@ 6465-6503 (lines=39) @@
6462
   *
6463
   * @return string <p>$str with all alphabetic characters converted to uppercase.</p>
6464
   */
6465
  public static function strtoupper($str, string $encoding = 'UTF-8', bool $cleanUtf8 = false, string $lang = null): string
6466
  {
6467
    $str = (string)$str;
6468
    if (!isset($str[0])) {
6469
      return '';
6470
    }
6471
6472
    if ($cleanUtf8 === true) {
6473
      // "\mb_strpos" and "\iconv_strpos" returns wrong position,
6474
      // if invalid characters are found in $haystack before $needle
6475
      $str = self::clean($str);
6476
    }
6477
6478
    if ($encoding !== 'UTF-8' && $encoding !== 'CP850') {
6479
      $encoding = self::normalize_encoding($encoding, 'UTF-8');
6480
    }
6481
6482
    if ($lang !== null) {
6483
6484
      if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) {
6485
        self::checkForSupport();
6486
      }
6487
6488
      if (self::$SUPPORT['intl'] === true) {
6489
6490
        $langCode = $lang . '-Upper';
6491
        if (!\in_array($langCode, self::$SUPPORT['intl__transliterator_list_ids'], true)) {
6492
          \trigger_error('UTF8::strtoupper() without intl for special language: ' . $lang, E_USER_WARNING);
6493
6494
          $langCode = 'Any-Upper';
6495
        }
6496
6497
        return transliterator_transliterate($langCode, $str);
6498
      }
6499
6500
      \trigger_error('UTF8::strtolower() without intl + PHP >= 5.4 cannot handle the "lang"-parameter: ' . $lang, E_USER_WARNING);
6501
    }
6502
6503
    return \mb_strtoupper($str, $encoding);
6504
  }
6505
6506
  /**