Code style changes

This commit is contained in:
Ismo Vuorinen
2023-03-09 14:40:55 +02:00
parent 12350f6c0a
commit 7e67ef3c95
2 changed files with 21 additions and 20 deletions

View File

@@ -194,7 +194,7 @@ class Curly
*/ */
public function __destruct() public function __destruct()
{ {
if ($this->ch !== null) { if ($this->ch !== false) {
$this->closeTransport(); $this->closeTransport();
} }
} }
@@ -304,6 +304,7 @@ class Curly
return $this; return $this;
} }
/** /**
* @return array|string[] * @return array|string[]
*/ */
@@ -354,7 +355,7 @@ class Curly
{ {
$this->ch = curl_init(); $this->ch = curl_init();
if (!$this->ch) { if ($this->ch === false) {
throw new Exceptions\HTTPException("Could not init data channel"); throw new Exceptions\HTTPException("Could not init data channel");
} }
@@ -408,7 +409,7 @@ class Curly
return false; return false;
} }
return match ($this->httpVersion) { match ($this->httpVersion) {
'1.0' => curl_setopt( '1.0' => curl_setopt(
$this->ch, $this->ch,
CURLOPT_HTTP_VERSION, CURLOPT_HTTP_VERSION,
@@ -425,6 +426,8 @@ class Curly
CURL_HTTP_VERSION_NONE CURL_HTTP_VERSION_NONE
), ),
}; };
return true;
} }
private function initCurlAuthenticationMethod(): void private function initCurlAuthenticationMethod(): void
@@ -510,6 +513,7 @@ class Curly
} }
switch ($this->method) { switch ($this->method) {
default:
case 'GET': case 'GET':
$payload = empty($data) $payload = empty($data)
? $this->address ? $this->address
@@ -520,8 +524,7 @@ class Curly
CURLOPT_URL, CURLOPT_URL,
$payload $payload
); );
break;
return;
case 'PUT': case 'PUT':
curl_setopt( curl_setopt(
@@ -549,7 +552,7 @@ class Curly
$this->address $this->address
); );
return; break;
case 'POST': case 'POST':
curl_setopt( curl_setopt(
@@ -576,7 +579,7 @@ class Curly
$this->address $this->address
); );
return; break;
case 'DELETE': case 'DELETE':
curl_setopt( curl_setopt(
@@ -604,7 +607,7 @@ class Curly
$this->address $this->address
); );
return; break;
} }
} }
@@ -803,10 +806,10 @@ class Curly
* Send data via STREAM * Send data via STREAM
* *
* @uses \League\Uri\Uri * @uses \League\Uri\Uri
* @uses \League\Uri\Uri
* @return string * @return string
* *
* @throws Exceptions\HTTPException * @throws Exceptions\HTTPException
* @uses \League\Uri\Uri
*/ */
private function sendUsingStream(): string private function sendUsingStream(): string
{ {
@@ -876,7 +879,7 @@ class Curly
3 3
); );
$this->receivedHttpStatus = (int) $receivedHttpStatus; $this->receivedHttpStatus = (int)$receivedHttpStatus;
unset($version, $msg); unset($version, $msg);
@@ -970,9 +973,11 @@ class Curly
if (!in_array($method, $this->supportedHttpMethods, true)) { if (!in_array($method, $this->supportedHttpMethods, true)) {
throw new Exceptions\HTTPException( throw new Exceptions\HTTPException(
"Unsupported HTTP method: " . $method sprintf(
. '. Should be one of: ' "Unsupported HTTP method: %s. Should be one of: %s",
. implode(', ', $this->supportedHttpMethods) $method,
implode(', ', $this->supportedHttpMethods)
)
); );
} }
@@ -1016,7 +1021,7 @@ class Curly
* Set HTTP method to use * Set HTTP method to use
* *
* @param string $address Proxy URL or IP address * @param string $address Proxy URL or IP address
* @param string|null $user (optional) User name for proxy auth * @param string|null $user (optional) Username for proxy auth
* @param string|null $pass (optional) User password for proxy auth * @param string|null $pass (optional) User password for proxy auth
* *
* @return self * @return self

View File

@@ -12,8 +12,6 @@ class CurlyBasicsTest extends TestCase
* This is just a simple check to make sure your library has no * This is just a simple check to make sure your library has no
* syntax error. This helps you troubleshoot any typo before you * syntax error. This helps you troubleshoot any typo before you
* even use this library in a real project. * even use this library in a real project.
*
* @throws \ivuorinen\Curly\Exceptions\HTTPException
*/ */
public function testIsThereAnySyntaxError(): void public function testIsThereAnySyntaxError(): void
{ {
@@ -28,8 +26,6 @@ class CurlyBasicsTest extends TestCase
* This is just a simple check to make sure your library has no * This is just a simple check to make sure your library has no
* syntax error. This helps you troubleshoot any typo before you * syntax error. This helps you troubleshoot any typo before you
* even use this library in a real project. * even use this library in a real project.
*
* @throws \ivuorinen\Curly\Exceptions\HTTPException
*/ */
public function testParseData(): void public function testParseData(): void
{ {