Skip to content

Commit af89959

Browse files
authored
feature KnpLabs#986 Deprecate ResultPager::postFetch method (acrobat)
This PR was merged into the 3.2.x-dev branch. Discussion ---------- We don't see any real usecases for the method to be called from the outside. Therefor we prepare this method for removal in 4.0. If you have any valid usecases, please open an issue to discuss this. Fixes KnpLabs#951 Commits ------- cf7ca9a Deprecate ResultPager::postFetch method
2 parents bf8d54b + cf7ca9a commit af89959

File tree

6 files changed

+45
-6
lines changed

6 files changed

+45
-6
lines changed

UPGRADE-4.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## UPGRADE from 3.x to 4.0
2+
3+
### ResultPager
4+
5+
* `\Github\ResultPagerInterface::postFetch` is deprecated, and the method will be removed from the ResultPager interface/class.

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"psr/http-client-implementation": "^1.0",
2929
"psr/http-factory-implementation": "^1.0",
3030
"psr/http-message": "^1.0",
31-
"symfony/polyfill-php80": "^1.17"
31+
"symfony/polyfill-php80": "^1.17",
32+
"symfony/deprecation-contracts": "^2.2"
3233
},
3334
"require-dev": {
3435
"symfony/cache": "^5.1.8",
@@ -39,7 +40,8 @@
3940
"phpstan/phpstan": "^0.12.57",
4041
"phpstan/extension-installer": "^1.0.5",
4142
"phpstan/phpstan-deprecation-rules": "^0.12.5",
42-
"phpunit/phpunit": "^8.5 || ^9.4"
43+
"phpunit/phpunit": "^8.5 || ^9.4",
44+
"symfony/phpunit-bridge": "^5.2"
4345
},
4446
"autoload": {
4547
"psr-4": { "Github\\": "lib/Github/" }

lib/Github/ResultPager.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function fetch(AbstractApi $api, string $method, array $parameters = []):
8686
$api = $closure($api);
8787
$result = $api->$method(...$parameters);
8888

89-
$this->postFetch();
89+
$this->postFetch(true);
9090

9191
return $result;
9292
}
@@ -130,9 +130,13 @@ public function fetchAllLazy(AbstractApi $api, string $method, array $parameters
130130
/**
131131
* {@inheritdoc}
132132
*/
133-
public function postFetch(): void
133+
public function postFetch(/* $skipDeprecation = false */): void
134134
{
135-
$this->pagination = ResponseMediator::getPagination($this->client->getLastResponse());
135+
if (func_num_args() === 0 || (func_num_args() > 0 && false === func_get_arg(0))) {
136+
trigger_deprecation('KnpLabs/php-github-api', '3.2', 'The "%s" method is deprecated and will be removed.', __METHOD__);
137+
}
138+
139+
$this->setPagination();
136140
}
137141

138142
/**
@@ -196,8 +200,13 @@ protected function get(string $key): array
196200

197201
$result = $this->client->getHttpClient()->get($this->pagination[$key]);
198202

199-
$this->postFetch();
203+
$this->postFetch(true);
200204

201205
return ResponseMediator::getContent($result);
202206
}
207+
208+
private function setPagination(): void
209+
{
210+
$this->pagination = ResponseMediator::getPagination($this->client->getLastResponse());
211+
}
203212
}

lib/Github/ResultPagerInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public function fetchAllLazy(AbstractApi $api, string $method, array $parameters
5454
/**
5555
* Method that performs the actual work to refresh the pagination property.
5656
*
57+
* @deprecated since 3.2 and will be removed in 4.0.
58+
*
5759
* @return void
5860
*/
5961
public function postFetch(): void;

phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@
2727
<directory suffix=".php">./lib/Github/</directory>
2828
</whitelist>
2929
</filter>
30+
31+
<listeners>
32+
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
33+
</listeners>
3034
</phpunit>

test/Github/Tests/ResultPagerTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use GuzzleHttp\Psr7\Utils;
1414
use Http\Client\HttpClient;
1515
use Psr\Http\Client\ClientInterface;
16+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1617

1718
/**
1819
* @author Ramon de la Fuente <ramon@future500.nl>
@@ -21,6 +22,8 @@
2122
*/
2223
class ResultPagerTest extends \PHPUnit\Framework\TestCase
2324
{
25+
use ExpectDeprecationTrait;
26+
2427
public function provideFetchCases()
2528
{
2629
return [
@@ -197,4 +200,18 @@ public function testFetchAllWithoutKeys()
197200

198201
$this->assertCount(9, $result);
199202
}
203+
204+
/**
205+
* @group legacy
206+
*/
207+
public function testPostFetchDeprecation()
208+
{
209+
$this->expectDeprecation('Since KnpLabs/php-github-api 3.2: The "Github\ResultPager::postFetch" method is deprecated and will be removed.');
210+
211+
$clientMock = $this->createMock(Client::class);
212+
$clientMock->method('getLastResponse')->willReturn(new PaginatedResponse(3, []));
213+
214+
$paginator = new ResultPager($clientMock);
215+
$paginator->postFetch();
216+
}
200217
}

0 commit comments

Comments
 (0)