Skip to content
This repository has been archived by the owner on Apr 1, 2023. It is now read-only.

Commit

Permalink
Fix CS
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Dec 6, 2019
1 parent 2e586d6 commit 16ab689
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 58 deletions.
26 changes: 11 additions & 15 deletions Goutte/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use GuzzleHttp\Cookie\CookieJar;
use GuzzleHttp\Exception\RequestException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;
use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\BrowserKit\Request;
use Symfony\Component\BrowserKit\Response;
Expand All @@ -33,16 +32,13 @@ class Client extends AbstractBrowser
{
protected $client;

private $headers = array();
private $headers = [];
private $auth;

public function setClient(GuzzleClientInterface $client)
{
$this->client = $client;

/**
* @var $baseUri UriInterface
*/
if (null !== $this->getServerParameter('HTTP_HOST', null) || null === $baseUri = $client->getConfig('base_uri')) {
return $this;
}
Expand All @@ -69,7 +65,7 @@ public function setClient(GuzzleClientInterface $client)
public function getClient()
{
if (!$this->client) {
$this->client = new GuzzleClient(array('allow_redirects' => false, 'cookies' => true));
$this->client = new GuzzleClient(['allow_redirects' => false, 'cookies' => true]);
}

return $this->client;
Expand All @@ -89,7 +85,7 @@ public function removeHeader($name)

public function resetHeaders()
{
$this->headers = array();
$this->headers = [];

return $this;
}
Expand All @@ -106,7 +102,7 @@ public function restart()

public function setAuth($user, $password = '', $type = 'basic')
{
$this->auth = array($user, $password, $type);
$this->auth = [$user, $password, $type];

return $this;
}
Expand All @@ -125,10 +121,10 @@ public function resetAuth()
*/
protected function doRequest($request)
{
$headers = array();
$headers = [];
foreach ($request->getServer() as $key => $val) {
$key = strtolower(str_replace('_', '-', $key));
$contentHeaders = array('content-length' => true, 'content-md5' => true, 'content-type' => true);
$contentHeaders = ['content-length' => true, 'content-md5' => true, 'content-type' => true];
if (0 === strpos($key, 'http-')) {
$headers[substr($key, 5)] = $val;
}
Expand All @@ -143,13 +139,13 @@ protected function doRequest($request)
parse_url($request->getUri(), PHP_URL_HOST)
);

$requestOptions = array(
$requestOptions = [
'cookies' => $cookies,
'allow_redirects' => false,
'auth' => $this->auth,
);
];

if (!in_array($request->getMethod(), array('GET', 'HEAD'))) {
if (!\in_array($request->getMethod(), ['GET', 'HEAD'])) {
if (null !== $content = $request->getContent()) {
$requestOptions['body'] = $content;
} else {
Expand Down Expand Up @@ -203,7 +199,7 @@ protected function addPostFiles(array $files, array &$multipart, $arrayName = ''
'name' => $name,
];

if (is_array($info)) {
if (\is_array($info)) {
if (isset($info['tmp_name'])) {
if ('' !== $info['tmp_name']) {
$file['contents'] = fopen($info['tmp_name'], 'r');
Expand Down Expand Up @@ -232,7 +228,7 @@ public function addPostFields(array $formParams, array &$multipart, $arrayName =
$name = $arrayName.'['.$name.']';
}

if (is_array($value)) {
if (\is_array($value)) {
$this->addPostFields($value, $multipart, $name);
} else {
$multipart[] = [
Expand Down
86 changes: 43 additions & 43 deletions Goutte/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response as GuzzleResponse;
use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Response as GuzzleResponse;
use PHPUnit\Framework\TestCase;
use Symfony\Component\BrowserKit\Cookie;

Expand All @@ -42,7 +42,7 @@ protected function getGuzzle(array $responses = [], array $extraConfig = [])
$handlerStack = HandlerStack::create($this->mock);
$this->history = [];
$handlerStack->push(Middleware::history($this->history));
$guzzle = new GuzzleClient(array_merge(array('redirect.disable' => true, 'base_uri' => '', 'handler' => $handlerStack), $extraConfig));
$guzzle = new GuzzleClient(array_merge(['redirect.disable' => true, 'base_uri' => '', 'handler' => $handlerStack], $extraConfig));

return $guzzle;
}
Expand Down Expand Up @@ -131,14 +131,14 @@ public function testUsesPostFiles()
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$files = array(
'test' => array(
$files = [
'test' => [
'name' => 'test.txt',
'tmp_name' => __DIR__.'/fixtures.txt',
),
);
],
];

$client->request('POST', 'http://www.example.com/', array(), $files);
$client->request('POST', 'http://www.example.com/', [], $files);
$request = end($this->history)['request'];

$stream = $request->getBody();
Expand All @@ -155,11 +155,11 @@ public function testUsesPostNamedFiles()
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$files = array(
$files = [
'test' => __DIR__.'/fixtures.txt',
);
];

$client->request('POST', 'http://www.example.com/', array(), $files);
$client->request('POST', 'http://www.example.com/', [], $files);
$request = end($this->history)['request'];

$stream = $request->getBody();
Expand All @@ -176,16 +176,16 @@ public function testUsesPostFilesNestedFields()
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$files = array(
'form' => array(
'test' => array(
$files = [
'form' => [
'test' => [
'name' => 'test.txt',
'tmp_name' => __DIR__.'/fixtures.txt',
),
),
);
],
],
];

$client->request('POST', 'http://www.example.com/', array(), $files);
$client->request('POST', 'http://www.example.com/', [], $files);
$request = end($this->history)['request'];

$stream = $request->getBody();
Expand All @@ -202,12 +202,12 @@ public function testPostFormWithFiles()
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$files = array(
$files = [
'test' => __DIR__.'/fixtures.txt',
);
$params = array(
];
$params = [
'foo' => 'bar',
);
];

$client->request('POST', 'http://www.example.com/', $params, $files);
$request = end($this->history)['request'];
Expand All @@ -228,14 +228,14 @@ public function testPostEmbeddedFormWithFiles()
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$files = array(
$files = [
'test' => __DIR__.'/fixtures.txt',
);
$params = array(
'foo' => array(
];
$params = [
'foo' => [
'bar' => 'baz',
),
);
],
];

$client->request('POST', 'http://www.example.com/', $params, $files);
$request = end($this->history)['request'];
Expand All @@ -256,11 +256,11 @@ public function testUsesPostFilesOnClientSide()
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$files = array(
$files = [
'test' => __DIR__.'/fixtures.txt',
);
];

$client->request('POST', 'http://www.example.com/', array(), $files);
$client->request('POST', 'http://www.example.com/', [], $files);
$request = end($this->history)['request'];

$stream = $request->getBody();
Expand All @@ -277,17 +277,17 @@ public function testUsesPostFilesUploadError()
$guzzle = $this->getGuzzle();
$client = new Client();
$client->setClient($guzzle);
$files = array(
'test' => array(
$files = [
'test' => [
'name' => '',
'type' => '',
'tmp_name' => '',
'error' => 4,
'size' => 0,
),
);
],
];

$client->request('POST', 'http://www.example.com/', array(), $files);
$client->request('POST', 'http://www.example.com/', [], $files);
$request = end($this->history)['request'];
$stream = $request->getBody();
$boundary = $stream->getBoundary();
Expand All @@ -307,9 +307,9 @@ public function testCreatesResponse()
public function testHandlesRedirectsCorrectly()
{
$guzzle = $this->getGuzzle([
new GuzzleResponse(301, array(
new GuzzleResponse(301, [
'Location' => 'http://www.example.com/',
)),
]),
new GuzzleResponse(200, [], '<html><body><p>Test</p></body></html>'),
]);

Expand All @@ -320,15 +320,15 @@ public function testHandlesRedirectsCorrectly()
$this->assertEquals('Test', $crawler->filter('p')->text());

// Ensure that two requests were sent
$this->assertEquals(2, count($this->history));
$this->assertEquals(2, \count($this->history));
}

public function testConvertsGuzzleHeadersToArrays()
{
$guzzle = $this->getGuzzle([
new GuzzleResponse(200, array(
new GuzzleResponse(200, [
'Date' => 'Tue, 04 Jun 2013 13:22:41 GMT',
)),
]),
]);

$client = new Client();
Expand Down Expand Up @@ -383,7 +383,7 @@ public function testResetHeaders()

$reflectionProperty = new \ReflectionProperty('Goutte\Client', 'headers');
$reflectionProperty->setAccessible(true);
$this->assertEquals(array('x-test' => 'test'), $reflectionProperty->getValue($client));
$this->assertEquals(['x-test' => 'test'], $reflectionProperty->getValue($client));

$client->resetHeaders();
$this->assertEquals([], $reflectionProperty->getValue($client));
Expand All @@ -397,11 +397,11 @@ public function testRestart()

$headersReflectionProperty = new \ReflectionProperty('Goutte\Client', 'headers');
$headersReflectionProperty->setAccessible(true);
$this->assertEquals(array('x-test' => 'test'), $headersReflectionProperty->getValue($client));
$this->assertEquals(['x-test' => 'test'], $headersReflectionProperty->getValue($client));

$authReflectionProperty = new \ReflectionProperty('Goutte\Client', 'auth');
$authReflectionProperty->setAccessible(true);
$this->assertEquals(array('foo', 'bar', 'basic'), $authReflectionProperty->getValue($client));
$this->assertEquals(['foo', 'bar', 'basic'], $authReflectionProperty->getValue($client));

$client->restart();
$this->assertEquals([], $headersReflectionProperty->getValue($client));
Expand Down

0 comments on commit 16ab689

Please sign in to comment.