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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- New #156: Add `NumericHelper::trimDecimalZeros()` (@samdark, @vjik)
- Enh #163: Explicitly import classes, functions, and constants in "use" sections (@vjik)
- Enh #167: Remove dead code in `StringHelper::truncateWordsByLength()` (@vjik)
- Enh #172: Optimize `StringHelper::startsWithIgnoringCase()` and `StringHelper::endsWithIgnoringCase()` (@vjik)

## 2.7.0 November 23, 2025

Expand Down
4 changes: 1 addition & 3 deletions src/Inflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,8 @@
*/
$result = preg_replace($regex, addslashes($separator) . '\1', $input);

if ($separator !== '_') {

Check warning on line 538 in src/Inflector.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "NotIdentical": @@ @@ * never returns `false`. */ $result = preg_replace($regex, addslashes($separator) . '\1', $input); - if ($separator !== '_') { + if ($separator === '_') { $result = str_replace('_', $separator, $result); } return mb_strtolower(trim($result, $separator));
$result = str_replace('_', $separator, $result);

Check warning on line 539 in src/Inflector.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "UnwrapStrReplace": @@ @@ */ $result = preg_replace($regex, addslashes($separator) . '\1', $input); if ($separator !== '_') { - $result = str_replace('_', $separator, $result); + $result = $result; } return mb_strtolower(trim($result, $separator)); }
}

return mb_strtolower(trim($result, $separator));
Expand Down Expand Up @@ -602,7 +602,7 @@
{
$input = $this->toPascalCase($input);

return mb_strtolower(mb_substr($input, 0, 1)) . mb_substr($input, 1);

Check warning on line 605 in src/Inflector.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "MBString": @@ @@ public function toCamelCase(string $input): string { $input = $this->toPascalCase($input); - return mb_strtolower(mb_substr($input, 0, 1)) . mb_substr($input, 1); + return strtolower(mb_substr($input, 0, 1)) . mb_substr($input, 1); } /** * Returns given word as "snake_cased".
}

/**
Expand Down Expand Up @@ -668,7 +668,7 @@
*/
public function toSlug(string $input, string $replacement = '-', bool $lowercase = true): string
{
$quotedReplacement = preg_quote($replacement, '/');

Check warning on line 671 in src/Inflector.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "PregQuote": @@ @@ */ public function toSlug(string $input, string $replacement = '-', bool $lowercase = true): string { - $quotedReplacement = preg_quote($replacement, '/'); + $quotedReplacement = $replacement; /** * Replace all non-words character *

/**
* Replace all non-words character
Expand All @@ -685,7 +685,7 @@
* `preg_replace()` never returns `false`.
*/
$input = preg_replace(
"/^(?:$quotedReplacement)+|(?:$quotedReplacement)+$/u" . ($lowercase ? 'i' : ''),

Check warning on line 688 in src/Inflector.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ConcatOperandRemoval": @@ @@ * @var string $input We assume that `$input` and `$quotedReplacement` are valid UTF-8 strings, so * `preg_replace()` never returns `false`. */ - $input = preg_replace("/^(?:{$quotedReplacement})+|(?:{$quotedReplacement})+\$/u" . ($lowercase ? 'i' : ''), '', $input); + $input = preg_replace("/^(?:{$quotedReplacement})+|(?:{$quotedReplacement})+\$/u", '', $input); return $lowercase ? strtolower($input) : $input; } /**

Check warning on line 688 in src/Inflector.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "Ternary": @@ @@ * @var string $input We assume that `$input` and `$quotedReplacement` are valid UTF-8 strings, so * `preg_replace()` never returns `false`. */ - $input = preg_replace("/^(?:{$quotedReplacement})+|(?:{$quotedReplacement})+\$/u" . ($lowercase ? 'i' : ''), '', $input); + $input = preg_replace("/^(?:{$quotedReplacement})+|(?:{$quotedReplacement})+\$/u" . ($lowercase ? '' : 'i'), '', $input); return $lowercase ? strtolower($input) : $input; } /**
'',
$input,
);
Expand All @@ -710,9 +710,7 @@
public function toTransliterated(string $input, $transliterator = null): string
{
if ($this->useIntl()) {
if ($transliterator === null) {
$transliterator = $this->transliterator;
}
$transliterator ??= $this->transliterator;

/**
* @noinspection PhpComposerExtensionStubsInspection
Expand Down
26 changes: 9 additions & 17 deletions src/StringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,12 @@ public static function startsWith(string $input, ?string $with): bool
*/
public static function startsWithIgnoringCase(string $input, ?string $with): bool
{
$bytes = self::byteLength($with);

if ($bytes === 0) {
if ($with === null || $with === '') {
return true;
}

/** @psalm-suppress PossiblyNullArgument */
$bytes = self::byteLength($with);

return self::lowercase(self::substring($input, 0, $bytes, '8bit')) === self::lowercase($with);
}

Expand Down Expand Up @@ -248,13 +247,12 @@ public static function endsWith(string $input, ?string $with): bool
*/
public static function endsWithIgnoringCase(string $input, ?string $with): bool
{
$bytes = self::byteLength($with);

if ($bytes === 0) {
if ($with === null || $with === '') {
return true;
}

/** @psalm-suppress PossiblyNullArgument */
$bytes = self::byteLength($with);

return self::lowercase(mb_substr($input, -$bytes, mb_strlen($input, '8bit'), '8bit')) === self::lowercase($with);
}

Expand Down Expand Up @@ -718,9 +716,7 @@ public static function rtrim(string|array $string, string $pattern = self::DEFAU
*/
public static function findBetween(string $string, string $start, ?string $end = null): ?string
{
if ($end === null) {
$end = $start;
}
$end ??= $start;

$startPos = mb_strpos($string, $start);

Expand Down Expand Up @@ -750,9 +746,7 @@ public static function findBetween(string $string, string $start, ?string $end =
*/
public static function findBetweenFirst(string $string, string $start, ?string $end = null): ?string
{
if ($end === null) {
$end = $start;
}
$end ??= $start;

$startPos = mb_strpos($string, $start);

Expand Down Expand Up @@ -782,9 +776,7 @@ public static function findBetweenFirst(string $string, string $start, ?string $
*/
public static function findBetweenLast(string $string, string $start, ?string $end = null): ?string
{
if ($end === null) {
$end = $start;
}
$end ??= $start;

$endPos = mb_strrpos($string, $end);

Expand Down
Loading