Skip to content
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

CS: align multiple subsequent assignment statements #399

Merged
merged 1 commit into from
Oct 21, 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
8 changes: 4 additions & 4 deletions bin/create_pear_package.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@
);

$context['files'] = '';
$path = realpath(dirname(__FILE__) . '/../library/Requests');
$path = realpath(dirname(__FILE__) . '/../library/Requests');
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
if (preg_match('/\.php$/', $file)) {
$name = str_replace($path . DIRECTORY_SEPARATOR, '', $file);
$name = str_replace(DIRECTORY_SEPARATOR, '/', $name);
$name = str_replace($path . DIRECTORY_SEPARATOR, '', $file);
$name = str_replace(DIRECTORY_SEPARATOR, '/', $name);
$context['files'][] = "\t\t\t\t\t" . '<file install-as="Requests/' . $name . '" name="' . $name . '" role="php" />';
}
}

$context['files'] = implode("\n", $context['files']);

$template = file_get_contents(dirname(__FILE__) . '/../package.xml.tpl');
$content = preg_replace_callback('/\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/', 'replace_parameters', $template);
$content = preg_replace_callback('/\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/', 'replace_parameters', $template);
file_put_contents(dirname(__FILE__) . '/../package.xml', $content);

function replace_parameters($matches) {
Expand Down
4 changes: 2 additions & 2 deletions examples/session.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
Requests::register_autoloader();

// Set up our session
$session = new Requests_Session('http://httpbin.org/');
$session = new Requests_Session('http://httpbin.org/');
$session->headers['Accept'] = 'application/json';
$session->useragent = 'Awesomesauce';
$session->useragent = 'Awesomesauce';

// Now let's make a request!
$request = $session->get('/get');
Expand Down
36 changes: 18 additions & 18 deletions library/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,9 @@ public static function request($url, $headers = array(), $data = array(), $type
}
}
else {
$need_ssl = (0 === stripos($url, 'https://'));
$need_ssl = (0 === stripos($url, 'https://'));
$capabilities = array('ssl' => $need_ssl);
$transport = self::get_transport($capabilities);
$transport = self::get_transport($capabilities);
}
$response = $transport->request($url, $headers, $data, $options);

Expand Down Expand Up @@ -447,7 +447,7 @@ public static function request_multiple($requests, $options = array()) {
$request['type'] = self::GET;
}
if (!isset($request['options'])) {
$request['options'] = $options;
$request['options'] = $options;
$request['options']['type'] = $request['type'];
}
else {
Expand Down Expand Up @@ -595,9 +595,9 @@ protected static function set_defaults(&$url, &$headers, &$data, &$type, &$optio
}

if ($options['idn'] !== false) {
$iri = new Requests_IRI($url);
$iri = new Requests_IRI($url);
$iri->host = Requests_IDNAEncoder::encode($iri->ihost);
$url = $iri->uri;
$url = $iri->uri;
}

// Massage the type to ensure we support it.
Expand Down Expand Up @@ -642,7 +642,7 @@ protected static function parse_response($headers, $url, $req_headers, $req_data
throw new Requests_Exception('Missing header/body separator', 'requests.no_crlf_separator');
}

$headers = substr($return->raw, 0, $pos);
$headers = substr($return->raw, 0, $pos);
$return->body = substr($return->raw, $pos + strlen("\n\r\n\r"));
}
else {
Expand All @@ -658,14 +658,14 @@ protected static function parse_response($headers, $url, $req_headers, $req_data
throw new Requests_Exception('Response could not be parsed', 'noversion', $headers);
}
$return->protocol_version = (float) $matches[1];
$return->status_code = (int) $matches[2];
$return->status_code = (int) $matches[2];
if ($return->status_code >= 200 && $return->status_code < 300) {
$return->success = true;
}

foreach ($headers as $header) {
list($key, $value) = explode(':', $header, 2);
$value = trim($value);
$value = trim($value);
preg_replace('#(\s+)#i', ' ', $value);
$return->headers[$key] = $value;
}
Expand Down Expand Up @@ -705,7 +705,7 @@ protected static function parse_response($headers, $url, $req_headers, $req_data
$return
);
$options['hooks']->dispatch('requests.before_redirect', $hook_args);
$redirected = self::request($location, $req_headers, $req_data, $options['type'], $options);
$redirected = self::request($location, $req_headers, $req_data, $options['type'], $options);
$redirected->history[] = $return;
return $redirected;
}
Expand All @@ -732,10 +732,10 @@ protected static function parse_response($headers, $url, $req_headers, $req_data
*/
public static function parse_multiple(&$response, $request) {
try {
$url = $request['url'];
$headers = $request['headers'];
$data = $request['data'];
$options = $request['options'];
$url = $request['url'];
$headers = $request['headers'];
$data = $request['data'];
$options = $request['options'];
$response = self::parse_response($response, $url, $headers, $data, $options);
}
catch (Requests_Exception $e) {
Expand Down Expand Up @@ -772,8 +772,8 @@ protected static function decode_chunked($data) {
}

$chunk_length = strlen($matches[0]);
$decoded .= substr($encoded, $chunk_length, $length);
$encoded = substr($encoded, $chunk_length + $length + 2);
$decoded .= substr($encoded, $chunk_length, $length);
$encoded = substr($encoded, $chunk_length + $length + 2);

if (trim($encoded) === '0' || empty($encoded)) {
return $decoded;
Expand Down Expand Up @@ -866,12 +866,12 @@ public static function compatible_gzinflate($gzData) {
// Compressed data might contain a full zlib header, if so strip it for
// gzinflate()
if (substr($gzData, 0, 3) == "\x1f\x8b\x08") {
$i = 10;
$i = 10;
$flg = ord(substr($gzData, 3, 1));
if ($flg > 0) {
if ($flg & 4) {
list($xlen) = unpack('v', substr($gzData, $i, 2));
$i = $i + 2 + $xlen;
$i = $i + 2 + $xlen;
}
if ($flg & 8) {
$i = strpos($gzData, "\0", $i) + 1;
Expand Down Expand Up @@ -900,7 +900,7 @@ public static function compatible_gzinflate($gzData) {
$huffman_encoded = false;

// low nibble of first byte should be 0x08
list(, $first_nibble) = unpack('h', $gzData);
list(, $first_nibble) = unpack('h', $gzData);

// First 2 bytes should be divisible by 0x1F
list(, $first_two_bytes) = unpack('n', $gzData);
Expand Down
24 changes: 12 additions & 12 deletions library/Requests/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ class Requests_Cookie {
* @param array|Requests_Utility_CaseInsensitiveDictionary $attributes Associative array of attribute data
*/
public function __construct($name, $value, $attributes = array(), $flags = array(), $reference_time = null) {
$this->name = $name;
$this->value = $value;
$this->name = $name;
$this->value = $value;
$this->attributes = $attributes;
$default_flags = array(
$default_flags = array(
'creation' => time(),
'last-access' => time(),
'persistent' => false,
'host-only' => true,
);
$this->flags = array_merge($default_flags, $flags);
$this->flags = array_merge($default_flags, $flags);

$this->reference_time = time();
if ($reference_time !== null) {
Expand Down Expand Up @@ -228,7 +228,7 @@ public function path_matches($request_path) {
public function normalize() {
foreach ($this->attributes as $key => $value) {
$orig_value = $value;
$value = $this->normalize_attribute($key, $value);
$value = $this->normalize_attribute($key, $value);
if ($value === null) {
unset($this->attributes[$key]);
continue;
Expand Down Expand Up @@ -385,7 +385,7 @@ public function __toString() {
* @return Requests_Cookie Parsed cookie object
*/
public static function parse($string, $name = '', $reference_time = null) {
$parts = explode(';', $string);
$parts = explode(';', $string);
$kvparts = array_shift($parts);

if (!empty($name)) {
Expand All @@ -397,13 +397,13 @@ public static function parse($string, $name = '', $reference_time = null) {
// (`=foo`)
//
// https://bugzilla.mozilla.org/show_bug.cgi?id=169091
$name = '';
$name = '';
$value = $kvparts;
}
else {
list($name, $value) = explode('=', $kvparts, 2);
}
$name = trim($name);
$name = trim($name);
$value = trim($value);

// Attribute key are handled case-insensitively
Expand All @@ -412,15 +412,15 @@ public static function parse($string, $name = '', $reference_time = null) {
if (!empty($parts)) {
foreach ($parts as $part) {
if (strpos($part, '=') === false) {
$part_key = $part;
$part_key = $part;
$part_value = true;
}
else {
list($part_key, $part_value) = explode('=', $part, 2);
$part_value = trim($part_value);
$part_value = trim($part_value);
}

$part_key = trim($part_key);
$part_key = trim($part_key);
$attributes[$part_key] = $part_value;
}
}
Expand Down Expand Up @@ -449,7 +449,7 @@ public static function parse_from_headers(Requests_Response_Headers $headers, Re
// Default domain/path attributes
if (empty($parsed->attributes['domain']) && !empty($origin)) {
$parsed->attributes['domain'] = $origin->host;
$parsed->flags['host-only'] = true;
$parsed->flags['host-only'] = true;
}
else {
$parsed->flags['host-only'] = false;
Expand Down
4 changes: 2 additions & 2 deletions library/Requests/Cookie/Jar.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ public function before_redirect_check(Requests_Response $return) {
$url = new Requests_IRI($url);
}

$cookies = Requests_Cookie::parse_from_headers($return->headers, $url);
$this->cookies = array_merge($this->cookies, $cookies);
$cookies = Requests_Cookie::parse_from_headers($return->headers, $url);
$this->cookies = array_merge($this->cookies, $cookies);
$return->cookies = $this;
}
}
2 changes: 1 addition & 1 deletion library/Requests/Exception/Transport/cURL.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Requests_Exception_Transport_cURL extends Requests_Exception_Transport {

const EASY = 'cURLEasy';
const EASY = 'cURLEasy';
const MULTI = 'cURLMulti';
const SHARE = 'cURLShare';

Expand Down
12 changes: 6 additions & 6 deletions library/Requests/IDNAEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,25 @@ protected static function utf8_to_codepoints($input) {
// One byte sequence:
if ((~$value & 0x80) === 0x80) {
$character = $value;
$length = 1;
$length = 1;
$remaining = 0;
}
// Two byte sequence:
elseif (($value & 0xE0) === 0xC0) {
$character = ($value & 0x1F) << 6;
$length = 2;
$length = 2;
$remaining = 1;
}
// Three byte sequence:
elseif (($value & 0xF0) === 0xE0) {
$character = ($value & 0x0F) << 12;
$length = 3;
$length = 3;
$remaining = 2;
}
// Four byte sequence:
elseif (($value & 0xF8) === 0xF0) {
$character = ($value & 0x07) << 18;
$length = 4;
$length = 4;
$remaining = 3;
}
// Invalid byte:
Expand Down Expand Up @@ -236,7 +236,7 @@ public static function punycode_encode($input) {
$h = $b = 0; // see loop
// copy them to the output in order
$codepoints = self::utf8_to_codepoints($input);
$extended = array();
$extended = array();

foreach ($codepoints as $char) {
if ($char < 128) {
Expand Down Expand Up @@ -302,7 +302,7 @@ public static function punycode_encode($input) {
break;
}
// output the code point for digit t + ((q - t) mod (base - t))
$digit = $t + (($q - $t) % (self::BOOTSTRAP_BASE - $t));
$digit = $t + (($q - $t) % (self::BOOTSTRAP_BASE - $t));
$output .= self::digit_to_char($digit);
// let q = (q - t) div (base - t)
$q = floor(($q - $t) / (self::BOOTSTRAP_BASE - $t));
Expand Down
20 changes: 10 additions & 10 deletions library/Requests/IPv6.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public static function uncompress($ip) {
}

list($ip1, $ip2) = explode('::', $ip);
$c1 = ($ip1 === '') ? -1 : substr_count($ip1, ':');
$c2 = ($ip2 === '') ? -1 : substr_count($ip2, ':');
$c1 = ($ip1 === '') ? -1 : substr_count($ip1, ':');
$c2 = ($ip2 === '') ? -1 : substr_count($ip2, ':');

if (strpos($ip2, '.') !== false) {
$c2++;
Expand All @@ -53,17 +53,17 @@ public static function uncompress($ip) {
// ::xxx
elseif ($c1 === -1) {
$fill = str_repeat('0:', 7 - $c2);
$ip = str_replace('::', $fill, $ip);
$ip = str_replace('::', $fill, $ip);
}
// xxx::
elseif ($c2 === -1) {
$fill = str_repeat(':0', 7 - $c1);
$ip = str_replace('::', $fill, $ip);
$ip = str_replace('::', $fill, $ip);
}
// xxx::xxx
else {
$fill = ':' . str_repeat('0:', 6 - $c2 - $c1);
$ip = str_replace('::', $fill, $ip);
$ip = str_replace('::', $fill, $ip);
}
return $ip;
}
Expand All @@ -84,7 +84,7 @@ public static function uncompress($ip) {
*/
public static function compress($ip) {
// Prepare the IP to be compressed
$ip = self::uncompress($ip);
$ip = self::uncompress($ip);
$ip_parts = self::split_v6_v4($ip);

// Replace all leading zeros
Expand Down Expand Up @@ -126,7 +126,7 @@ public static function compress($ip) {
*/
protected static function split_v6_v4($ip) {
if (strpos($ip, '.') !== false) {
$pos = strrpos($ip, ':');
$pos = strrpos($ip, ':');
$ipv6_part = substr($ip, 0, $pos);
$ipv4_part = substr($ip, $pos + 1);
return array($ipv6_part, $ipv4_part);
Expand All @@ -145,10 +145,10 @@ protected static function split_v6_v4($ip) {
* @return bool true if $ip is a valid IPv6 address
*/
public static function check_ipv6($ip) {
$ip = self::uncompress($ip);
$ip = self::uncompress($ip);
list($ipv6, $ipv4) = self::split_v6_v4($ip);
$ipv6 = explode(':', $ipv6);
$ipv4 = explode('.', $ipv4);
$ipv6 = explode(':', $ipv6);
$ipv4 = explode('.', $ipv4);
if (count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4) {
foreach ($ipv6 as $ipv6_part) {
// The section can't be empty
Expand Down
2 changes: 1 addition & 1 deletion library/Requests/Proxy/HTTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __construct($args = null) {
}
elseif (count($args) == 3) {
list($this->proxy, $this->user, $this->pass) = $args;
$this->use_authentication = true;
$this->use_authentication = true;
}
else {
throw new Requests_Exception('Invalid number of arguments', 'proxyhttpbadargs');
Expand Down
2 changes: 1 addition & 1 deletion library/Requests/SSL.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static function match_domain($host, $reference) {
// Also validates that the host has 3 parts or more, as per Firefox's
// ruleset.
if (ip2long($host) === false) {
$parts = explode('.', $host);
$parts = explode('.', $host);
$parts[0] = '*';
$wildcard = implode('.', $parts);
if ($wildcard === $reference) {
Expand Down
4 changes: 2 additions & 2 deletions library/Requests/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class Requests_Session {
* @param array $options Default options for requests
*/
public function __construct($url = null, $headers = array(), $data = array(), $options = array()) {
$this->url = $url;
$this->url = $url;
$this->headers = $headers;
$this->data = $data;
$this->data = $data;
$this->options = $options;

if (empty($this->options['cookies'])) {
Expand Down
Loading