Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Lines changed: 7 additions & 3 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /