Skip to content

Commit

Permalink
Update ValueAs::arr to use parse_str
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed May 19, 2021
1 parent aa8fb5b commit 2da103f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
9 changes: 3 additions & 6 deletions src/ValueAs.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,13 @@ public static function arr($value, $default = [])

if(is_string($value))
{
if(strpos($value, '=') !== false && strpos($value, '&') !== false)
if(strpos($value, '=') !== false)
{
$array = [];
foreach(explode('&', $value) as $set)
{
list($key, $val) = explode('=', $set, 2);
$array[$key] = $val;
}
parse_str($value, $array);
return $array;
}

if(strpos($value, ',') !== false)
{
return explode(',', $value);
Expand Down
2 changes: 1 addition & 1 deletion tests/DateTimeHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function uniqidProvider()

public function testMilliseconds()
{
static::assertIsInt(DateTimeHelper::milliseconds());
static::assertInternalType('int', DateTimeHelper::milliseconds());
}

public function testToSeconds()
Expand Down
8 changes: 4 additions & 4 deletions tests/SystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ protected function tearDown(): void

public function testGlobals()
{
static::assertIsBool(System::isHHVM());
static::assertIsBool(System::isMac());
static::assertIsBool(System::isWindows());
static::assertInternalType('bool', System::isHHVM());
static::assertInternalType('bool', System::isMac());
static::assertInternalType('bool', System::isWindows());
}

public function testIsAppEngine()
Expand Down Expand Up @@ -61,7 +61,7 @@ public function testIsBuiltInWebServer()

public function testCommandFinder()
{
static::assertIsBool(System::commandExists('whois'));
static::assertInternalType('bool', System::commandExists('whois'));
if(System::isWindows())
{
static::assertTrue(System::commandExists('explorer'));
Expand Down
6 changes: 2 additions & 4 deletions tests/ValueAsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ class ValueAsTest extends TestCase
*/
public function testExactConversions($method, $value, $default, $expect)
{
static::assertSame(
$expect,
ValueAs::$method($value, $default)
);
static::assertSame($expect, ValueAs::$method($value, $default));
}

/**
Expand Down Expand Up @@ -76,6 +73,7 @@ public function exactProvider()
['arr', "hey", null, ["hey"]],
['arr', "hello,world", null, ["hello", "world"]],
['arr', "test=one&unit=two", null, ["test" => 'one', "unit" => 'two']],
['arr', "test=one", null, ["test" => 'one']],
['arr', "", ["test"], ["test"]],
['arr', tmpfile(), ["test"], ["test"]],
['arr', $objectTest, ["test"], ["item" => "value"]],
Expand Down

0 comments on commit 2da103f

Please sign in to comment.