Skip to content

Commit

Permalink
Merge pull request #15 from szepeviktor/fix-problems
Browse files Browse the repository at this point in the history
Fix curly braces in strings
  • Loading branch information
voku committed Jul 18, 2023
2 parents c4d6ec4 + 39b589d commit 352a962
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 24 deletions.
8 changes: 5 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
* text=auto

/examples export-ignore
/tests export-ignore
/examples/ export-ignore
/tests/ export-ignore
/build.sh export-ignore
/.editorconfig export-ignore
/.scrutinizer.yml export-ignore
/.styleci.yml export-ignore
/.gitattributes export-ignore
/.github export-ignore
/.github/ export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/circle.yml export-ignore
/phpcs.php_cs export-ignore
/phpstan.neon export-ignore
/phpunit.xml.dist export-ignore
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

## 2.4.5 (2021-09-14)

- "XmlMimeHandler" -> show the borken xml
- "XmlMimeHandler" -> show the broken xml

## 2.4.4 (2021-09-09)

Expand Down
22 changes: 9 additions & 13 deletions src/Httpful/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,10 @@ public function _curlPrep(): self
foreach ($this->headers as $header => $value) {
if (\is_array($value)) {
foreach ($value as $valueInner) {
$headers[] = "${header}: ${valueInner}";
$headers[] = "{$header}: {$valueInner}";
}
} else {
$headers[] = "${header}: ${value}";
$headers[] = "{$header}: {$value}";
}
}

Expand Down Expand Up @@ -475,7 +475,7 @@ public function _curlPrep(): self
}

$path = ($url['path'] ?? '/') . (isset($url['query']) ? '?' . $url['query'] : '');
$this->raw_headers = "{$this->method} ${path} HTTP/{$this->protocol_version}\r\n";
$this->raw_headers = "{$this->method} {$path} HTTP/{$this->protocol_version}\r\n";
$this->raw_headers .= \implode("\r\n", $headers);
$this->raw_headers .= "\r\n";

Expand Down Expand Up @@ -1586,12 +1586,9 @@ public function hasProxy(): bool
* but also by environment variable called http_proxy.
*/
return (
isset($this->additional_curl_opts[\CURLOPT_PROXY])
&&
\is_string($this->additional_curl_opts[\CURLOPT_PROXY])
)
||
\getenv('http_proxy');
isset($this->additional_curl_opts[\CURLOPT_PROXY])
&& \is_string($this->additional_curl_opts[\CURLOPT_PROXY])
) || \getenv('http_proxy');
}

/**
Expand Down Expand Up @@ -1916,7 +1913,6 @@ public function send(): Response
||
$this->curl->errorCode === \CURLE_BAD_CONTENT_ENCODING
) {

// Docs say 'identity,' but 'none' seems to work (sometimes?).
$this->curl->setOpt(\CURLOPT_ENCODING, 'none');

Expand Down Expand Up @@ -2166,7 +2162,7 @@ public function useSocks5Proxy(
*/
public function withAddedCookie(string $name, string $value): self
{
return $this->withAddedHeader('Cookie', "${name}=${value}");
return $this->withAddedHeader('Cookie', "{$name}={$value}");
}

/**
Expand Down Expand Up @@ -2431,7 +2427,7 @@ public function withContentTypeYaml(): self
*/
public function withCookie(string $name, string $value): self
{
return $this->withHeader('Cookie', "${name}=${value}");
return $this->withHeader('Cookie', "{$name}={$value}");
}

/**
Expand Down Expand Up @@ -2612,7 +2608,7 @@ public function withParseCallback(callable $callback): self
* Default null, no authentication
* @param string $auth_username Authentication username. Default null
* @param string $auth_password Authentication password. Default null
* @param int $proxy_type Proxy-Tye for Curl. Default is "Proxy::HTTP"
* @param int $proxy_type Proxy-Type for Curl. Default is "Proxy::HTTP"
*
* @return static
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Httpful/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function __construct($uri = '')
$parts = \parse_url($uri);

if ($parts === false) {
throw new \InvalidArgumentException("Unable to parse URI: ${uri}");
throw new \InvalidArgumentException("Unable to parse URI: {$uri}");
}

$this->_applyParts($parts);
Expand Down
6 changes: 3 additions & 3 deletions src/Httpful/UriResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ private static function getRelativePath(UriInterface $base, UriInterface $target
// as the first segment of a relative-path reference, as it would be mistaken for a scheme name.
/* @phpstan-ignore-next-line | FP? */
if ($relativePath === '' || \strpos(\explode('/', $relativePath, 2)[0], ':') !== false) {
$relativePath = "./${relativePath}";
$relativePath = "./{$relativePath}";
} elseif ($relativePath[0] === '/') {
if ($base->getAuthority() !== '' && $base->getPath() === '') {
// In this case an extra slash is added by resolve() automatically. So we must not add one here.
$relativePath = ".${relativePath}";
$relativePath = ".{$relativePath}";
} else {
$relativePath = "./${relativePath}";
$relativePath = "./{$relativePath}";
}
}

Expand Down
1 change: 0 additions & 1 deletion tests/Httpful/HttpfulTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,6 @@ public function testUserAgentGet()
static::assertNotContains('User-Agent: HttpFul/1.0', $r->getRawHeaders());
}


$r = Request::get('http://example.com/')
->withUserAgent('');

Expand Down
4 changes: 2 additions & 2 deletions tests/Httpful/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public function uriComponentsEncodingProvider()
// Don't encode path segments
['/pa/th//two?q=va/lue#frag/ment', '/pa/th//two', 'q=va/lue', 'frag/ment', '/pa/th//two?q=va/lue#frag/ment'],
// Don't encode unreserved chars or sub-delimiters
["/${unreserved}?${unreserved}#${unreserved}", "/${unreserved}", $unreserved, $unreserved, "/${unreserved}?${unreserved}#${unreserved}"],
["/{$unreserved}?{$unreserved}#{$unreserved}", "/{$unreserved}", $unreserved, $unreserved, "/{$unreserved}?{$unreserved}#{$unreserved}"],
// Encoded unreserved chars are not decoded
['/p%61th?q=v%61lue#fr%61gment', '/p%61th', 'q=v%61lue', 'fr%61gment', '/p%61th?q=v%61lue#fr%61gment'],
];
Expand Down Expand Up @@ -451,7 +451,7 @@ public function testAddsSlashForRelativeUriStringWithHost()
static::assertSame('//example.com/foo', (string) $uri);
}

public function testRemoveExtraSlashesWihoutHost()
public function testRemoveExtraSlashesWithoutHost()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The path of a URI without an authority must not start with two slashes');
Expand Down

0 comments on commit 352a962

Please sign in to comment.