Skip to content

Commit 63b14f1

Browse files
authored
Remove dupplicated code in paginated response (#1012)
1 parent 698023f commit 63b14f1

File tree

3 files changed

+3
-81
lines changed

3 files changed

+3
-81
lines changed

src/Result/ListFunctionsResponse.php

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -86,33 +86,7 @@ public function getFunctions(bool $currentPageOnly = false): iterable
8686
*/
8787
public function getIterator(): \Traversable
8888
{
89-
$client = $this->awsClient;
90-
if (!$client instanceof LambdaClient) {
91-
throw new InvalidArgument('missing client injected in paginated result');
92-
}
93-
if (!$this->input instanceof ListFunctionsRequest) {
94-
throw new InvalidArgument('missing last request injected in paginated result');
95-
}
96-
$input = clone $this->input;
97-
$page = $this;
98-
while (true) {
99-
if ($page->getNextMarker()) {
100-
$input->setMarker($page->getNextMarker());
101-
102-
$this->registerPrefetch($nextPage = $client->listFunctions($input));
103-
} else {
104-
$nextPage = null;
105-
}
106-
107-
yield from $page->getFunctions(true);
108-
109-
if (null === $nextPage) {
110-
break;
111-
}
112-
113-
$this->unregisterPrefetch($nextPage);
114-
$page = $nextPage;
115-
}
89+
yield from $this->getFunctions();
11690
}
11791

11892
public function getNextMarker(): ?string

src/Result/ListLayerVersionsResponse.php

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,7 @@ class ListLayerVersionsResponse extends Result implements \IteratorAggregate
3232
*/
3333
public function getIterator(): \Traversable
3434
{
35-
$client = $this->awsClient;
36-
if (!$client instanceof LambdaClient) {
37-
throw new InvalidArgument('missing client injected in paginated result');
38-
}
39-
if (!$this->input instanceof ListLayerVersionsRequest) {
40-
throw new InvalidArgument('missing last request injected in paginated result');
41-
}
42-
$input = clone $this->input;
43-
$page = $this;
44-
while (true) {
45-
if ($page->getNextMarker()) {
46-
$input->setMarker($page->getNextMarker());
47-
48-
$this->registerPrefetch($nextPage = $client->listLayerVersions($input));
49-
} else {
50-
$nextPage = null;
51-
}
52-
53-
yield from $page->getLayerVersions(true);
54-
55-
if (null === $nextPage) {
56-
break;
57-
}
58-
59-
$this->unregisterPrefetch($nextPage);
60-
$page = $nextPage;
61-
}
35+
yield from $this->getLayerVersions();
6236
}
6337

6438
/**

src/Result/ListVersionsByFunctionResponse.php

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -41,33 +41,7 @@ class ListVersionsByFunctionResponse extends Result implements \IteratorAggregat
4141
*/
4242
public function getIterator(): \Traversable
4343
{
44-
$client = $this->awsClient;
45-
if (!$client instanceof LambdaClient) {
46-
throw new InvalidArgument('missing client injected in paginated result');
47-
}
48-
if (!$this->input instanceof ListVersionsByFunctionRequest) {
49-
throw new InvalidArgument('missing last request injected in paginated result');
50-
}
51-
$input = clone $this->input;
52-
$page = $this;
53-
while (true) {
54-
if ($page->getNextMarker()) {
55-
$input->setMarker($page->getNextMarker());
56-
57-
$this->registerPrefetch($nextPage = $client->listVersionsByFunction($input));
58-
} else {
59-
$nextPage = null;
60-
}
61-
62-
yield from $page->getVersions(true);
63-
64-
if (null === $nextPage) {
65-
break;
66-
}
67-
68-
$this->unregisterPrefetch($nextPage);
69-
$page = $nextPage;
70-
}
44+
yield from $this->getVersions();
7145
}
7246

7347
public function getNextMarker(): ?string

0 commit comments

Comments
 (0)