for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Akibatech\FreeMobileSms;
/**
* Class CurlClient
*
* @package Akibatech\FreeMobileSms
*/
class CurlClient
{
* @var resource cURL handle
private $resource;
* @var int
private $response;
* Constructor.
* @param string $url
* @param array $options
* @return self
@return
Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.
Please refer to the PHP core documentation on constructors.
public function __construct($url, array $options = [])
$this->resource = curl_init();
$query = http_build_query($options);
$url .= '?' . $query;
$this->addOption(CURLOPT_URL, $url);
$this->addOption(CURLOPT_RETURNTRANSFER, false);
false
boolean
string
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example:
function acceptsInteger($int) { } $x = '123'; // string "123" // Instead of acceptsInteger($x); // we recommend to use acceptsInteger((integer) $x);
}
//-------------------------------------------------------------------------
* Add an option.
* @param string $key
* @param string $value
* @return $this
public function addOption($key, $value)
curl_setopt($this->resource, $key, $value);
return $this;
* Get the response
* @param void
* @return int
* @throws \RuntimeException On cURL error
public function hit()
if (is_null($this->response) === false)
return $this->response;
curl_exec($this->resource);
$error = curl_error($this->resource);
$errno = curl_errno($this->resource);
$response = (int)curl_getinfo($this->resource, CURLINFO_HTTP_CODE);
if (is_resource($this->resource))
curl_close($this->resource);
if (0 !== $errno)
throw new \RuntimeException($error, $errno);
$this->response = $response;
return $response;
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.