Skip to content

Commit 7d8485f

Browse files
authored
Merge pull request #43 from donatj/fix/user-statics-internally
Replace internal calls to helpers with StaticInflector
2 parents c6fcdf4 + c6e5ea6 commit 7d8485f

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

lib/Inflections.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public function __get(string $property)
178178
*/
179179
public function acronym(string $acronym): self
180180
{
181-
$this->acronyms[downcase($acronym)] = $acronym;
181+
$this->acronyms[StaticInflector::downcase($acronym)] = $acronym;
182182
$this->acronym_regex = '/' . implode('|', $this->acronyms) . '/';
183183

184184
return $this;
@@ -252,11 +252,11 @@ public function irregular(string $singular, string $plural): self
252252
unset($this->uncountables[$plural]);
253253

254254
$s0 = mb_substr($singular, 0, 1);
255-
$s0_upcase = upcase($s0);
255+
$s0_upcase = StaticInflector::upcase($s0);
256256
$srest = mb_substr($singular, 1);
257257

258258
$p0 = mb_substr($plural, 0, 1);
259-
$p0_upcase = upcase($p0);
259+
$p0_upcase = StaticInflector::upcase($p0);
260260
$prest = mb_substr($plural, 1);
261261

262262
if ($s0_upcase == $p0_upcase) {
@@ -266,8 +266,8 @@ public function irregular(string $singular, string $plural): self
266266
$this->singular("/({$s0}){$srest}$/i", '\1' . $srest);
267267
$this->singular("/({$p0}){$prest}$/i", '\1' . $srest);
268268
} else {
269-
$s0_downcase = downcase($s0);
270-
$p0_downcase = downcase($p0);
269+
$s0_downcase = StaticInflector::downcase($s0);
270+
$p0_downcase = StaticInflector::downcase($p0);
271271

272272
$this->plural("/{$s0_upcase}(?i){$srest}$/", $p0_upcase . $prest);
273273
$this->plural("/{$s0_downcase}(?i){$srest}$/", $p0_downcase . $prest);

lib/Inflector.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private function apply_inflections(string $word, array $rules): string
116116
return $rc;
117117
}
118118

119-
if (preg_match('/\b[[:word:]]+\Z/u', downcase($rc), $matches)) {
119+
if (preg_match('/\b[[:word:]]+\Z/u', StaticInflector::downcase($rc), $matches)) {
120120
if (isset($this->inflections->uncountables[$matches[0]])) {
121121
return $rc;
122122
}
@@ -203,7 +203,7 @@ public function camelize(string $term, bool $downcase_first_letter = self::UPCAS
203203
. trim($this->inflections->acronym_regex, '/')
204204
. '(?=\b|[[:upper:]_])|\w)/u',
205205
function (array $matches): string {
206-
return downcase($matches[0]);
206+
return StaticInflector::downcase($matches[0]);
207207
},
208208
$string,
209209
1
@@ -214,7 +214,7 @@ function (array $matches): string {
214214
function (array $matches) use ($acronyms): string {
215215
$m = $matches[0];
216216

217-
return !empty($acronyms[$m]) ? $acronyms[$m] : capitalize($m, true);
217+
return !empty($acronyms[$m]) ? $acronyms[$m] : StaticInflector::capitalize($m, true);
218218
},
219219
$string,
220220
1
@@ -228,7 +228,7 @@ function (array $matches) use ($acronyms): string {
228228
function (array $matches) use ($acronyms): string {
229229
[ , $m1, $m2 ] = $matches;
230230

231-
return $m1 . ($acronyms[$m2] ?? capitalize($m2, true));
231+
return $m1 . ($acronyms[$m2] ?? StaticInflector::capitalize($m2, true));
232232
},
233233
$string
234234
);
@@ -266,7 +266,7 @@ public function underscore(string $camel_cased_word): string
266266
function (array $matches): string {
267267
[ , $m1, $m2 ] = $matches;
268268

269-
return $m1 . ($m1 ? '_' : '') . downcase($m2);
269+
return $m1 . ($m1 ? '_' : '') . StaticInflector::downcase($m2);
270270
},
271271
$word
272272
);
@@ -279,7 +279,7 @@ function (array $matches): string {
279279
$word = preg_replace('/\-+|\s+/', '_', $word);
280280

281281
// @phpstan-ignore-next-line
282-
return downcase($word);
282+
return StaticInflector::downcase($word);
283283
}
284284

285285
/**
@@ -315,7 +315,7 @@ public function humanize(string $lower_case_and_underscored_word): string
315315
function (array $matches) use ($acronyms): string {
316316
[ $m ] = $matches;
317317

318-
return !empty($acronyms[$m]) ? $acronyms[$m] : downcase($m);
318+
return !empty($acronyms[$m]) ? $acronyms[$m] : StaticInflector::downcase($m);
319319
},
320320
$result
321321
);
@@ -324,7 +324,7 @@ function (array $matches) use ($acronyms): string {
324324

325325
// @phpstan-ignore-next-line
326326
return preg_replace_callback('/^[[:lower:]]/u', function (array $matches): string {
327-
return upcase($matches[0]);
327+
return StaticInflector::upcase($matches[0]);
328328
}, $result);
329329
}
330330

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

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

@@ -438,7 +438,7 @@ public function is_uncountable(string $word): bool
438438
$rc = $word;
439439

440440
return $rc
441-
&& preg_match('/\b[[:word:]]+\Z/u', downcase($rc), $matches)
441+
&& preg_match('/\b[[:word:]]+\Z/u', StaticInflector::downcase($rc), $matches)
442442
&& isset($this->inflections->uncountables[$matches[0]]);
443443
}
444444
}

lib/StaticInflector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ public static function capitalize(string $str, bool $preserve_str_end = false):
3434
$end = mb_substr($str, 1);
3535

3636
if (!$preserve_str_end) {
37-
$end = downcase($end);
37+
$end = self::downcase($end);
3838
}
3939

40-
return upcase(mb_substr($str, 0, 1)) . $end;
40+
return self::upcase(mb_substr($str, 0, 1)) . $end;
4141
}
4242

4343
/**

0 commit comments

Comments
 (0)