Skip to content

Commit

Permalink
Merge pull request #3 from Art4/psr12-code-style
Browse files Browse the repository at this point in the history
Change code style to PSR-12
  • Loading branch information
Art4 authored Oct 7, 2022
2 parents 55651c8 + c379305 commit d337e8e
Show file tree
Hide file tree
Showing 83 changed files with 6,091 additions and 5,610 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
operating-system: ['ubuntu-latest']
php: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']

steps:
- name: Checkout
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/.php-cs-fixer.cache
/.phpunit.result.cache
/composer.lock
/vendor/
17 changes: 17 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

$finder = (new PhpCsFixer\Finder())
->in('src')
->in('tests')
;

return (new PhpCsFixer\Config())
->setRules([
'@PSR12' => true,
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,
'void_return' => false,
'@PHPUnit84Migration:risky' => true,
])
->setFinder($finder)
;
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add required PHP version in `composer.json`

### Changed

- Change Code Style to PSR-12
- Drop support for PHP 7.0

## [1.0.0-beta](https://github.com/Art4/WP-Requests-PSR18-Adapter/compare/09aae5d7deac8058c5a25c1d951cd350d066ad6e...1.0.0-beta)

### Added
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Use [WordPress/Requests](https://github.com/WordPress/Requests) as a [PSR-18](https://www.php-fig.org/psr/psr-18/) HTTP client adapter.

Requires PHP 7.0+
Requires PHP 7.1+

## Why?

Expand Down Expand Up @@ -30,7 +30,7 @@ require_once dirname(__DIR__) . '/vendor/autoload.php';

// Define Requests options
$options = [
'proxy' => '127.0.0.1:8080',
'proxy' => '127.0.0.1:8080',
'transport' => $customTransport,
// other Requests options
];
Expand All @@ -50,6 +50,6 @@ try {
throw $th;
}

// See the result
// Use the PSR-7 Response
var_dump($response);
```
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
}
],
"require": {
"php": "^7.0 || ^8.0",
"php": "^7.1 || ^8.0",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0",
"rmccue/requests": "^2.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"yoast/phpunit-polyfills": "^1.0"
},
"autoload": {
Expand Down
60 changes: 32 additions & 28 deletions src/Exception/Psr/NetworkException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* Transport Exception
*
Expand All @@ -23,36 +25,38 @@
*
* Example: the target host name can not be resolved or the connection failed.
*/
class NetworkException extends Exception implements NetworkExceptionInterface {

class NetworkException extends Exception implements NetworkExceptionInterface
{
/**
* @var RequestInterface
*/
private $request;
* @var RequestInterface
*/
private $request;

/**
* Create a new exception
*
* @param RequestInterface $request
* @param Transport $previous
*/
public function __construct(RequestInterface $request, Transport $previous) {
parent::__construct(
$previous->getMessage(),
$previous->getType(),
$previous->getData(),
$previous->getCode()
);
/**
* Create a new exception
*
* @param RequestInterface $request
* @param Transport $previous
*/
public function __construct(RequestInterface $request, Transport $previous)
{
parent::__construct(
$previous->getMessage(),
$previous->getType(),
$previous->getData(),
$previous->getCode()
);

$this->request = $request;
}
$this->request = $request;
}

/**
* Returns the request.
*
* The request object MAY be a different object from the one passed to ClientInterface::sendRequest()
*/
public function getRequest(): RequestInterface {
return $this->request;
}
/**
* Returns the request.
*
* The request object MAY be a different object from the one passed to ClientInterface::sendRequest()
*/
public function getRequest(): RequestInterface
{
return $this->request;
}
}
62 changes: 33 additions & 29 deletions src/Exception/Psr/RequestException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* Transport Exception
*
Expand All @@ -20,36 +22,38 @@
* - Request is invalid (e.g. method is missing)
* - Runtime request errors (e.g. the body stream is not seekable)
*/
class RequestException extends Exception implements RequestExceptionInterface {

/**
* @var RequestInterface
*/
private $request;
class RequestException extends Exception implements RequestExceptionInterface
{
/**
* @var RequestInterface
*/
private $request;

/**
* Create a new exception
*
* @param RequestInterface $request
* @param Transport $previous
*/
public function __construct(RequestInterface $request, Exception $previous) {
parent::__construct(
$previous->getMessage(),
$previous->getType(),
$previous->getData(),
$previous->getCode()
);
/**
* Create a new exception
*
* @param RequestInterface $request
* @param Transport $previous
*/
public function __construct(RequestInterface $request, Exception $previous)
{
parent::__construct(
$previous->getMessage(),
$previous->getType(),
$previous->getData(),
$previous->getCode()
);

$this->request = $request;
}
$this->request = $request;
}

/**
* Returns the request.
*
* The request object MAY be a different object from the one passed to ClientInterface::sendRequest()
*/
public function getRequest(): RequestInterface {
return $this->request;
}
/**
* Returns the request.
*
* The request object MAY be a different object from the one passed to ClientInterface::sendRequest()
*/
public function getRequest(): RequestInterface
{
return $this->request;
}
}
Loading

0 comments on commit d337e8e

Please sign in to comment.