Skip to content

Commit

Permalink
Added property & return type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
shudd3r committed Mar 7, 2021
1 parent 6426b21 commit 778a418
Show file tree
Hide file tree
Showing 14 changed files with 328 additions and 327 deletions.
8 changes: 4 additions & 4 deletions src/Cookie/CookieSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class CookieSetup
{
private const FIVE_YEARS_IN_SEC = 157680000;

private $responseHeaders;
private $directives;
private ResponseHeaders $responseHeaders;
private array $directives;

/**
* @param ResponseHeaders $responseHeaders
Expand Down Expand Up @@ -96,7 +96,7 @@ public function cookie(string $name): Cookie
*
* @return Cookie
*/
public function permanentCookie($name): Cookie
public function permanentCookie(string $name): Cookie
{
$this->maxAge(self::FIVE_YEARS_IN_SEC);
return $this->cookie($name);
Expand All @@ -111,7 +111,7 @@ public function permanentCookie($name): Cookie
*
* @return Cookie
*/
public function sessionCookie($name): Cookie
public function sessionCookie(string $name): Cookie
{
$this->httpOnly();
$this->sameSite('Lax');
Expand Down
8 changes: 4 additions & 4 deletions src/Cookie/HeadersContextCookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class HeadersContextCookie implements Cookie
{
const DIRECTIVE_NAMES = ['Domain', 'Path', 'Expires', 'MaxAge', 'Secure', 'HttpOnly', 'SameSite'];

private $name;
private $directives;
private $headers;
private string $name;
private array $directives;
private ResponseHeaders $headers;

private $sent = false;
private bool $sent = false;

/**
* @param string $name
Expand Down
10 changes: 5 additions & 5 deletions src/Header/SetCookieHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@

class SetCookieHeader implements Header
{
private $header;
private string $headerValue;

/**
* @param string $header
* @param string $headerValue
*/
public function __construct(string $header)
public function __construct(string $headerValue)
{
$this->header = $header;
$this->headerValue = $headerValue;
}

public function addToMessage(MessageInterface $message): MessageInterface
{
return $message->withAddedHeader('Set-Cookie', $this->header);
return $message->withAddedHeader('Set-Cookie', $this->headerValue);
}
}
2 changes: 1 addition & 1 deletion src/ResponseHeaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

final class ResponseHeaders implements MiddlewareInterface
{
private $headers = [];
private array $headers;

/**
* @param Header[] $headers
Expand Down
177 changes: 177 additions & 0 deletions tests/Doubles/DummyServerRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?php declare(strict_types=1);

/*
* This file is part of Polymorphine/Headers package.
*
* (c) Shudd3r <q3.shudder@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Polymorphine\Headers\Tests\Doubles;

use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UriInterface;


class DummyServerRequest implements ServerRequestInterface
{
public ?UriInterface $uri;

public function __construct(UriInterface $uri = null)
{
$this->uri = $uri;
}

public function getMethod(): string
{
return 'GET';
}

public function getUri(): UriInterface
{
return $this->uri;
}

public function getRequestTarget(): string
{
return 'foo?bar=baz';
}

public function getProtocolVersion(): string
{
return '1.1';
}

public function withProtocolVersion($version): self
{
return $this;
}

public function getHeaders(): array
{
return [];
}

public function hasHeader($name): bool
{
return false;
}

public function getHeader($name): array
{
return [];
}

public function getHeaderLine($name): string
{
return '';
}

public function withHeader($name, $value): self
{
return $this;
}

public function withAddedHeader($name, $value): self
{
return $this;
}

public function withoutHeader($name): self
{
return $this;
}

public function getBody(): StreamInterface
{
return new DummyStream();
}

public function withBody(StreamInterface $body): self
{
return $this;
}

public function withRequestTarget($requestTarget): self
{
return $this;
}

public function withMethod($method): self
{
return $this;
}

public function withUri(UriInterface $uri, $preserveHost = false): self
{
return $this;
}

public function getServerParams(): array
{
return [];
}

public function getCookieParams(): array
{
return [];
}

public function withCookieParams(array $cookies): self
{
return $this;
}

public function getQueryParams(): array
{
return [];
}

public function withQueryParams(array $query): self
{
return $this;
}

public function getUploadedFiles(): array
{
return [];
}

public function withUploadedFiles(array $uploadedFiles): self
{
return $this;
}

public function getParsedBody(): array
{
return [];
}

public function withParsedBody($data): self
{
return $this;
}

public function getAttributes(): array
{
return [];
}

public function getAttribute($name, $default = null)
{
return $default;
}

public function withAttribute($name, $value): self
{
return $this;
}

public function withoutAttribute($name): self
{
return $this;
}
}
88 changes: 88 additions & 0 deletions tests/Doubles/DummyStream.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php declare(strict_types=1);

/*
* This file is part of Polymorphine/Headers package.
*
* (c) Shudd3r <q3.shudder@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Polymorphine\Headers\Tests\Doubles;

use Psr\Http\Message\StreamInterface;


class DummyStream implements StreamInterface
{
public function __toString(): string
{
return 'Hello world';
}

public function close(): void
{
}

public function detach()
{
}

public function getSize(): ?int
{
return 10;
}

public function tell(): int
{
return 5;
}

public function eof(): bool
{
return false;
}

public function isSeekable(): bool
{
return true;
}

public function seek($offset, $whence = SEEK_SET): void
{
}

public function rewind(): void
{
}

public function isWritable(): bool
{
return true;
}

public function write($string): void
{
}

public function isReadable(): bool
{
return true;
}

public function read($length): string
{
return 'Hello';
}

public function getContents(): string
{
return ' World';
}

public function getMetadata($key = null): array
{
return [];
}
}
4 changes: 2 additions & 2 deletions tests/Doubles/FakeHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

class FakeHeader implements Header
{
private $name;
private $value;
private string $name;
private string $value;

public function __construct(string $name, string $value)
{
Expand Down
9 changes: 3 additions & 6 deletions tests/Doubles/FakeRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@

class FakeRequestHandler implements RequestHandlerInterface
{
private $response;
private $sideEffect;
private ResponseInterface $response;

public function __construct(ResponseInterface $response, callable $sideEffect = null)
public function __construct(ResponseInterface $response)
{
$this->response = $response;
$this->sideEffect = $sideEffect;
$this->response = $response;
}

public function handle(ServerRequestInterface $request): ResponseInterface
{
if ($this->sideEffect) { ($this->sideEffect)(); }
return $this->response;
}
}
Loading

0 comments on commit 778a418

Please sign in to comment.