diff --git a/CHANGELOG.md b/CHANGELOG.md index c33248e..45e2bb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/UPGRADE.md b/UPGRADE.md index e7cb567..42dc833 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -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. diff --git a/src/Inflector.php b/src/Inflector.php index f9543be..289d468 100644 --- a/src/Inflector.php +++ b/src/Inflector.php @@ -613,11 +613,11 @@ public function toCamelCase(string $input): string * 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`. diff --git a/tests/InflectorTest.php b/tests/InflectorTest.php index 9b0cb8c..dbf87f7 100644 --- a/tests/InflectorTest.php +++ b/tests/InflectorTest.php @@ -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'], ]; }