Skip to content

Switch to PSR-17 #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ This version requires [PHP](https://php.net) 7.2-7.4.
To get the latest version, simply require the project using [Composer](https://getcomposer.org). You will need to install any package that "provides" `psr/http-client-implementation`. Pure PHP users will want something like:

```bash
$ composer require bitbucket/client guzzlehttp/guzzle:^7.0.1
$ composer require bitbucket/client:^3.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0
```

Laravel users will want something like:

```bash
$ composer require graham-campbell/bitbucket guzzlehttp/guzzle:^7.0.1
$ composer require graham-campbell/bitbucket:^7.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0
```

We are decoupled from any HTTP messaging client with help by [HTTPlug](http://httplug.io). You can visit [HTTPlug for library users](https://docs.php-http.org/en/latest/httplug/users.html) to get more information about installing HTTPlug related packages. [`graham-campbell/bitbucket`](https://github.com/GrahamCampbell/Laravel-Bitbucket) is also maintained by [Graham Campbell](https://github.com/GrahamCampbell).
Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
],
"require": {
"php": "^7.2.5",
"php-http/client-common": "^2.1",
"php-http/client-common": "^2.2",
"php-http/cache-plugin": "^1.7",
"php-http/discovery": "^1.7",
"php-http/discovery": "^1.9",
"php-http/httplug": "^2.1",
"php-http/multipart-stream-builder": "^1.1",
"psr/cache": "^1.0",
Expand All @@ -24,9 +24,10 @@
"require-dev": {
"bamarni/composer-bin-plugin": "^1.4.1",
"graham-campbell/analyzer": "^3.0",
"phpunit/phpunit": "^8.5|^9.0",
"php-http/guzzle6-adapter": "^2.0",
"php-http/mock-client": "^1.3"
"guzzlehttp/guzzle": "^7.0.1",
"http-interop/http-factory-guzzle": "^1.0",
"php-http/mock-client": "^1.4",
"phpunit/phpunit": "^8.5|^9.0"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use Http\Client\Common\Plugin\HeaderDefaultsPlugin;
use Http\Client\Common\Plugin\HistoryPlugin;
use Http\Client\Common\Plugin\RedirectPlugin;
use Http\Discovery\UriFactoryDiscovery;
use Http\Discovery\Psr17FactoryDiscovery;

/**
* The Bitbucket API 2.0 client.
Expand Down Expand Up @@ -191,7 +191,7 @@ public function authenticate(string $method, string $token, string $password = n
public function setUrl(string $url)
{
$this->httpClientBuilder->removePlugin(AddHostPlugin::class);
$this->httpClientBuilder->addPlugin(new AddHostPlugin(UriFactoryDiscovery::find()->createUri($url)));
$this->httpClientBuilder->addPlugin(new AddHostPlugin(Psr17FactoryDiscovery::findUrlFactory()->createUri($url)));
}

/**
Expand Down
25 changes: 12 additions & 13 deletions src/HttpClient/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
use Http\Client\Common\Plugin\Cache\Generator\HeaderCacheKeyGenerator;
use Http\Client\Common\Plugin\CachePlugin;
use Http\Client\Common\PluginClientFactory;
use Http\Discovery\MessageFactoryDiscovery;
use Http\Discovery\Psr17FactoryDiscovery;
use Http\Discovery\Psr18ClientDiscovery;
use Http\Discovery\StreamFactoryDiscovery;
use Http\Message\RequestFactory;
use Http\Message\StreamFactory;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;

/**
* The Bitbucket HTTP client builder class.
Expand Down Expand Up @@ -59,14 +58,14 @@ final class Builder
/**
* The HTTP request factory.
*
* @var \Http\Message\RequestFactory
* @var \Psr\Http\Message\RequestFactoryInterface
*/
private $requestFactory;

/**
* The HTTP stream factory.
*
* @var \Http\Message\StreamFactory
* @var \Psr\Http\Message\StreamFactoryInterface
*/
private $streamFactory;

Expand Down Expand Up @@ -96,18 +95,18 @@ final class Builder
/**
* Create a new http client builder instance.
*
* @param \Psr\Http\Client\ClientInterface|null $httpClient
* @param \Http\Message\RequestFactory|null $requestFactory
* @param \Http\Message\StreamFactory|null $streamFactory
* @param \Psr\Http\Client\ClientInterface|null $httpClient
* @param \Psr\Http\Message\RequestFactoryInterface|null $requestFactory
* @param \Psr\Http\Message\StreamFactoryInterface|null $streamFactory
*/
public function __construct(
ClientInterface $httpClient = null,
RequestFactory $requestFactory = null,
StreamFactory $streamFactory = null
RequestFactoryInterface $requestFactory = null,
StreamFactoryInterface $streamFactory = null
) {
$this->httpClient = $httpClient ?? Psr18ClientDiscovery::find();
$this->requestFactory = $requestFactory ?? MessageFactoryDiscovery::find();
$this->streamFactory = $streamFactory ?? StreamFactoryDiscovery::find();
$this->requestFactory = $requestFactory ?? Psr17FactoryDiscovery::findRequestFactory();
$this->streamFactory = $streamFactory ?? Psr17FactoryDiscovery::findStreamFactory();
}

/**
Expand Down
15 changes: 5 additions & 10 deletions tests/MockedClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

use Bitbucket\Client;
use Bitbucket\HttpClient\Builder;
use Http\Message\ResponseFactory;
use Http\Mock\Client as MockClient;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;

/**
Expand All @@ -42,25 +42,20 @@ public static function create(ResponseInterface $response)
/**
* @param \Psr\Http\Message\ResponseInterface $response
*
* @return \Http\Message\ResponseFactory
* @return \Psr\Http\Message\ResponseFactoryInterface
*/
private static function createResponseFactory(ResponseInterface $response)
{
return new class($response) implements ResponseFactory {
return new class($response) implements ResponseFactoryInterface {
private $response;

public function __construct(ResponseInterface $response)
{
$this->response = $response;
}

public function createResponse(
$statusCode = 200,
$reasonPhrase = null,
array $headers = [],
$body = null,
$protocolVersion = '1.1'
) {
public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
{
return $this->response;
}
};
Expand Down
3 changes: 2 additions & 1 deletion vendor-bin/phpstan/composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"require": {
"phpstan/phpstan": "^0.12.31",
"phpstan/phpstan": "^0.12.32",
"phpstan/extension-installer": "^1.0.4",
"phpstan/phpstan-deprecation-rules": "^0.12.4",
"phpstan/phpstan-strict-rules": "^0.12.2",
"thecodingmachine/phpstan-strict-rules": "^0.12.0"
},
Expand Down