Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux committed Jul 24, 2018
1 parent 1024f1d commit 4000dce
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/Subaccounts/Subaccounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,7 @@ public function retrieve($id)
*/
public function create($name = null)
{
$request = new \stdClass();
if ($name !== null) {
$request->name = $name;
}
$res = $this->client->post('/subaccounts', ['json' => $request]);
$json = \GuzzleHttp\json_decode($res->getBody());
$mapper = SeatsioJsonMapper::create();
return $mapper->map($json, new Subaccount());
return $this->doCreate(null, $name);
}

/**
Expand All @@ -67,9 +60,19 @@ public function create($name = null)
* @return Subaccount
*/
public function createWithEmail($email, $name = null)
{
return $this->doCreate($email, $name);
}

/**
* @return Subaccount
*/
private function doCreate($email = null, $name = null)
{
$request = new \stdClass();
$request->email = $email;
if ($email !== null) {
$request->email = $email;
}
if ($name !== null) {
$request->name = $name;
}
Expand Down

0 comments on commit 4000dce

Please sign in to comment.