Skip to content

Commit d592891

Browse files
committed
up: update some for data and stream helper
1 parent c3a38a2 commit d592891

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/Helper/DataHelper.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
namespace Toolkit\Stdlib\Helper;
1111

12+
use Toolkit\Stdlib\Json;
1213
use function filter_var;
1314
use function gettype;
1415
use function is_array;
1516
use function is_bool;
1617
use function is_object;
1718
use function is_scalar;
1819
use function is_string;
19-
use function json_encode;
2020
use function method_exists;
2121
use const FILTER_NULL_ON_FAILURE;
2222
use const FILTER_VALIDATE_BOOLEAN;
@@ -59,13 +59,17 @@ public static function toBool(mixed $val, bool $nullAsFalse = false): bool
5959

6060
/**
6161
* @param mixed $val
62+
* @param bool $simpleBool
6263
*
6364
* @return string
6465
*/
65-
public static function toString(mixed $val): string
66+
public static function toString(mixed $val, bool $simpleBool = false): string
6667
{
6768
if (is_scalar($val)) {
6869
if (is_bool($val)) {
70+
if ($simpleBool) {
71+
return $val ? 'TRUE' : 'FALSE';
72+
}
6973
return $val ? 'bool(TRUE)' : 'bool(FALSE)';
7074
}
7175

@@ -78,7 +82,7 @@ public static function toString(mixed $val): string
7882
}
7983

8084
if (is_array($val)) {
81-
return json_encode($val);
85+
return Json::enc($val);
8286
}
8387

8488
if (is_object($val)) {

src/Util/Stream/MapStream.php

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function map(callable $mapper): static
4545

4646
/**
4747
* @param callable(mixed): mixed $func
48+
* @param array $map
4849
*
4950
* @return array<string, mixed>
5051
*/

test/Str/StringHelperTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ public function testIsBool(): void
3636
$this->assertFalse(Str::isBool('abc'));
3737
}
3838

39+
public function testIsVarName(): void
40+
{
41+
$this->assertTrue(Str::isVarName('true'));
42+
$this->assertTrue(Str::isVarName('abc'));
43+
$this->assertTrue(Str::isVarName('some_name'));
44+
$this->assertFalse(Str::isVarName('some-name'));
45+
$this->assertFalse(Str::isVarName('some_name()'));
46+
}
47+
3948
public function testToTyped(): void
4049
{
4150
$tests = [

0 commit comments

Comments
 (0)