Skip to content

Commit

Permalink
qa: apply CS fixes
Browse files Browse the repository at this point in the history
Signed-off-by: George Steel <george@net-glue.co.uk>
  • Loading branch information
gsteel committed Jul 6, 2022
1 parent b54995e commit cd02372
Show file tree
Hide file tree
Showing 28 changed files with 72 additions and 81 deletions.
3 changes: 3 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@

<!-- Include all rules from Laminas Coding Standard -->
<rule ref="LaminasCodingStandard"/>
<rule ref="WebimpressCodingStandard.NamingConventions.ValidVariableName.NotCamelCaps">
<severity>0</severity>
</rule>
</ruleset>
1 change: 1 addition & 0 deletions src/Exception/InvalidStreamPointerPositionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

class InvalidStreamPointerPositionException extends RuntimeException implements ExceptionInterface
{
/** @param int $code */
public function __construct(
string $message = 'Invalid pointer position',
$code = 0,
Expand Down
1 change: 1 addition & 0 deletions src/Exception/UploadedFileAlreadyMovedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

class UploadedFileAlreadyMovedException extends RuntimeException implements ExceptionInterface
{
/** @param int $code */
public function __construct(
string $message = 'Cannot retrieve stream after it has already moved',
$code = 0,
Expand Down
12 changes: 3 additions & 9 deletions src/HeaderSecurity.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@

/**
* Provide security tools around HTTP headers to prevent common injection vectors.
*
* Code is largely lifted from the Laminas\Http\Header\HeaderValue implementation in
* Laminas, released with the copyright and license below.
*
* @copyright Copyright (c) 2005-2015 Laminas (https://www.zend.com)
* @license https://getlaminas.org/license/new-bsd New BSD License
*/
final class HeaderSecurity
{
Expand Down Expand Up @@ -128,14 +122,14 @@ public static function isValid($value): bool
* Assert a header value is valid.
*
* @param mixed $value Value to be tested. This method asserts it is a string or number.
* @throws Exception\InvalidArgumentException for invalid values
* @throws Exception\InvalidArgumentException For invalid values.
*/
public static function assertValid($value): void
{
if (! is_string($value) && ! is_numeric($value)) {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid header value type; must be a string or numeric; received %s',
(is_object($value) ? get_class($value) : gettype($value))
is_object($value) ? get_class($value) : gettype($value)
));
}
if (! self::isValid($value)) {
Expand All @@ -159,7 +153,7 @@ public static function assertValidName($name): void
if (! is_string($name)) {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid header name type; expected string; received %s',
(is_object($name) ? get_class($name) : gettype($name))
is_object($name) ? get_class($name) : gettype($name)
));
}
if (! preg_match('/^[a-zA-Z0-9\'`#$%&*+.^_|~!-]+$/', $name)) {
Expand Down
11 changes: 7 additions & 4 deletions src/MessageTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function getHeaderLine($name): string
* @param string $name Case-insensitive header field name.
* @param string|string[] $value Header value(s).
* @return static
* @throws Exception\InvalidArgumentException for invalid header names or values.
* @throws Exception\InvalidArgumentException For invalid header names or values.
*/
public function withHeader($name, $value): MessageInterface
{
Expand Down Expand Up @@ -229,7 +229,7 @@ public function withHeader($name, $value): MessageInterface
* @param string $name Case-insensitive header field name to add.
* @param string|string[] $value Header value(s).
* @return static
* @throws Exception\InvalidArgumentException for invalid header names or values.
* @throws Exception\InvalidArgumentException For invalid header names or values.
*/
public function withAddedHeader($name, $value): MessageInterface
{
Expand Down Expand Up @@ -303,6 +303,9 @@ public function withBody(StreamInterface $body): MessageInterface
return $new;
}

/**
* @param StreamInterface|string|resource $stream
*/
private function getStream($stream, string $modeIfNotInstance): StreamInterface
{
if ($stream instanceof StreamInterface) {
Expand Down Expand Up @@ -348,7 +351,7 @@ private function setHeaders(array $originalHeaders): void
* Validate the HTTP protocol version
*
* @param string $version
* @throws Exception\InvalidArgumentException on invalid HTTP protocol version
* @throws Exception\InvalidArgumentException On invalid HTTP protocol version.
*/
private function validateProtocolVersion($version): void
{
Expand All @@ -360,7 +363,7 @@ private function validateProtocolVersion($version): void
if (! is_string($version)) {
throw new Exception\InvalidArgumentException(sprintf(
'Unsupported HTTP protocol version; must be a string, received %s',
(is_object($version) ? get_class($version) : gettype($version))
is_object($version) ? get_class($version) : gettype($version)
));
}

Expand Down
9 changes: 2 additions & 7 deletions src/RelativeStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
use const SEEK_SET;

/**
* Class RelativeStream
*
* Wrapper for default Stream class, representing subpart (starting from given offset) of initial stream.
* It can be used to avoid copying full stream, conserving memory.
*
* @example see Laminas\Diactoros\AbstractSerializer::splitStream()
* @see AbstractSerializer::splitStream()
*/
final class RelativeStream implements StreamInterface
{
Expand All @@ -24,9 +22,6 @@ final class RelativeStream implements StreamInterface
/** @var int */
private $offset;

/**
* Class constructor
*/
public function __construct(StreamInterface $decoratedStream, ?int $offset)
{
$this->decoratedStream = $decoratedStream;
Expand Down Expand Up @@ -97,7 +92,7 @@ public function isSeekable(): bool
*/
public function seek($offset, $whence = SEEK_SET): void
{
if ($whence == SEEK_SET) {
if ($whence === SEEK_SET) {
$this->decoratedStream->seek($offset + $this->offset, $whence);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Request implements RequestInterface
* @param null|string $method HTTP method for the request, if any.
* @param string|resource|StreamInterface $body Message body, if any.
* @param array $headers Headers for the message, if any.
* @throws Exception\InvalidArgumentException for any invalid value.
* @throws Exception\InvalidArgumentException For any invalid value.
*/
public function __construct($uri = null, ?string $method = null, $body = 'php://temp', array $headers = [])
{
Expand Down
2 changes: 1 addition & 1 deletion src/Request/ArraySerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static function toArray(RequestInterface $request): array
/**
* Deserialize a request array to a request instance.
*
* @throws Exception\DeserializationException when cannot deserialize response
* @throws Exception\DeserializationException When the response cannot be deserialized.
*/
public static function fromArray(array $serializedRequest): Request
{
Expand Down
7 changes: 3 additions & 4 deletions src/Request/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class Serializer extends AbstractSerializer
*
* Internally, casts the message to a stream and invokes fromStream().
*
* @throws Exception\SerializationException when errors occur parsing the message.
* @throws Exception\SerializationException When errors occur parsing the message.
*/
public static function fromString(string $message): Request
{
Expand All @@ -41,9 +41,8 @@ public static function fromString(string $message): Request
/**
* Deserialize a request stream to a request instance.
*
* @throws Exception\InvalidArgumentException if the message stream is not
* readable or seekable.
* @throws Exception\SerializationException if an invalid request line is detected.
* @throws Exception\InvalidArgumentException If the message stream is not readable or seekable.
* @throws Exception\SerializationException If an invalid request line is detected.
*/
public static function fromStream(StreamInterface $stream): Request
{
Expand Down
8 changes: 4 additions & 4 deletions src/RequestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ trait RequestTrait
* @param null|string $method HTTP method for the request, if any.
* @param string|resource|StreamInterface $body Message body, if any.
* @param array $headers Headers for the message, if any.
* @throws Exception\InvalidArgumentException for any invalid value.
* @throws Exception\InvalidArgumentException For any invalid value.
*/
private function initialize(
$uri = null,
Expand Down Expand Up @@ -157,7 +157,7 @@ public function getRequestTarget(): string
* request-target forms allowed in request messages)
*
* @param string $requestTarget
* @throws Exception\InvalidArgumentException if the request target is invalid.
* @throws Exception\InvalidArgumentException If the request target is invalid.
*/
public function withRequestTarget($requestTarget): RequestInterface
{
Expand Down Expand Up @@ -194,7 +194,7 @@ public function getMethod(): string
* changed request method.
*
* @param string $method Case-insensitive method.
* @throws Exception\InvalidArgumentException for invalid HTTP methods.
* @throws Exception\InvalidArgumentException For invalid HTTP methods.
*/
public function withMethod($method): RequestInterface
{
Expand Down Expand Up @@ -281,7 +281,7 @@ public function withUri(UriInterface $uri, $preserveHost = false): RequestInterf
* Set and validate the HTTP method
*
* @param string $method
* @throws Exception\InvalidArgumentException on invalid HTTP method.
* @throws Exception\InvalidArgumentException On invalid HTTP method.
*/
private function setMethod($method): void
{
Expand Down
4 changes: 2 additions & 2 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Response implements ResponseInterface
* @param string|resource|StreamInterface $body Stream identifier and/or actual stream resource
* @param int $status Status code for the response, if any.
* @param array $headers Headers for the response, if any.
* @throws Exception\InvalidArgumentException on any invalid element.
* @throws Exception\InvalidArgumentException On any invalid element.
*/
public function __construct($body = 'php://memory', int $status = 200, array $headers = [])
{
Expand Down Expand Up @@ -160,7 +160,7 @@ public function withStatus($code, $reasonPhrase = ''): Response
*
* @param int $code
* @param string $reasonPhrase
* @throws Exception\InvalidArgumentException on an invalid status code.
* @throws Exception\InvalidArgumentException On an invalid status code.
*/
private function setStatusCode($code, $reasonPhrase = ''): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Response/ArraySerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static function toArray(ResponseInterface $response): array
/**
* Deserialize a response array to a response instance.
*
* @throws Exception\DeserializationException when cannot deserialize response
* @throws Exception\DeserializationException When cannot deserialize response.
*/
public static function fromArray(array $serializedResponse): Response
{
Expand Down
8 changes: 4 additions & 4 deletions src/Response/HtmlResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class HtmlResponse extends Response
* @param string|StreamInterface $html HTML or stream for the message body.
* @param int $status Integer status code for the response; 200 by default.
* @param array $headers Array of headers to use at initialization.
* @throws Exception\InvalidArgumentException if $html is neither a string or stream.
* @throws Exception\InvalidArgumentException If $html is neither a string or stream.
*/
public function __construct($html, int $status = 200, array $headers = [])
{
Expand All @@ -50,7 +50,7 @@ public function __construct($html, int $status = 200, array $headers = [])
* Create the message body.
*
* @param string|StreamInterface $html
* @throws Exception\InvalidArgumentException if $html is neither a string or stream.
* @throws Exception\InvalidArgumentException If $html is neither a string or stream.
*/
private function createBody($html): StreamInterface
{
Expand All @@ -61,8 +61,8 @@ private function createBody($html): StreamInterface
if (! is_string($html)) {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid content (%s) provided to %s',
(is_object($html) ? get_class($html) : gettype($html)),
__CLASS__
is_object($html) ? get_class($html) : gettype($html),
self::class
));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Response/InjectContentTypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ trait InjectContentTypeTrait
private function injectContentType(string $contentType, array $headers): array
{
$hasContentType = array_reduce(array_keys($headers), function ($carry, $item) {
return $carry ?: (strtolower($item) === 'content-type');
return $carry ?: strtolower($item) === 'content-type';
}, false);

if (! $hasContentType) {
Expand Down
6 changes: 3 additions & 3 deletions src/Response/JsonResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class JsonResponse extends Response
* @param int $status Integer status code for the response; 200 by default.
* @param array $headers Array of headers to use at initialization.
* @param int $encodingOptions JSON encoding options to use.
* @throws Exception\InvalidArgumentException if unable to encode the $data to JSON.
* @throws Exception\InvalidArgumentException If unable to encode the $data to JSON.
*/
public function __construct(
$data,
Expand Down Expand Up @@ -128,7 +128,7 @@ private function createBodyFromJson(string $json): Stream
* Encode the provided data to JSON.
*
* @param mixed $data
* @throws Exception\InvalidArgumentException if unable to encode the $data to JSON.
* @throws Exception\InvalidArgumentException If unable to encode the $data to JSON.
*/
private function jsonEncode($data, int $encodingOptions): string
{
Expand All @@ -144,7 +144,7 @@ private function jsonEncode($data, int $encodingOptions): string
if (JSON_ERROR_NONE !== json_last_error()) {
throw new Exception\InvalidArgumentException(sprintf(
'Unable to encode data to JSON in %s: %s',
__CLASS__,
self::class,
json_last_error_msg()
));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Response/RedirectResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct($uri, int $status = 302, array $headers = [])
if (! is_string($uri) && ! $uri instanceof UriInterface) {
throw new Exception\InvalidArgumentException(sprintf(
'Uri provided to %s MUST be a string or Psr\Http\Message\UriInterface instance; received "%s"',
__CLASS__,
self::class,
is_object($uri) ? get_class($uri) : gettype($uri)
));
}
Expand Down
10 changes: 5 additions & 5 deletions src/Response/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class Serializer extends AbstractSerializer
/**
* Deserialize a response string to a response instance.
*
* @throws Exception\SerializationException when errors occur parsing the message.
* @throws Exception\SerializationException When errors occur parsing the message.
*/
public static function fromString(string $message): Response
{
Expand All @@ -31,8 +31,8 @@ public static function fromString(string $message): Response
/**
* Parse a response from a stream.
*
* @throws Exception\InvalidArgumentException when the stream is not readable.
* @throws Exception\SerializationException when errors occur parsing the message.
* @throws Exception\InvalidArgumentException When the stream is not readable.
* @throws Exception\SerializationException When errors occur parsing the message.
*/
public static function fromStream(StreamInterface $stream): Response
{
Expand Down Expand Up @@ -70,7 +70,7 @@ public static function toString(ResponseInterface $response): string
$format,
$response->getProtocolVersion(),
$response->getStatusCode(),
($reasonPhrase ? ' ' . $reasonPhrase : ''),
$reasonPhrase ? ' ' . $reasonPhrase : '',
$headers,
$body
);
Expand All @@ -80,7 +80,7 @@ public static function toString(ResponseInterface $response): string
* Retrieve the status line for the message.
*
* @return array Array with three elements: 0 => version, 1 => status, 2 => reason
* @throws Exception\SerializationException if line is malformed
* @throws Exception\SerializationException If line is malformed.
*/
private static function getStatusLine(StreamInterface $stream): array
{
Expand Down
8 changes: 4 additions & 4 deletions src/Response/TextResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TextResponse extends Response
* @param string|StreamInterface $text String or stream for the message body.
* @param int $status Integer status code for the response; 200 by default.
* @param array $headers Array of headers to use at initialization.
* @throws Exception\InvalidArgumentException if $text is neither a string or stream.
* @throws Exception\InvalidArgumentException If $text is neither a string or stream.
*/
public function __construct($text, int $status = 200, array $headers = [])
{
Expand All @@ -50,7 +50,7 @@ public function __construct($text, int $status = 200, array $headers = [])
* Create the message body.
*
* @param string|StreamInterface $text
* @throws Exception\InvalidArgumentException if $text is neither a string or stream.
* @throws Exception\InvalidArgumentException If $text is neither a string or stream.
*/
private function createBody($text): StreamInterface
{
Expand All @@ -61,8 +61,8 @@ private function createBody($text): StreamInterface
if (! is_string($text)) {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid content (%s) provided to %s',
(is_object($text) ? get_class($text) : gettype($text)),
__CLASS__
is_object($text) ? get_class($text) : gettype($text),
self::class
));
}

Expand Down

0 comments on commit cd02372

Please sign in to comment.