diff --git a/README.md b/README.md index e885c50..fa1caf9 100755 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ This package is compatible with PHP 5.6+. ## How to install it ? -Todo: Composer via packagist +composer require 202ecommerce/bridge-sdk To use this package with php 5.6 or in production mode, please install this dependency with : diff --git a/bridgesdk.zip b/bridgesdk.zip deleted file mode 100644 index f70c557..0000000 Binary files a/bridgesdk.zip and /dev/null differ diff --git a/composer.json b/composer.json index f0badc3..d33957c 100755 --- a/composer.json +++ b/composer.json @@ -35,9 +35,6 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.4", - "psr/log": "^1.0", - "psr/http-message": "^1.0", - "psr/cache": "^1.0.0", "phpunit/phpunit": "^9.0", "phpstan/phpstan": "^0.12.81" }, diff --git a/gitrepo.zip b/gitrepo.zip deleted file mode 100644 index 6c07c57..0000000 Binary files a/gitrepo.zip and /dev/null differ diff --git a/src/Client.php b/src/Client.php index 5e58ca0..a5e1f01 100644 --- a/src/Client.php +++ b/src/Client.php @@ -23,8 +23,6 @@ use BridgeSDK\Response\WebhookResponse; use InvalidArgumentException; use Logger\NullLogger; -use Psr\Http\Message\RequestInterface; -use Psr\Log\LoggerInterface; use RuntimeException; use UnexpectedValueException; @@ -48,7 +46,7 @@ class Client protected $options; /** - * @var LoggerInterface + * @var mixed */ protected $logger; @@ -89,13 +87,16 @@ public function __construct() } /** - * Send a PSR-7 Request. + * Send a Request * - * @return AbstractResponse + * @param AbstractRequest $request + * @param mixed $additionnalHeaders + * + * @return Response\AbstractResponse * - * @throws RequestException Invalid request + * @throws RequestException Invalid request * @throws InvalidArgumentException Invalid header names and/or values - * @throws RuntimeException Failure to create stream + * @throws RuntimeException Failure to create stream */ public function sendRequest(AbstractRequest $request) { @@ -217,7 +218,7 @@ public function setVersion($version) } /** - * @param LoggerInterface $logger + * @param mixed $logger * * @return Client */ @@ -261,14 +262,14 @@ protected function createResponse($request) } /** - * Create array of headers to pass to CURLOPT_HTTPHEADER. + * Create array of headers to pass to CURLOPT_HTTPHEADER * - * @param RequestInterface $request Request object - * @param array $options cURL options + * @param AbstractRequest $request Request object + * @param array $options cURL options * * @return array Array of http header lines */ - protected function createHeaders(RequestInterface $request, array $options) + protected function createHeaders(AbstractRequest $request, array $options) { $headers = []; $request_headers = $request->getHeaders(); @@ -303,15 +304,18 @@ protected function createHeaders(RequestInterface $request, array $options) } /** - * Create cURL request options. + * Create cURL request options + * + * @param AbstractRequest $request + * @param ResponseBuilder $response * * @return array cURL options * - * @throws RequestException Invalid request + * @throws RequestException Invalid request * @throws InvalidArgumentException Invalid header names and/or values - * @throws RuntimeException Unable to read request body + * @throws RuntimeException Unable to read request body */ - protected function createOptions(RequestInterface $request, ResponseBuilder $response) + protected function createOptions(AbstractRequest $request, ResponseBuilder $response) { $options = $this->options; @@ -363,14 +367,14 @@ protected function createOptions(RequestInterface $request, ResponseBuilder $res } /** - * Add cURL options related to the request body. + * Add cURL options related to the request body * - * @param RequestInterface $request Request object - * @param array $options cURL options + * @param AbstractRequest $request Request object + * @param array $options cURL options * * @return mixed */ - protected function addRequestBodyOptions(RequestInterface $request, array $options) + protected function addRequestBodyOptions(AbstractRequest $request, array $options) { /* * HTTP methods that cannot have payload: diff --git a/src/Exception/RequestException.php b/src/Exception/RequestException.php index 942e004..a083f84 100755 --- a/src/Exception/RequestException.php +++ b/src/Exception/RequestException.php @@ -15,42 +15,42 @@ namespace BridgeSDK\Exception; +use BridgeSDK\Request\AbstractRequest; use Exception; -use Psr\Http\Message\RequestInterface; use RuntimeException; /** - * Request Exception. + * Request Exception * * Failed http request exception class */ class RequestException extends RuntimeException { /** - * Request object. + * Request object * - * @var RequestInterface + * @var AbstractRequest */ private $request; /** - * Create request exception object. + * Create request exception object * - * @param string $message Exception message - * @param RequestInterface $request Request object - * @param null|\Exception $lastException Previous exception object + * @param string $message Exception message + * @param AbstractRequest $request Request object + * @param \Exception|null $last_exception Previous exception object */ - public function __construct($message, RequestInterface $request, Exception $lastException = null) + public function __construct($message, AbstractRequest $request, ?Exception $last_exception) { $this->request = $request; - parent::__construct($message, 0, $lastException); + parent::__construct($message, 0, $last_exception); } /** - * Get the request object. + * Get the request object * - * @return RequestInterface + * @return AbstractRequest */ public function getRequest() { diff --git a/src/Logger/NullLogger.php b/src/Logger/NullLogger.php index b11a783..cd7bd8c 100755 --- a/src/Logger/NullLogger.php +++ b/src/Logger/NullLogger.php @@ -15,9 +15,7 @@ namespace Logger; -use Psr\Log\LoggerInterface; - -class NullLogger implements LoggerInterface +class NullLogger { public function emergency($message, array $context = []) { diff --git a/src/Request/AbstractRequest.php b/src/Request/AbstractRequest.php index 3346ee3..ec638c0 100755 --- a/src/Request/AbstractRequest.php +++ b/src/Request/AbstractRequest.php @@ -19,12 +19,11 @@ use BridgeSDK\Stream; use BridgeSDK\Uri\ApiUri; use JsonSerializable; -use Psr\Http\Message\RequestInterface; /** * API client. */ -abstract class AbstractRequest implements RequestInterface, JsonSerializable +abstract class AbstractRequest implements JsonSerializable { use MessageTrait; use RequestTrait; diff --git a/src/Request/MessageTrait.php b/src/Request/MessageTrait.php index f91d230..da3a911 100755 --- a/src/Request/MessageTrait.php +++ b/src/Request/MessageTrait.php @@ -16,7 +16,6 @@ namespace BridgeSDK\Request; use BridgeSDK\Stream; -use Psr\Http\Message\StreamInterface; /** * Trait implementing functionality common to requests and responses. @@ -38,7 +37,7 @@ trait MessageTrait /** @var string */ protected $protocol = '1.1'; - /** @var null|StreamInterface */ + /** @var null|Stream */ protected $stream; /** @@ -184,7 +183,7 @@ public function getBody() /** * @inherit */ - public function withBody(StreamInterface $body) + public function withBody(Stream $body) { if ($body === $this->stream) { return $this; diff --git a/src/Request/RequestTrait.php b/src/Request/RequestTrait.php index 4cc09dc..d620a9d 100755 --- a/src/Request/RequestTrait.php +++ b/src/Request/RequestTrait.php @@ -15,8 +15,6 @@ namespace BridgeSDK\Request; -use Psr\Http\Message\UriInterface; - /** * @internal should not be used outside of BridgeSDK as it does not fall under our BC promise */ @@ -28,7 +26,7 @@ trait RequestTrait /** @var null|string */ protected $requestTarget; - /** @var UriInterface */ + /** @var array|mixed|void|bool|null */ protected $uri; public function getRequestTarget() @@ -81,7 +79,7 @@ public function getUri() return $this->uri; } - public function withUri(UriInterface $uri, $preserveHost = false) + public function withUri($uri, $preserveHost = false) { if ($uri === $this->uri) { return $this; diff --git a/src/Response/AbstractResponse.php b/src/Response/AbstractResponse.php index 84f91b5..f8bc13d 100644 --- a/src/Response/AbstractResponse.php +++ b/src/Response/AbstractResponse.php @@ -20,13 +20,11 @@ use BridgeSDK\Request\MessageTrait; use BridgeSDK\Stream; use JsonSerializable; -use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\StreamInterface; /** - * API client. + * API client */ -abstract class AbstractResponse implements ResponseInterface, JsonSerializable +abstract class AbstractResponse implements JsonSerializable { use MessageTrait; @@ -35,6 +33,41 @@ abstract class AbstractResponse implements ResponseInterface, JsonSerializable */ protected $body; + /** @var string[] */ + private $error = []; + + /** + * Get body + * + * @return AbstractModel|ArrayCollection + */ + abstract public function getModel(); + + /** + * Gets the body of the message. + * + * @return Stream|null Returns the body as a stream. + */ + public function getBody() + { + return $this->stream; + } + + /** + * Set body + * + * @param string $body + * + * @return self + */ + public function setBody($body) + { + $jsonBody = json_decode($body, true); + $this->body = $jsonBody; + + return $this; + } + /** @var array Map of standard HTTP status code/reason phrases */ private static $PHRASES = [ 100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing', @@ -47,18 +80,15 @@ abstract class AbstractResponse implements ResponseInterface, JsonSerializable /** @var string */ private $reasonPhrase = ''; - /** @var string[] */ - private $error = []; - /** @var int */ private $statusCode; /** - * @param int $status Status code - * @param array $headers Response headers - * @param null|resource|StreamInterface|string $body Response body - * @param string $version Protocol version - * @param null|string $reason Reason phrase (when empty a default will be used based on the status code) + * @param int $status Status code + * @param array $headers Response headers + * @param string|resource|Stream|null $body Response body + * @param string $version Protocol version + * @param string|null $reason Reason phrase (when empty a default will be used based on the status code) */ public function __construct($status = 200, array $headers = [], $body = null, $version = '1.1', $reason = null) { @@ -79,59 +109,48 @@ public function __construct($status = 200, array $headers = [], $body = null, $v } /** - * Get body. - * - * @return null|AbstractModel|ArrayCollection + * @return int */ - abstract public function getModel(); + public function getStatusCode() + { + return $this->statusCode; + } /** - * Gets the body of the message. - * - * @param mixed $returnStream - * - * @return null|AbstractModel|StreamInterface returns the body as a stream + * @return string */ - public function getBody($returnStream = true) + public function getReasonPhrase() { - return true === $returnStream ? $this->stream : $this->body; + return $this->reasonPhrase; } /** - * Set body. - * - * @param string $body + * @param int $code Status code + * @param string $reasonPhrase Reason * * @return self */ - public function setBody($body) + public function withStatus($code, $reasonPhrase = '') { - $jsonBody = json_decode($body); - $this->body = $jsonBody; - - return $this; - } + $code = (int) $code; + if ($code < 100 || $code > 599) { + throw new \InvalidArgumentException(\sprintf('Status code has to be an integer between 100 and 599. A status code of %d was given', $code)); + } - /** - * @inherit - */ - public function getStatusCode() - { - return $this->statusCode; - } + $new = clone $this; + $new->statusCode = $code; + if (empty($reasonPhrase) === true && isset(self::$PHRASES[$new->statusCode])) { + $reasonPhrase = self::$PHRASES[$new->statusCode]; + } + $new->reasonPhrase = $reasonPhrase; - /** - * @inherit - */ - public function getReasonPhrase() - { - return $this->reasonPhrase; + return $new; } /** - * @inherit + * Get the value of error * - * @return mixed + * @return mixed */ public function getError() { @@ -139,42 +158,19 @@ public function getError() } /** - * @inherit + * Set the value of error * - * @param mixed $errors + * @param mixed $error * - * @return self + * @return self */ - public function setError($errors) + public function setError($error) { - $this->error = $errors; + $this->error = $error; return $this; } - /** - * @inherit - * - * @param mixed $code - * @param mixed $reasonPhrase - */ - public function withStatus($code, $reasonPhrase = '') - { - $code = (int) $code; - if ($code < 100 || $code > 599) { - throw new \InvalidArgumentException(sprintf('Status code has to be an integer between 100 and 599. A status code of %d was given', $code)); - } - - $new = clone $this; - $new->statusCode = $code; - if (true === empty($reasonPhrase) && isset(self::$PHRASES[$new->statusCode])) { - $reasonPhrase = self::$PHRASES[$new->statusCode]; - } - $new->reasonPhrase = $reasonPhrase; - - return $new; - } - /** * {@inheritdoc} */ diff --git a/src/Response/ResponseBuilder.php b/src/Response/ResponseBuilder.php index 3aade59..de75b97 100644 --- a/src/Response/ResponseBuilder.php +++ b/src/Response/ResponseBuilder.php @@ -20,12 +20,12 @@ /** * Response Builder. * - * Build a PSR-7 Response object + * Build a Response object */ class ResponseBuilder { /** - * PSR-7 Response. + * Response. * * @var AbstractResponse */ @@ -119,7 +119,7 @@ public function setHeadersFromArray(array $headers) } /** - * Set reponse status. + * Set response status. * * @param string $statusLine Response status line string * diff --git a/src/Stream.php b/src/Stream.php index 43653e5..d910675 100644 --- a/src/Stream.php +++ b/src/Stream.php @@ -15,32 +15,28 @@ namespace BridgeSDK; -use function clearstatcache; - use Exception; +use InvalidArgumentException; +use RuntimeException; +use function clearstatcache; use function fclose; use function feof; use function fseek; use function fstat; use function ftell; - -use InvalidArgumentException; -use Psr\Http\Message\StreamInterface; -use Psr\Http\Message\UriInterface; -use RuntimeException; +use function is_resource; +use function var_export; use const SEEK_CUR; use const SEEK_SET; -use function var_export; - /** - * @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md + * @final This class should never be extended */ -class Stream implements StreamInterface +class Stream { - /** @var null|resource A resource reference */ + /** @var resource|null A resource reference */ private $stream; /** @var bool */ @@ -52,10 +48,10 @@ class Stream implements StreamInterface /** @var bool */ private $writable; - /** @var null|array|bool|mixed|void */ + /** @var array|mixed|void|bool|null */ private $uri; - /** @var null|int */ + /** @var int|null */ private $size; /** @var array Hash of readable and writable stream types */ @@ -75,42 +71,17 @@ class Stream implements StreamInterface ]; /** - * Closes the stream when the destructed. - */ - public function __destruct() - { - $this->close(); - } - - /** - * @return string - * - * @throws Exception - */ - public function __toString() - { - if ($this->isSeekable()) { - $this->seek(0); - } - - return $this->getContents(); - } - - /** - * Creates a new PSR-7 stream. + * Creates a new stream. * - * @param resource|StreamInterface|string $body + * @param string|resource $body * - * @return StreamInterface + * @return self */ public static function create($body = '') { - if ($body instanceof StreamInterface) { - return $body; - } - if (\is_string($body)) { + if (is_string($body)) { $resource = fopen('php://temp', 'rw+'); - if (false === $resource) { + if ($resource === false) { $new = new self(); $new->stream = null; @@ -120,7 +91,7 @@ public static function create($body = '') $body = $resource; } - if (\is_resource($body)) { + if (is_resource($body)) { $new = new self(); $new->stream = $body; $meta = stream_get_meta_data($new->stream); @@ -132,14 +103,40 @@ public static function create($body = '') } throw new InvalidArgumentException( - 'Body must be a resource but '.\gettype($body).' is given.' + 'Body must be a ressource but ' . gettype($body) . ' is given.' ); } + /** + * Closes the stream when the destructed. + * + * @return void + */ + public function __destruct() + { + $this->close(); + } + + /** + * @return string + * @throws Exception + */ + public function __toString() + { + if ($this->isSeekable()) { + $this->seek(0); + } + + return $this->getContents(); + } + + /** + * @return void + */ public function close() { if (isset($this->stream)) { - if (\is_resource($this->stream)) { + if (is_resource($this->stream)) { fclose($this->stream); } $this->detach(); @@ -147,7 +144,7 @@ public function close() } /** - * @return null|resource + * @return resource|null */ public function detach() { @@ -156,15 +153,28 @@ public function detach() } $result = $this->stream; - $this->stream = null; + unset($this->stream); $this->size = $this->uri = null; $this->readable = $this->writable = $this->seekable = false; return $result; } + /** + * get Uri + * + * @return array|mixed|void|bool|null + */ + private function getUri() + { + if (false !== $this->uri) { + $this->uri = empty($this->getMetadata('uri')) ? false : $this->getMetadata('uri'); + } + + return $this->uri; + } /** - * @return null|int|mixed + * @return int|mixed|null */ public function getSize() { @@ -177,12 +187,12 @@ public function getSize() } // Clear the stat cache if the stream has a URI - if (false === empty($uri = $this->getUri())) { + if (empty($uri = $this->getUri()) === false) { clearstatcache(true, $uri); } $stats = (array) fstat($this->stream); - if (false === empty($stats['size'])) { + if (empty($stats['size']) === false) { $this->size = $stats['size']; return $this->size; @@ -204,7 +214,7 @@ public function tell() throw new RuntimeException( sprintf( 'Unable to determine stream position: %s', - false === empty(error_get_last()) ? error_get_last()['message'] : '' + empty(error_get_last()) === false ? error_get_last()['message'] : '' ) ); } @@ -229,7 +239,7 @@ public function isSeekable() } /** - * Seek on stream. + * Seek on stream * * @param int $offset * @param int $whence @@ -249,12 +259,12 @@ public function seek($offset, $whence = SEEK_SET) } if (-1 === fseek($this->stream, $offset, $whence)) { - throw new RuntimeException('Unable to seek to stream position "'.$offset.'" with whence '.var_export($whence, true)); + throw new RuntimeException('Unable to seek to stream position "' . $offset . '" with whence ' . var_export($whence, true)); } } /** - * Rewind stream. + * Rewind stream * * @return void */ @@ -295,7 +305,7 @@ public function write($string) throw new RuntimeException( sprintf( 'Unable to write stream position: %s', - false === empty(error_get_last()) ? error_get_last()['message'] : '' + empty(error_get_last()) === false ? error_get_last()['message'] : '' ) ); } @@ -332,7 +342,7 @@ public function read($length) throw new RuntimeException( sprintf( 'Unable to read from stream: %s', - false === empty(error_get_last()) ? error_get_last()['message'] : '' + empty(error_get_last()) === false ? error_get_last()['message'] : '' ) ); } @@ -352,7 +362,7 @@ public function getContents() throw new RuntimeException( sprintf( 'Unable to read from stream: %s', - false === empty(error_get_last()) ? error_get_last()['message'] : '' + empty(error_get_last()) === false ? error_get_last()['message'] : '' ) ); } @@ -363,7 +373,7 @@ public function getContents() /** * @param string $key * - * @return null|array|mixed + * @return array|mixed|null */ public function getMetadata($key = null) { @@ -377,20 +387,6 @@ public function getMetadata($key = null) return $meta; } - return $meta[$key] ? null : $meta[$key]; - } - - /** - * get Uri. - * - * @return UriInterface - */ - private function getUri() - { - if (false !== $this->uri) { - $this->uri = empty($this->getMetadata('uri')) ? false : $this->getMetadata('uri'); - } - - return $this->uri; + return isset($meta[$key]) ? $meta[$key] : null; } } diff --git a/src/Uri/AbstractUri.php b/src/Uri/AbstractUri.php index 3f3d1e4..e1eaf9c 100644 --- a/src/Uri/AbstractUri.php +++ b/src/Uri/AbstractUri.php @@ -15,13 +15,20 @@ namespace BridgeSDK\Uri; -use Psr\Http\Message\UriInterface; - /** - * Uri. + * Uri */ -abstract class AbstractUri implements UriInterface +abstract class AbstractUri { + /** @var array SCHEMES. */ + private static $SCHEMES = ['http' => 80, 'https' => 443]; + + /** @var string CHAR_UNRESERVED. */ + private static $CHAR_UNRESERVED = 'a-zA-Z0-9_\-\.~'; + + /** @var string CHAR_SUB_DELIMS. */ + private static $CHAR_SUB_DELIMS = '!\$&\'\(\)\*\+,;='; + /** @var string Uri scheme. */ protected $scheme = 'https'; @@ -44,47 +51,33 @@ abstract class AbstractUri implements UriInterface protected $fragment = ''; /** - * @var string - */ - protected $version = ''; - - /** @var array SCHEMES. */ - private static $SCHEMES = ['http' => 80, 'https' => 443]; - - /** @var string CHAR_UNRESERVED. */ - private static $CHAR_UNRESERVED = 'a-zA-Z0-9_\-\.~'; - - /** @var string CHAR_SUB_DELIMS. */ - private static $CHAR_SUB_DELIMS = '!\$&\'\(\)\*\+,;='; - - /** - * Constructor. + * Constructor * * @param string $uri uri */ public function __construct($uri = '') { if ('' !== $uri) { - if (false === $parts = parse_url($uri)) { - throw new \InvalidArgumentException(sprintf('Unable to parse URI: "%s"', $uri)); + if (false === $parts = \parse_url($uri)) { + throw new \InvalidArgumentException(\sprintf('Unable to parse URI: "%s"', $uri)); } // Apply parse_url parts to a URI. - $this->scheme = isset($parts['scheme']) ? strtr($parts['scheme'], 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') : ''; + $this->scheme = isset($parts['scheme']) ? \strtr($parts['scheme'], 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') : ''; $this->userInfo = empty($parts['user']) ? '' : $parts['user']; - $this->host = isset($parts['host']) ? strtr($parts['host'], 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') : ''; + $this->host = isset($parts['host']) ? \strtr($parts['host'], 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') : ''; $this->port = isset($parts['port']) ? $this->filterPort($parts['port']) : null; $this->path = isset($parts['path']) ? $this->filterPath($parts['path']) : ''; $this->query = isset($parts['query']) ? $this->filterQueryAndFragment($parts['query']) : ''; $this->fragment = isset($parts['fragment']) ? $this->filterQueryAndFragment($parts['fragment']) : ''; if (isset($parts['pass'])) { - $this->userInfo .= ':'.$parts['pass']; + $this->userInfo .= ':' . $parts['pass']; } } } /** - * __toString. + * __toString * * @return string */ @@ -94,7 +87,7 @@ public function __toString() } /** - * Get Scheme. + * Get Scheme * * @return string */ @@ -104,7 +97,7 @@ public function getScheme() } /** - * @inherit + * @return string */ public function getAuthority() { @@ -114,18 +107,18 @@ public function getAuthority() $authority = $this->host; if ('' !== $this->userInfo) { - $authority = $this->userInfo.'@'.$authority; + $authority = $this->userInfo . '@' . $authority; } if (null !== $this->port) { - $authority .= ':'.$this->port; + $authority .= ':' . $this->port; } return $authority; } /** - * @inherit + * @return string */ public function getUserInfo() { @@ -133,7 +126,7 @@ public function getUserInfo() } /** - * @inherit + * @return string */ public function getHost() { @@ -141,7 +134,7 @@ public function getHost() } /** - * @inherit + * @return null|int */ public function getPort() { @@ -149,7 +142,7 @@ public function getPort() } /** - * @inherit + * @return string */ public function getPath() { @@ -157,7 +150,7 @@ public function getPath() } /** - * @inherit + * @return string */ public function getQuery() { @@ -165,7 +158,7 @@ public function getQuery() } /** - * @inherit + * @return string */ public function getFragment() { @@ -173,9 +166,8 @@ public function getFragment() } /** - * @inherit - * - * @param mixed $scheme + * @param mixed $scheme + * @return self */ public function withScheme($scheme) { @@ -183,7 +175,7 @@ public function withScheme($scheme) throw new \InvalidArgumentException('Scheme must be a string'); } - if ($this->scheme === $scheme = strtr($scheme, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')) { + if ($this->scheme === $scheme = \strtr($scheme, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')) { return $this; } @@ -195,16 +187,15 @@ public function withScheme($scheme) } /** - * @inherit - * - * @param mixed $user - * @param null|mixed $password + * @param mixed $user + * @param mixed $password + * @return self */ public function withUserInfo($user, $password = null) { $info = $user; if (null !== $password && '' !== $password) { - $info .= ':'.$password; + $info .= ':' . $password; } if ($this->userInfo === $info) { @@ -218,9 +209,8 @@ public function withUserInfo($user, $password = null) } /** - * @inherit - * - * @param mixed $host + * @param mixed $host + * @return self */ public function withHost($host) { @@ -228,7 +218,7 @@ public function withHost($host) throw new \InvalidArgumentException('Host must be a string'); } - if ($this->host === $host = strtr($host, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')) { + if ($this->host === $host = \strtr($host, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')) { return $this; } @@ -239,9 +229,8 @@ public function withHost($host) } /** - * @inherit - * - * @param mixed $port + * @param mixed $port + * @return self */ public function withPort($port) { @@ -256,9 +245,8 @@ public function withPort($port) } /** - * @inherit - * - * @param mixed $path + * @param mixed $path + * @return self */ public function withPath($path) { @@ -273,9 +261,8 @@ public function withPath($path) } /** - * @inherit - * - * @param mixed $query + * @param mixed $query + * @return self */ public function withQuery($query) { @@ -290,9 +277,8 @@ public function withQuery($query) } /** - * @inherit - * - * @param mixed $fragment + * @param mixed $fragment + * @return self */ public function withFragment($fragment) { @@ -307,7 +293,7 @@ public function withFragment($fragment) } /** - * create Uri String. + * create Uri String * * @param string $scheme * @param string $authority @@ -321,24 +307,24 @@ protected static function createUriString($scheme, $authority, $path, $query, $f { $uri = ''; if ('' !== $scheme) { - $uri .= $scheme.':'; + $uri .= $scheme . ':'; } if ('' !== $authority) { - $uri .= '//'.$authority; + $uri .= '//' . $authority; } if ('' !== $path) { if (!empty($path[0]) && '/' !== $path[0]) { if ('' !== $authority) { // If the path is rootless and an authority is present, the path MUST be prefixed by "/" - $path = '/'.$path; + $path = '/' . $path; } } elseif (isset($path[1]) && '/' === $path[1]) { if ('' === $authority) { // If the path is starting with more than one "/" and no authority is present, the // starting slashes MUST be reduced to one. - $path = '/'.ltrim($path, '/'); + $path = '/' . \ltrim($path, '/'); } } @@ -346,20 +332,20 @@ protected static function createUriString($scheme, $authority, $path, $query, $f } if ('' !== $query) { - $uri .= '?'.$query; + $uri .= '?' . $query; } if ('' !== $fragment) { - $uri .= '#'.$fragment; + $uri .= '#' . $fragment; } return $uri; } /** - * Validate port. + * Validate port * - * @param string $scheme + * @param string $scheme * @param null|int $port * * @return bool @@ -370,12 +356,11 @@ protected static function isNonStandardPort($scheme, $port) } /** - * Validate port. + * Validate port * * @param null|int $port * - * @return null|int - * + * @return int|null * @throws \InvalidArgumentException */ protected function filterPort($port) @@ -385,20 +370,19 @@ protected function filterPort($port) } $port = (int) $port; - if (0 > $port || 0xFFFF < $port) { - throw new \InvalidArgumentException(sprintf('Invalid port: %d. Must be between 0 and 65535', $port)); + if (0 > $port || 0xffff < $port) { + throw new \InvalidArgumentException(\sprintf('Invalid port: %d. Must be between 0 and 65535', $port)); } return self::isNonStandardPort($this->scheme, $port) ? $port : null; } /** - * Validate QueryAndFragment. + * Validate QueryAndFragment * * @param string $path * * @return string - * * @throws \InvalidArgumentException */ protected function filterPath($path) @@ -407,16 +391,15 @@ protected function filterPath($path) throw new \InvalidArgumentException('Path must be a string'); } - return (string) preg_replace_callback('/(?:[^'.self::$CHAR_UNRESERVED.self::$CHAR_SUB_DELIMS.'%:@\/]++|%(?![A-Fa-f0-9]{2}))/', [__CLASS__, 'rawurlencodeMatchZero'], $path); + return (string) \preg_replace_callback('/(?:[^' . self::$CHAR_UNRESERVED . self::$CHAR_SUB_DELIMS . '%:@\/]++|%(?![A-Fa-f0-9]{2}))/', [__CLASS__, 'rawurlencodeMatchZero'], $path); } /** - * Validate QueryAndFragment. + * Validate QueryAndFragment * * @param string $str * * @return string - * * @throws \InvalidArgumentException */ protected function filterQueryAndFragment($str) @@ -425,11 +408,11 @@ protected function filterQueryAndFragment($str) throw new \InvalidArgumentException('Query and fragment must be a string'); } - return (string) preg_replace_callback('/(?:[^'.self::$CHAR_UNRESERVED.self::$CHAR_SUB_DELIMS.'%:@\/\?]++|%(?![A-Fa-f0-9]{2}))/', [__CLASS__, 'rawurlencodeMatchZero'], $str); + return (string) \preg_replace_callback('/(?:[^' . self::$CHAR_UNRESERVED . self::$CHAR_SUB_DELIMS . '%:@\/\?]++|%(?![A-Fa-f0-9]{2}))/', [__CLASS__, 'rawurlencodeMatchZero'], $str); } /** - * Raw urlencode Match Zero. + * Raw urlencode Match Zero * * @param array $match * @@ -437,6 +420,6 @@ protected function filterQueryAndFragment($str) */ protected static function rawurlencodeMatchZero(array $match) { - return rawurlencode($match[0]); + return \rawurlencode($match[0]); } }