Code Duplication    Length = 39-40 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

@@ 5320-5359 (lines=40) @@
5317
   *
5318
   * @return string str with all alphabetic characters converted to lowercase.
5319
   */
5320
  public static function strtolower($str, string $encoding = 'UTF-8', bool $cleanUtf8 = false, string $lang = null): string
5321
  {
5322
    // init
5323
    $str = (string)$str;
5324
    if (!isset($str[0])) {
5325
      return '';
5326
    }
5327
5328
    if ($cleanUtf8 === true) {
5329
      // "\mb_strpos" and "\iconv_strpos" returns wrong position,
5330
      // if invalid characters are found in $haystack before $needle
5331
      $str = self::clean($str);
5332
    }
5333
5334
    if ($encoding !== 'UTF-8') {
5335
      $encoding = self::normalize_encoding($encoding, 'UTF-8');
5336
    }
5337
5338
    if ($lang !== null) {
5339
      if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) {
5340
        self::checkForSupport();
5341
      }
5342
5343
      if (self::$SUPPORT['intl'] === true) {
5344
5345
        $langCode = $lang . '-Lower';
5346
        if (!\in_array($langCode, self::$SUPPORT['intl__transliterator_list_ids'], true)) {
5347
          trigger_error('UTF8::strtolower() without intl for special language: ' . $lang, E_USER_WARNING);
5348
5349
          $langCode = 'Any-Lower';
5350
        }
5351
5352
        return transliterator_transliterate($langCode, $str);
5353
      }
5354
5355
      trigger_error('UTF8::strtolower() without intl + PHP >= 5.4 cannot handle the "lang"-parameter: ' . $lang, E_USER_WARNING);
5356
    }
5357
5358
    return \mb_strtolower($str, $encoding);
5359
  }
5360
5361
  /**
5362
   * Generic case sensitive transformation for collation matching.
@@ 5386-5424 (lines=39) @@
5383
   *
5384
   * @return string <p>$str with all alphabetic characters converted to uppercase.</p>
5385
   */
5386
  public static function strtoupper($str, string $encoding = 'UTF-8', bool $cleanUtf8 = false, string $lang = null): string
5387
  {
5388
    $str = (string)$str;
5389
    if (!isset($str[0])) {
5390
      return '';
5391
    }
5392
5393
    if ($cleanUtf8 === true) {
5394
      // "\mb_strpos" and "\iconv_strpos" returns wrong position,
5395
      // if invalid characters are found in $haystack before $needle
5396
      $str = self::clean($str);
5397
    }
5398
5399
    if ($encoding !== 'UTF-8') {
5400
      $encoding = self::normalize_encoding($encoding, 'UTF-8');
5401
    }
5402
5403
    if ($lang !== null) {
5404
      if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) {
5405
        self::checkForSupport();
5406
      }
5407
5408
      if (self::$SUPPORT['intl'] === true) {
5409
5410
        $langCode = $lang . '-Upper';
5411
        if (!\in_array($langCode, self::$SUPPORT['intl__transliterator_list_ids'], true)) {
5412
          trigger_error('UTF8::strtoupper() without intl for special language: ' . $lang, E_USER_WARNING);
5413
5414
          $langCode = 'Any-Upper';
5415
        }
5416
5417
        return transliterator_transliterate($langCode, $str);
5418
      }
5419
5420
      trigger_error('UTF8::strtolower() without intl + PHP >= 5.4 cannot handle the "lang"-parameter: ' . $lang, E_USER_WARNING);
5421
    }
5422
5423
    return \mb_strtoupper($str, $encoding);
5424
  }
5425
5426
  /**
5427
   * Translate characters or replace sub-strings.