Code Duplication    Length = 39-40 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

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