Skip to content
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
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"type": "library",
"license": "MIT",
"require": {
"php": ">=8.0"
"php": ">=8.1"
},
"require-dev": {
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.5",
"laravel/pint": "^1.5.0",
"phpstan/phpstan": "^1.10"
"laravel/pint": "^1.5.0"
},
"scripts": {
"lint": "./vendor/bin/pint --test --config pint.json",
Expand Down
23 changes: 23 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,29 @@ public function addHeader(string $key, string $value): self
return $this;
}

/**
* Remove a specific header.
*
* @param string $key
* @return self
*/
public function removeHeader(string $key): self
{
unset($this->headers[strtolower($key)]);
return $this;
}

/**
* Clear all headers.
*
* @return self
*/
public function clearHeaders(): self
{
$this->headers = [];
return $this;
}

/**
* Set the request timeout.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function __construct($message)
{
parent::__construct($message); // Call the parent constructor
}
public function __toString()
public function __toString(): string
{
return __CLASS__ . " {$this->message}\n"; // Return the class name, code and message
}
Expand Down
24 changes: 13 additions & 11 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(
$this->headers = $headers;
$this->statusCode = $statusCode;
}
# Getters

/**
* This method is used to get the response body as string
* @return mixed
Expand All @@ -55,6 +55,7 @@ public function getBody(): mixed
{
return $this->body;
}

/**
* This method is used to get the response headers
* @return array<string, string>
Expand All @@ -63,6 +64,7 @@ public function getHeaders(): array
{
return $this->headers;
}

/**
* This method is used to get the response status code
* @return int
Expand All @@ -71,19 +73,19 @@ public function getStatusCode(): int
{
return $this->statusCode;
}
// Methods

/**
* This method is used to convert the response body to text
* @return string
*/
* This method is used to convert the response body to text
* @return string
*/
public function text(): string
{
return \strval($this->body);
}

/**
* This method is used to convert the response body to JSON
* @return mixed
* This method is used to convert the response body to JSON
* @return mixed
*/
public function json(): mixed
{
Expand All @@ -94,10 +96,10 @@ public function json(): mixed
return $data;
}

/*
* This method is used to convert the response body to blob
* @return string
*/
/**
* This method is used to convert the response body to blob
* @return string
*/
public function blob(): string
{
$bin = "";
Expand Down