Skip to content

Commit

Permalink
Further refactoring of Listers
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux committed May 8, 2018
1 parent ddfcf80 commit ed65641
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 36 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ $chart1 = $seatsio->charts()->create();
$chart2 = $seatsio->charts()->create();
$chart3 = $seatsio->charts()->create();

$charts = $seatsio->charts()->iterator()->all();
$charts = $seatsio->charts()->listAll();
foreach($charts as $chart) {
echo 'Chart ' . $chart->key;
}
Expand Down
18 changes: 8 additions & 10 deletions src/Charts/Charts.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ class Charts
*/
private $client;

/**
* @var ChartLister
*/
public $archive;

public function __construct($client)
{
$this->client = $client;
$this->archive = new ChartLister(new PageFetcher('/charts/archive', $this->client, function () {
return new ChartPage();
}));
}

/**
Expand Down Expand Up @@ -271,16 +279,6 @@ private function iterator()
}));
}

/**
* @return ChartLister
*/
public function archive()
{
return new ChartLister(new PageFetcher('/charts/archive', $this->client, function () {
return new ChartPage();
}));
}

private function listParamsToArray($chartListParams)
{
if ($chartListParams == null) {
Expand Down
36 changes: 16 additions & 20 deletions src/Subaccounts/Subaccounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,25 @@ class Subaccounts
*/
private $client;

/**
* @var SubaccountLister
*/
public $active;

/**
* @var SubaccountLister
*/
public $inactive;

public function __construct($client)
{
$this->client = $client;
$this->active = new SubaccountLister(new PageFetcher('/subaccounts/active', $this->client, function () {
return new SubaccountPage();
}));
$this->inactive = new SubaccountLister(new PageFetcher('/subaccounts/inactive', $this->client, function () {
return new SubaccountPage();
}));
}

/**
Expand Down Expand Up @@ -171,24 +187,4 @@ private function iterator()
}));
}

/**
* @return SubaccountLister
*/
public function active()
{
return new SubaccountLister(new PageFetcher('/subaccounts/active', $this->client, function () {
return new SubaccountPage();
}));
}

/**
* @return SubaccountLister
*/
public function inactive()
{
return new SubaccountLister(new PageFetcher('/subaccounts/inactive', $this->client, function () {
return new SubaccountPage();
}));
}

}
2 changes: 1 addition & 1 deletion tests/Charts/ListChartsInArchiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function test()

$this->seatsioClient->charts()->create();

$charts = $this->seatsioClient->charts()->archive()->all();
$charts = $this->seatsioClient->charts()->archive->all();
$chartKeys = \Functional\map($charts, function($chart) { return $chart->key; });

self::assertEquals([$chart2->key, $chart1->key], array_values($chartKeys));
Expand Down
2 changes: 1 addition & 1 deletion tests/Charts/MoveChartOutOfArchiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function test()

$this->seatsioClient->charts()->moveOutOfArchive($chart->key);

$archivedCharts = $this->seatsioClient->charts()->archive()->all();
$archivedCharts = $this->seatsioClient->charts()->archive->all();
self::assertFalse($archivedCharts->valid());
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Charts/MoveChartToArchiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function test()

$this->seatsioClient->charts()->moveToArchive($chart->key);

$archivedCharts = $this->seatsioClient->charts()->archive()->all();
$archivedCharts = $this->seatsioClient->charts()->archive->all();
$archivedChartKeys = \Functional\map($archivedCharts, function($chart) { return $chart->key; });

self::assertEquals([$chart->key], array_values($archivedChartKeys));
Expand Down
2 changes: 1 addition & 1 deletion tests/Subacounts/ListActiveSubaccountsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function test()
$subaccount3 = $this->seatsioClient->subaccounts()->create();
$this->seatsioClient->subaccounts()->deactivate($subaccount3->id);

$subaccounts = $this->seatsioClient->subaccounts()->active()->all();
$subaccounts = $this->seatsioClient->subaccounts()->active->all();
$subaccountIds = \Functional\map($subaccounts, function($subaccount) { return $subaccount->id; });

self::assertEquals([$subaccount2->id, $subaccount1->id], array_values($subaccountIds));
Expand Down
2 changes: 1 addition & 1 deletion tests/Subacounts/ListInactiveSubaccountsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function test()

$this->seatsioClient->subaccounts()->create();

$subaccounts = $this->seatsioClient->subaccounts()->inactive()->all();
$subaccounts = $this->seatsioClient->subaccounts()->inactive->all();
$subaccountIds = \Functional\map($subaccounts, function($subaccount) { return $subaccount->id; });

self::assertEquals([$subaccount2->id, $subaccount1->id], array_values($subaccountIds));
Expand Down

0 comments on commit ed65641

Please sign in to comment.