Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/Inflections.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
20 changes: 10 additions & 10 deletions lib/Inflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
);
Expand Down Expand Up @@ -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
);
Expand All @@ -279,7 +279,7 @@ function (array $matches): string {
$word = preg_replace('/\-+|\s+/', '_', $word);

// @phpstan-ignore-next-line
return downcase($word);
return StaticInflector::downcase($word);
}

/**
Expand Down Expand Up @@ -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
);
Expand All @@ -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);
}

Expand All @@ -347,7 +347,7 @@ public function titleize(string $str): string

// @phpstan-ignore-next-line
return preg_replace_callback('/\b(?<![\'’`])[[:lower:]]/u', function (array $matches): string {
return upcase($matches[0]);
return StaticInflector::upcase($matches[0]);
}, $str);
}

Expand Down Expand Up @@ -438,7 +438,7 @@ public function is_uncountable(string $word): bool
$rc = $word;

return $rc
&& preg_match('/\b[[:word:]]+\Z/u', downcase($rc), $matches)
&& preg_match('/\b[[:word:]]+\Z/u', StaticInflector::downcase($rc), $matches)
&& isset($this->inflections->uncountables[$matches[0]]);
}
}
4 changes: 2 additions & 2 deletions lib/StaticInflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down