Skip to content

Commit

Permalink
finish PR for types in constructors and private functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobion committed Jun 9, 2019
1 parent e4b5912 commit eb6f13a
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/MessageTrait.php
Expand Up @@ -159,7 +159,7 @@ private function setHeaders(array $headers): void
}
}

private function normalizeHeaderValue($value)
private function normalizeHeaderValue($value): array
{
if (!is_array($value)) {
return $this->trimHeaderValues([$value]);
Expand Down
2 changes: 1 addition & 1 deletion src/PumpStream.php
Expand Up @@ -21,7 +21,7 @@ class PumpStream implements StreamInterface
/** @var callable|null */
private $source;

/** @var int */
/** @var int|null */
private $size;

/** @var int */
Expand Down
2 changes: 1 addition & 1 deletion src/Response.php
Expand Up @@ -146,7 +146,7 @@ private function assertStatusCodeIsInteger($statusCode)
}
}

private function assertStatusCodeRange($statusCode)
private function assertStatusCodeRange(int $statusCode)
{
if ($statusCode < 100 || $statusCode >= 600) {
throw new \InvalidArgumentException('Status code must be an integer value between 1xx and 5xx.');
Expand Down
43 changes: 3 additions & 40 deletions src/UploadedFile.php
Expand Up @@ -31,7 +31,7 @@ class UploadedFile implements UploadedFileInterface
private $clientFilename;

/**
* @var string
* @var string|null
*/
private $clientMediaType;

Expand Down Expand Up @@ -87,7 +87,6 @@ public function __construct(
/**
* Depending on the value set file or stream variable
*
* @param mixed $streamOrFile
* @throws InvalidArgumentException
*/
private function setStreamOrFile($streamOrFile): void
Expand Down Expand Up @@ -119,21 +118,15 @@ private function setError(int $error): void
$this->error = $error;
}

/**
* @param mixed $param
* @return boolean
*/
private function isStringNotEmpty($param)
private function isStringNotEmpty($param): bool
{
return is_string($param) && false === empty($param);
}

/**
* Return true if there is no upload error
*
* @return boolean
*/
private function isOk()
private function isOk(): bool
{
return $this->error === UPLOAD_ERR_OK;
}
Expand All @@ -160,10 +153,6 @@ private function validateActive(): void
}
}

/**
* {@inheritdoc}
* @throws RuntimeException if the upload was not successful.
*/
public function getStream()
{
$this->validateActive();
Expand All @@ -175,17 +164,6 @@ public function getStream()
return new LazyOpenStream($this->file, 'r+');
}

/**
* {@inheritdoc}
*
* @see http://php.net/is_uploaded_file
* @see http://php.net/move_uploaded_file
* @param string $targetPath Path to which to move the uploaded file.
* @throws RuntimeException if the upload was not successful.
* @throws InvalidArgumentException if the $path specified is invalid.
* @throws RuntimeException on any error during the move operation, or on
* the second or subsequent call to the method.
*/
public function moveTo($targetPath)
{
$this->validateActive();
Expand Down Expand Up @@ -221,31 +199,16 @@ public function getSize()
return $this->size;
}

/**
* {@inheritdoc}
*
* @see http://php.net/manual/en/features.file-upload.errors.php
* @return int One of PHP's UPLOAD_ERR_XXX constants.
*/
public function getError()
{
return $this->error;
}

/**
* {@inheritdoc}
*
* @return string|null The filename sent by the client or null if none
* was provided.
*/
public function getClientFilename()
{
return $this->clientFilename;
}

/**
* {@inheritdoc}
*/
public function getClientMediaType()
{
return $this->clientMediaType;
Expand Down
6 changes: 1 addition & 5 deletions src/Uri.php
Expand Up @@ -62,12 +62,8 @@ class Uri implements UriInterface
/** @var string Uri fragment. */
private $fragment = '';

/**
* @param string $uri URI to parse
*/
public function __construct(string $uri = '')
{
// weak type check to also accept null until we can add scalar type hints
if ($uri !== '') {
$parts = parse_url($uri);
if ($parts === false) {
Expand Down Expand Up @@ -328,7 +324,7 @@ public static function withQueryValue(UriInterface $uri, $key, $value)
{
$result = self::getFilteredQueryString($uri, [$key]);

$result[] = self::generateQueryString($key, $value);
$result[] = self::generateQueryString($key, $value !== null ? (string) $value : null);

return $uri->withQuery(implode('&', $result));
}
Expand Down
2 changes: 1 addition & 1 deletion src/UriNormalizer.php
Expand Up @@ -180,7 +180,7 @@ public static function isEquivalent(UriInterface $uri1, UriInterface $uri2, $nor
return (string) self::normalize($uri1, $normalizations) === (string) self::normalize($uri2, $normalizations);
}

private static function capitalizePercentEncoding(UriInterface $uri)
private static function capitalizePercentEncoding(UriInterface $uri): UriInterface
{
$regex = '/(?:%[A-Fa-f0-9]{2})++/';

Expand Down
2 changes: 1 addition & 1 deletion src/UriResolver.php
Expand Up @@ -182,7 +182,7 @@ public static function relativize(UriInterface $base, UriInterface $target)
return $emptyPathUri;
}

private static function getRelativePath(UriInterface $base, UriInterface $target)
private static function getRelativePath(UriInterface $base, UriInterface $target): string
{
$sourceSegments = explode('/', $base->getPath());
$targetSegments = explode('/', $target->getPath());
Expand Down
2 changes: 1 addition & 1 deletion tests/RequestTest.php
Expand Up @@ -99,7 +99,7 @@ public function testWithUri()
*/
public function testConstructWithInvalidMethods($method)
{
$this->expectException(\InvalidArgumentException::class);
$this->expectException(\TypeError::class);
new Request($method, '/');
}

Expand Down
11 changes: 9 additions & 2 deletions tests/ResponseTest.php
Expand Up @@ -48,6 +48,14 @@ public function testConstructorDoesNotReadStreamBody()
$this->assertSame($body, $r->getBody());
}

public function testStatusCanBeNumericString()
{
$r = (new Response())->withStatus('201');

$this->assertSame(201, $r->getStatusCode());
$this->assertSame('Created', $r->getReasonPhrase());
}

public function testCanConstructWithHeaders()
{
$r = new Response(200, ['Foo' => 'Bar']);
Expand Down Expand Up @@ -297,8 +305,7 @@ public function testHeaderValuesAreTrimmed()
*/
public function testConstructResponseWithNonIntegerStatusCode($invalidValues)
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Status code must be an integer value.');
$this->expectException(\TypeError::class);
new Response($invalidValues);
}

Expand Down

0 comments on commit eb6f13a

Please sign in to comment.