Skip to content

Commit

Permalink
Fixed vimeo/psalm#7196 and updated pure annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoboss committed Jan 6, 2022
1 parent 6e0efbd commit dccd31c
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/AbstractMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ abstract class AbstractMessage implements Contract\Message

#[Pure] abstract public function getHeaderMap(): Contract\HeaderMap;

#[Pure] public function hasHeaderName(HeaderName $name): bool
public function hasHeaderName(HeaderName $name): bool
{
return $this->getHeaderMap()->has($name);
}

#[Pure] public function getHeaderName(HeaderName $name): ReadonlyList
public function getHeaderName(HeaderName $name): ReadonlyList
{
return $this->getHeaderMap()->get($name);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Contract/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public function withProtocolVersion(string $version): static;

public function withBody(Stream $body): static;

#[Pure] public function hasHeaderName(HeaderName $name): bool;
public function hasHeaderName(HeaderName $name): bool;

/**
* @param HeaderName $name
* @return ReadonlyList<string>
*/
#[Pure] public function getHeaderName(HeaderName $name): ReadonlyList;
public function getHeaderName(HeaderName $name): ReadonlyList;

/**
* @param HeaderName $name
Expand Down
8 changes: 4 additions & 4 deletions src/Contract/ReadonlyHeaderMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ interface ReadonlyHeaderMap extends ReadonlyMap, ArrayConvertible
*
* @return bool
*/
#[Pure] public function has(mixed $key): bool;
public function has(mixed $key): bool;

/**
* @param string|HeaderName $key
*
* @return ReadonlyList<string>
*/
#[Pure] public function get(mixed $key): mixed;
public function get(mixed $key): mixed;

#[Pure] public function asRequestHeaders(): RequestHeaderMap;
public function asRequestHeaders(): RequestHeaderMap;

#[Pure] public function asResponseHeaders(): ResponseHeaderMap;
public function asResponseHeaders(): ResponseHeaderMap;
}
2 changes: 1 addition & 1 deletion src/Contract/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function getHeaderMap(): ResponseHeaderMap;

public function withResponseCode(ResponseCode $code): static;

#[Pure] public function getContentType(): ?MimeTypeContract;
public function getContentType(): ?MimeTypeContract;

public function withContentType(?MimeTypeContract $mimeType): static;

Expand Down
2 changes: 1 addition & 1 deletion src/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Cookie implements Contract\Cookie
* @param string $cookies
* @return ArrayList<Contract\Cookie>
*/
#[Pure] public static function fromRequestString(string $cookies): ArrayList
public static function fromRequestString(string $cookies): ArrayList
{
return ArrayList::fromArray(mb_split(';', $cookies))
->map(static function (string $cookie): Contract\Cookie {
Expand Down
10 changes: 5 additions & 5 deletions src/HeaderMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class HeaderMap extends ObjectMap implements Contract\HeaderMap
return $headerName;
}

#[Pure] protected static function fromIterable(iterable $headers): self
protected static function fromIterable(iterable $headers): self
{
$map = new self();

Expand Down Expand Up @@ -91,7 +91,7 @@ class HeaderMap extends ObjectMap implements Contract\HeaderMap
*
* @psalm-suppress MoreSpecificImplementedParamType
*/
#[Pure] public function has(mixed $key): bool
public function has(mixed $key): bool
{
if (!$key instanceof Contract\HeaderName) {
$key = self::parseHeaderName($key);
Expand Down Expand Up @@ -134,7 +134,7 @@ public function put(mixed $key, mixed $value): void
*
* @psalm-suppress MoreSpecificImplementedParamType
*/
#[Pure] public function get(mixed $key): ArrayList
public function get(mixed $key): ArrayList
{
if (!$key instanceof Contract\HeaderName) {
$key = self::parseHeaderName($key);
Expand Down Expand Up @@ -177,12 +177,12 @@ public function asArray(): array
return $headers;
}

#[Pure] public function asRequestHeaders(): Contract\RequestHeaderMap
public function asRequestHeaders(): Contract\RequestHeaderMap
{
return RequestHeaderMap::fromIterable($this);
}

#[Pure] public function asResponseHeaders(): Contract\ResponseHeaderMap
public function asResponseHeaders(): Contract\ResponseHeaderMap
{
return ResponseHeaderMap::fromIterable($this);
}
Expand Down
2 changes: 1 addition & 1 deletion src/RequestHeaderMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class RequestHeaderMap extends HeaderMap implements Contract\RequestHeaderMap
{
#[Pure] public static function fromIterable(iterable $headers): self
public static function fromIterable(iterable $headers): self
{
$map = parent::fromIterable($headers);

Expand Down
6 changes: 4 additions & 2 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,20 @@ public function withResponseCode(Contract\ResponseCode $code): static
return new static($code, $this->headers->deepClone(), clone $this->body, $this->protocolVersion);
}

#[Pure] public function getContentType(): ?MimeTypeContract
public function getContentType(): ?MimeTypeContract
{
if (!$this->headers->has(HeaderName::ContentType)) {
return null;
}

/**
* @var null|string $value
*/
$value = $this->headers->get(HeaderName::ContentType)->first();
if (empty($value)) {
return null;
}

/** @psalm-suppress ImpureMethodCall */
$type = MimeType::tryfrom($value);

return $type ?? new CustomMimeType($value);
Expand Down
4 changes: 2 additions & 2 deletions src/ResponseHeaderMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class ResponseHeaderMap extends HeaderMap implements Contract\ResponseHeaderMap
{
#[Pure] public static function fromString(string $headers): self
public static function fromString(string $headers): self
{
$rows = Regex::split('/\n/', $headers);

Expand All @@ -35,7 +35,7 @@ class ResponseHeaderMap extends HeaderMap implements Contract\ResponseHeaderMap
return self::fromIterable($headerMap->asArray());
}

#[Pure] public static function fromIterable(iterable $headers): self
public static function fromIterable(iterable $headers): self
{
$map = parent::fromIterable($headers);

Expand Down
2 changes: 1 addition & 1 deletion src/ServerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(
return new ArrayMap($_SERVER);
}

#[Pure] public function getCookies(): ArrayList
public function getCookies(): ArrayList
{
/** @var ArrayList<Cookie> */
return $this->headers->get(HeaderName::Cookie);
Expand Down

0 comments on commit dccd31c

Please sign in to comment.