Skip to content
Open
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Yii Strings Change Log

## 2.7.1 under development
## 3.0.0 under development

- Chg #165: Change default value of `$strict` parameter in `Inflector::toSnakeCase()` to `false` (@vjik)
- New #156: Add `NumericHelper::trimDecimalZeros()` (@samdark, @vjik)
- Enh #163: Explicitly import classes, functions, and constants in "use" sections (@vjik)

Expand Down
13 changes: 12 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@ application when you upgrade the package from one version to another.
> to upgrade from version A to version C and there is version B between A and C, you need
> to following the instructions for both A and B.

## Upgrade from 1.2.0
## Upgrade from 2.x to 3.x

Default value of `$strict` parameter in `Inflector::toSnakeCase()` changed to `false`. To keep previous behaviour add
`strict: true` to call methods `Inflector::toSnakeCase()` without `strict` argument. For example:

```php
Inflector::toSnakeCase($name);
// change to
Inflector::toSnakeCase($name, true);
```

## Upgrade from 1.x to 2.x

`\Yiisoft\Strings\WildCardPattern` was changed.

Expand Down
4 changes: 2 additions & 2 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 All @@ -613,11 +613,11 @@
* so "who's online" will be converted to "who_s_online".
*
* @param string $input The word to convert. It must be valid UTF-8 string.
* @param bool $strict Whether to insert a separator between two consecutive uppercase chars, defaults to true.
* @param bool $strict Whether to insert a separator between two consecutive uppercase chars, defaults to false.
*
* @return string The "snake_cased" string.
*/
public function toSnakeCase(string $input, bool $strict = true): string
public function toSnakeCase(string $input, bool $strict = false): string
{
/**
* @var string $input We assume that `$input` is valid UTF-8 string, so `preg_replace()` never returns `false`.
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 Down
10 changes: 5 additions & 5 deletions tests/InflectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ public static function dataToSnakeCase(): array
{
return [
[['input' => 'userName'], 'user_name'],
[['input' => 'travelSGuide'], 'travel_s_guide'],
[['input' => 'travelSGuide', 'strict' => true], 'travel_s_guide'],
[['input' => 'ひらがなHepimiz'], 'ひらがな_hepimiz'],
[['input' => 'Let\'s say "Hello, World!" yii 3 😂'], 'let_s_say_hello_world_yii_3'],
[['input' => 'HTML'], 'h_t_m_l'],
[['input' => 'createMyDTO'], 'create_my_d_t_o'],
[['input' => 'HTML', 'strict' => false], 'html'],
[['input' => 'createMyDTO', 'strict' => false], 'create_my_dto'],
[['input' => 'HTML', 'strict' => true], 'h_t_m_l'],
[['input' => 'createMyDTO', 'strict' => true], 'create_my_d_t_o'],
[['input' => 'HTML'], 'html'],
[['input' => 'createMyDTO'], 'create_my_dto'],
];
}

Expand Down
Loading