Code Duplication    Length = 39-40 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

@@ 5413-5452 (lines=40) @@
5410
   *
5411
   * @return string str with all alphabetic characters converted to lowercase.
5412
   */
5413
  public static function strtolower($str, string $encoding = 'UTF-8', bool $cleanUtf8 = false, string $lang = null): string
5414
  {
5415
    // init
5416
    $str = (string)$str;
5417
    if (!isset($str[0])) {
5418
      return '';
5419
    }
5420
5421
    if ($cleanUtf8 === true) {
5422
      // "\mb_strpos" and "\iconv_strpos" returns wrong position,
5423
      // if invalid characters are found in $haystack before $needle
5424
      $str = self::clean($str);
5425
    }
5426
5427
    if ($encoding !== 'UTF-8' && $encoding !== 'CP850') {
5428
      $encoding = self::normalize_encoding($encoding, 'UTF-8');
5429
    }
5430
5431
    if ($lang !== null) {
5432
      if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) {
5433
        self::checkForSupport();
5434
      }
5435
5436
      if (self::$SUPPORT['intl'] === true) {
5437
5438
        $langCode = $lang . '-Lower';
5439
        if (!\in_array($langCode, self::$SUPPORT['intl__transliterator_list_ids'], true)) {
5440
          \trigger_error('UTF8::strtolower() without intl for special language: ' . $lang, E_USER_WARNING);
5441
5442
          $langCode = 'Any-Lower';
5443
        }
5444
5445
        return transliterator_transliterate($langCode, $str);
5446
      }
5447
5448
      \trigger_error('UTF8::strtolower() without intl + PHP >= 5.4 cannot handle the "lang"-parameter: ' . $lang, E_USER_WARNING);
5449
    }
5450
5451
    return \mb_strtolower($str, $encoding);
5452
  }
5453
5454
  /**
5455
   * Generic case sensitive transformation for collation matching.
@@ 5479-5517 (lines=39) @@
5476
   *
5477
   * @return string <p>$str with all alphabetic characters converted to uppercase.</p>
5478
   */
5479
  public static function strtoupper($str, string $encoding = 'UTF-8', bool $cleanUtf8 = false, string $lang = null): string
5480
  {
5481
    $str = (string)$str;
5482
    if (!isset($str[0])) {
5483
      return '';
5484
    }
5485
5486
    if ($cleanUtf8 === true) {
5487
      // "\mb_strpos" and "\iconv_strpos" returns wrong position,
5488
      // if invalid characters are found in $haystack before $needle
5489
      $str = self::clean($str);
5490
    }
5491
5492
    if ($encoding !== 'UTF-8' && $encoding !== 'CP850') {
5493
      $encoding = self::normalize_encoding($encoding, 'UTF-8');
5494
    }
5495
5496
    if ($lang !== null) {
5497
      if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) {
5498
        self::checkForSupport();
5499
      }
5500
5501
      if (self::$SUPPORT['intl'] === true) {
5502
5503
        $langCode = $lang . '-Upper';
5504
        if (!\in_array($langCode, self::$SUPPORT['intl__transliterator_list_ids'], true)) {
5505
          \trigger_error('UTF8::strtoupper() without intl for special language: ' . $lang, E_USER_WARNING);
5506
5507
          $langCode = 'Any-Upper';
5508
        }
5509
5510
        return transliterator_transliterate($langCode, $str);
5511
      }
5512
5513
      \trigger_error('UTF8::strtolower() without intl + PHP >= 5.4 cannot handle the "lang"-parameter: ' . $lang, E_USER_WARNING);
5514
    }
5515
5516
    return \mb_strtoupper($str, $encoding);
5517
  }
5518
5519
  /**
5520
   * Translate characters or replace sub-strings.