diff --git a/.github/workflows/code-style.yml b/.github/workflows/code-style.yml index effa430..735e565 100644 --- a/.github/workflows/code-style.yml +++ b/.github/workflows/code-style.yml @@ -6,7 +6,7 @@ on: jobs: phpcs: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index d77535e..8ec4b0e 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -6,7 +6,7 @@ on: jobs: phpstan: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dd48122..402c149 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,7 @@ on: jobs: phpunit: name: phpunit - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: matrix: php-version: diff --git a/lib/Inflections.php b/lib/Inflections.php index 2c15adc..28e75ed 100644 --- a/lib/Inflections.php +++ b/lib/Inflections.php @@ -178,7 +178,7 @@ public function __get(string $property) */ public function acronym(string $acronym): self { - $this->acronyms[downcase($acronym)] = $acronym; + $this->acronyms[StaticInflector::downcase($acronym)] = $acronym; $this->acronym_regex = '/' . implode('|', $this->acronyms) . '/'; return $this; @@ -252,11 +252,11 @@ public function irregular(string $singular, string $plural): self unset($this->uncountables[$plural]); $s0 = mb_substr($singular, 0, 1); - $s0_upcase = upcase($s0); + $s0_upcase = StaticInflector::upcase($s0); $srest = mb_substr($singular, 1); $p0 = mb_substr($plural, 0, 1); - $p0_upcase = upcase($p0); + $p0_upcase = StaticInflector::upcase($p0); $prest = mb_substr($plural, 1); if ($s0_upcase == $p0_upcase) { @@ -266,8 +266,8 @@ public function irregular(string $singular, string $plural): self $this->singular("/({$s0}){$srest}$/i", '\1' . $srest); $this->singular("/({$p0}){$prest}$/i", '\1' . $srest); } else { - $s0_downcase = downcase($s0); - $p0_downcase = downcase($p0); + $s0_downcase = StaticInflector::downcase($s0); + $p0_downcase = StaticInflector::downcase($p0); $this->plural("/{$s0_upcase}(?i){$srest}$/", $p0_upcase . $prest); $this->plural("/{$s0_downcase}(?i){$srest}$/", $p0_downcase . $prest); diff --git a/lib/Inflector.php b/lib/Inflector.php index e3b963e..22d5d21 100644 --- a/lib/Inflector.php +++ b/lib/Inflector.php @@ -116,7 +116,7 @@ private function apply_inflections(string $word, array $rules): string return $rc; } - if (preg_match('/\b[[:word:]]+\Z/u', downcase($rc), $matches)) { + if (preg_match('/\b[[:word:]]+\Z/u', StaticInflector::downcase($rc), $matches)) { if (isset($this->inflections->uncountables[$matches[0]])) { return $rc; } @@ -203,7 +203,7 @@ public function camelize(string $term, bool $downcase_first_letter = self::UPCAS . trim($this->inflections->acronym_regex, '/') . '(?=\b|[[:upper:]_])|\w)/u', function (array $matches): string { - return downcase($matches[0]); + return StaticInflector::downcase($matches[0]); }, $string, 1 @@ -214,7 +214,7 @@ function (array $matches): string { function (array $matches) use ($acronyms): string { $m = $matches[0]; - return !empty($acronyms[$m]) ? $acronyms[$m] : capitalize($m, true); + return !empty($acronyms[$m]) ? $acronyms[$m] : StaticInflector::capitalize($m, true); }, $string, 1 @@ -228,7 +228,7 @@ function (array $matches) use ($acronyms): string { function (array $matches) use ($acronyms): string { [ , $m1, $m2 ] = $matches; - return $m1 . ($acronyms[$m2] ?? capitalize($m2, true)); + return $m1 . ($acronyms[$m2] ?? StaticInflector::capitalize($m2, true)); }, $string ); @@ -266,7 +266,7 @@ public function underscore(string $camel_cased_word): string function (array $matches): string { [ , $m1, $m2 ] = $matches; - return $m1 . ($m1 ? '_' : '') . downcase($m2); + return $m1 . ($m1 ? '_' : '') . StaticInflector::downcase($m2); }, $word ); @@ -279,7 +279,7 @@ function (array $matches): string { $word = preg_replace('/\-+|\s+/', '_', $word); // @phpstan-ignore-next-line - return downcase($word); + return StaticInflector::downcase($word); } /** @@ -315,7 +315,7 @@ public function humanize(string $lower_case_and_underscored_word): string function (array $matches) use ($acronyms): string { [ $m ] = $matches; - return !empty($acronyms[$m]) ? $acronyms[$m] : downcase($m); + return !empty($acronyms[$m]) ? $acronyms[$m] : StaticInflector::downcase($m); }, $result ); @@ -324,7 +324,7 @@ function (array $matches) use ($acronyms): string { // @phpstan-ignore-next-line return preg_replace_callback('/^[[:lower:]]/u', function (array $matches): string { - return upcase($matches[0]); + return StaticInflector::upcase($matches[0]); }, $result); } @@ -347,7 +347,7 @@ public function titleize(string $str): string // @phpstan-ignore-next-line return preg_replace_callback('/\b(?inflections->uncountables[$matches[0]]); } } diff --git a/lib/StaticInflector.php b/lib/StaticInflector.php index 67780a6..3b2052e 100644 --- a/lib/StaticInflector.php +++ b/lib/StaticInflector.php @@ -34,10 +34,10 @@ public static function capitalize(string $str, bool $preserve_str_end = false): $end = mb_substr($str, 1); if (!$preserve_str_end) { - $end = downcase($end); + $end = self::downcase($end); } - return upcase(mb_substr($str, 0, 1)) . $end; + return self::upcase(mb_substr($str, 0, 1)) . $end; } /**