Skip to content

Commit

Permalink
Bugfix.
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Jun 10, 2020
1 parent 4142982 commit b335889
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 34 deletions.
63 changes: 42 additions & 21 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,49 @@
<?php
$header = <<<EOF
This file is part of the overtrue/http.
(c) overtrue <[email protected]>
This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.
EOF;

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules(array(
'@Symfony' => true,
'header_comment' => array('header' => $header),
'array_syntax' => array('syntax' => 'short'),
'ordered_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'php_unit_construct' => true,
'php_unit_strict' => true,
))
->setRules([
'@PSR2' => true,
'binary_operator_spaces' => true,
'blank_line_after_opening_tag' => true,
'compact_nullable_typehint' => true,
'declare_equal_normalize' => true,
'lowercase_cast' => true,
'lowercase_static_reference' => true,
'new_with_braces' => true,
'no_unused_imports' => true,
'no_blank_lines_after_class_opening' => true,
'no_leading_import_slash' => true,
'no_whitespace_in_blank_line' => true,
'ordered_class_elements' => [
'order' => [
'use_trait',
],
],
'ordered_imports' => [
'imports_order' => [
'class',
'function',
'const',
],
'sort_algorithm' => 'none',
],
'return_type_declaration' => true,
'short_scalar_cast' => true,
'single_blank_line_before_namespace' => true,
'single_trait_insert_per_statement' => true,
'ternary_operator_spaces' => true,
'unary_operator_spaces' => true,
'visibility_required' => [
'elements' => [
'const',
'method',
'property',
],
],
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude('vendor')
->in(__DIR__)
->in([__DIR__.'/src/', __DIR__.'/tests/'])
)
;
;
27 changes: 24 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
"ext-libxml": "*"
},
"require-dev": {
"phpunit/phpunit": "^6.5 || ^8.0",
"phpunit/phpunit": "^6.5 || ^8.5",
"mockery/mockery": "^1.0",
"overtrue/phplint": "^1.1 || ^2.0"
"overtrue/phplint": "^1.1 || ^2.0",
"brainmaestro/composer-git-hooks": "^2.7",
"friendsofphp/php-cs-fixer": "^2.15"
},
"autoload": {
"psr-4": {
Expand All @@ -26,5 +28,24 @@
"name": "overtrue",
"email": "[email protected]"
}
]
],
"scripts": {
"post-update-cmd": [
"cghooks update"
],
"post-merge": "composer install",
"post-install-cmd": [
"cghooks add --ignore-lock",
"cghooks update"
],
"cghooks": "vendor/bin/cghooks",
"check-style": "php-cs-fixer fix --using-cache=no --diff --config=.php_cs --dry-run --ansi",
"fix-style": "php-cs-fixer fix --using-cache=no --config=.php_cs --ansi",
"test": "vendor/bin/phpunit --colors=always"
},
"scripts-descriptions": {
"test": "Run all tests.",
"check-style": "Run style checks (only dry run - no fixing!).",
"fix-style": "Run style checks and fix violations."
}
}
15 changes: 9 additions & 6 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,17 @@ public function uploadAsync(string $uri, array $files = [], array $form = [], ar
* @param array $options
* @param bool $async
*
* @return \Psr\Http\Message\ResponseInterface|\Overtrue\Http\Support\Collection|array|object|string
* @return \Psr\Http\Message\ResponseInterface|\GuzzleHttp\Promise\PromiseInterface|\Overtrue\Http\Support\Collection|array|object|string
*/
public function request(string $uri, string $method = 'GET', array $options = [], bool $async = false)
{
return $this->castResponseToType(
$this->requestRaw($uri, $method, $options, $async),
$this->config->getOption('response_type')
);
$result = $this->requestRaw($uri, $method, $options, $async);

$transformer = function ($response) {
return $this->castResponseToType($response, $this->config->getOption('response_type'));
};

return $async ? $result->then($transformer) : $transformer($result);
}

/**
Expand All @@ -280,7 +283,7 @@ public function request(string $uri, string $method = 'GET', array $options = []
* @param array $options
* @param bool $async
*
* @return array|object|\Overtrue\Http\Support\Collection|\Psr\Http\Message\ResponseInterface|string
* @return \Psr\Http\Message\ResponseInterface|\GuzzleHttp\Promise\PromiseInterface|\Overtrue\Http\Support\Collection|array|object|string
*/
public function requestRaw(string $uri, string $method = 'GET', array $options = [], bool $async = false)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class Config
* @var array
*/
protected $options = [
'base_uri' => null,
'timeout' => 3000,
'base_uri' => null,
'timeout' => 3000,
'connect_timeout' => 3000,
'proxy' => [],
'proxy' => [],
];

/**
Expand Down
1 change: 0 additions & 1 deletion src/Traits/HasHttpRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use Psr\Http\Message\ResponseInterface;

/**
* Trait HasHttpRequests.
Expand Down

0 comments on commit b335889

Please sign in to comment.