Skip to content

Commit ec14da3

Browse files
authored
Attempt to remove yiisoft/strings (#480)
* Attempt to remove yiisoft/strings * Remove yiisoft/strings * remove unused code * styleci * mini fix * psalm fix
1 parent 179d3e8 commit ec14da3

4 files changed

Lines changed: 32 additions & 8 deletions

File tree

composer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
"ext-pdo": "*",
2727
"psr/log": "^2.0|^3.0",
2828
"yiisoft/arrays": "^2.0",
29-
"yiisoft/cache": "^2.0",
30-
"yiisoft/log": "^2.0",
31-
"yiisoft/strings": "^2.0"
29+
"yiisoft/cache": "^2.0"
3230
},
3331
"require-dev": {
3432
"maglnet/composer-require-checker": "^4.2",
@@ -41,7 +39,8 @@
4139
"yiisoft/cache-file": "^2.0",
4240
"yiisoft/di": "^1.0",
4341
"yiisoft/event-dispatcher": "^1.0",
44-
"yiisoft/json": "^1.0"
42+
"yiisoft/json": "^1.0",
43+
"yiisoft/log": "^2.0"
4544
},
4645
"autoload": {
4746
"psr-4": {

src/Helper/NumericHelper.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Yiisoft\Db\Helper;
6+
7+
final class NumericHelper
8+
{
9+
/**
10+
* Returns string representation of a number value without thousands separators and with dot as decimal separator.
11+
*
12+
* @param float|string $value
13+
*
14+
* @return string
15+
*/
16+
public static function normalizeFloat(float|string $value): string
17+
{
18+
if (is_float($value)) {
19+
$value = (string)$value;
20+
}
21+
22+
$value = str_replace([' ', ','], ['', '.'], $value);
23+
return preg_replace('/\.(?=.*\.)/', '', $value);
24+
}
25+
}

src/Schema/AbstractColumnSchema.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use PDO;
88
use Yiisoft\Db\Command\Param;
99
use Yiisoft\Db\Expression\ExpressionInterface;
10-
use Yiisoft\Strings\NumericHelper;
10+
use Yiisoft\Db\Helper\NumericHelper;
1111

1212
/**
1313
* The ColumnSchema class represents the metadata of a column in a database table. It provides information about the
@@ -278,7 +278,7 @@ protected function typecast(mixed $value): mixed
278278

279279
if (is_float($value)) {
280280
/* ensure type cast always has . as decimal separator in all locales */
281-
return NumericHelper::normalize((string) $value);
281+
return NumericHelper::normalizeFloat($value);
282282
}
283283

284284
if (is_bool($value)) {

src/Schema/AbstractColumnSchemaBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Yiisoft\Db\Schema;
66

77
use Yiisoft\Db\Expression\Expression;
8-
use Yiisoft\Strings\NumericHelper;
8+
use Yiisoft\Db\Helper\NumericHelper;
99

1010
use function gettype;
1111
use function strtr;
@@ -232,7 +232,7 @@ protected function buildDefaultString(): string
232232

233233
$string .= match (gettype($this->default)) {
234234
'object', 'integer' => (string)$this->default,
235-
'double' => NumericHelper::normalize((string)$this->default),
235+
'double' => NumericHelper::normalizeFloat((string)$this->default),
236236
'boolean' => $this->default ? 'TRUE' : 'FALSE',
237237
default => "'$this->default'",
238238
};

0 commit comments

Comments
 (0)