Skip to content

Commit

Permalink
Performance speedup
Browse files Browse the repository at this point in the history
Direct comparison is faster

Type casting is faster
  • Loading branch information
mrcnpdlk authored and staabm committed Dec 10, 2018
1 parent fc1c64b commit 69be093
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/Auth/AWS.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function init(): bool
{
$authHeader = $this->request->getHeader('Authorization');

if (is_null($authHeader)) {
if ($authHeader === null) {
$this->errorCode = self::ERR_NOAWSHEADER;

return false;
Expand Down
6 changes: 3 additions & 3 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function poll(): bool
);

if ($status && CURLMSG_DONE === $status['msg']) {
$resourceId = intval($status['handle']);
$resourceId = (int)$status['handle'];
list(
$request,
$successCallback,
Expand Down Expand Up @@ -461,7 +461,7 @@ protected function parseCurlResult(string $response, $curlHandle): array

$response->setBody($responseBody);

$httpCode = intval($response->getStatus());
$httpCode = (int)$response->getStatus();

return [
'status' => $httpCode >= 400 ? self::STATUS_HTTPERROR : self::STATUS_SUCCESS,
Expand All @@ -487,7 +487,7 @@ protected function sendAsyncInternal(RequestInterface $request, callable $succes
$this->createCurlSettingsArray($request)
);
curl_multi_add_handle($this->curlMultiHandle, $curl);
$this->curlMultiMap[intval($curl)] = [
$this->curlMultiMap[(int)$curl] = [
$request,
$success,
$error,
Expand Down
6 changes: 3 additions & 3 deletions lib/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getBodyAsStream()
if (is_callable($this->body)) {
$body = $this->getBodyAsString();
}
if (is_string($body) || is_null($body)) {
if (is_string($body) || $body === null) {
$stream = fopen('php://temp', 'r+');
fwrite($stream, (string) $body);
rewind($stream);
Expand All @@ -75,7 +75,7 @@ public function getBodyAsString(): string
if (is_string($body)) {
return $body;
}
if (is_null($body)) {
if ($body === null) {
return '';
}
if (is_callable($body)) {
Expand Down Expand Up @@ -220,7 +220,7 @@ public function setHeaders(array $headers)
* another value. Individual values can be retrieved with
* getHeadersAsArray.
*
* @param scalar $value
* @param string|string[] $value
*/
public function addHeader(string $name, $value)
{
Expand Down
6 changes: 3 additions & 3 deletions lib/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ class Response extends Message implements ResponseInterface
*/
public function __construct($status = 500, array $headers = null, $body = null)
{
if (!is_null($status)) {
if ($status !== null) {
$this->setStatus($status);
}
if (!is_null($headers)) {
if ($headers !== null) {
$this->setHeaders($headers);
}
if (!is_null($body)) {
if ($body !== null) {
$this->setBody($body);
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Sapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static function sendResponse(ResponseInterface $response)
}

$body = $response->getBody();
if (is_null($body)) {
if ($body === null) {
return;
}

Expand Down Expand Up @@ -199,11 +199,11 @@ public static function createFromServerArray(array $serverArray): Request
}
}

if (is_null($url)) {
if ($url === null) {
throw new InvalidArgumentException('The _SERVER array must have a REQUEST_URI key');
}

if (is_null($method)) {
if ($method === null) {
throw new InvalidArgumentException('The _SERVER array must have a REQUEST_METHOD key');
}
$r = new Request($method, $url, $headers);
Expand Down
2 changes: 1 addition & 1 deletion lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function negotiateContentType($acceptHeaderValue, array $availableOptions)

foreach ($proposals as $proposal) {
// Ignoring broken values.
if (is_null($proposal)) {
if ($proposal === null) {
continue;
}

Expand Down

0 comments on commit 69be093

Please sign in to comment.