Skip to content

Commit

Permalink
Make ->formatParams recursive
Browse files Browse the repository at this point in the history
  • Loading branch information
richardm-stripe committed May 15, 2020
1 parent a75a888 commit 76ecf45
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/Service/AbstractService.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ public function getClient()
*
* @param null|array $params
*/
private static function formatParams($params)
public static function formatParams($params)
{
if (null === $params) {
return $params;
}

$formatted = [];
foreach ($params as $k => $v) {
if (null === $v) {
if (\is_array($v)) {
$formatted[$k] = static::formatParams($v);
} elseif (null === $v) {
$formatted[$k] = '';
} else {
$formatted[$k] = $v;
Expand Down
12 changes: 12 additions & 0 deletions tests/Stripe/Service/AbstractServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,16 @@ public function testRetrieveThrowsIfIdNullIsWhitespace()

$this->service->retrieve(' ');
}

public function testFormatParams()
{
$result = \Stripe\Service\AbstractService::formatParams(['foo' => null]);
static::assertTrue('' === $result['foo']);
static::assertTrue(null !== $result['foo']);

$result = \Stripe\Service\AbstractService::formatParams(['foo' => ['bar' => null, 'baz' => 1]]);
static::assertTrue('' === $result['foo']['bar']);
static::assertTrue(null !== $result['foo']['bar']);
static::assertTrue(1 === $result['foo']['baz']);
}
}

0 comments on commit 76ecf45

Please sign in to comment.