Skip to content

Commit

Permalink
Merge pull request #41 from lcobucci/upgrade-dependencies
Browse files Browse the repository at this point in the history
Upgrade dependencies
  • Loading branch information
lcobucci authored Feb 26, 2020
2 parents bf9a8e7 + e5e95bf commit a0ea2ad
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build:
rabbitmq: false
mongodb: false
php:
version: 7.3
version: 7.4

cache:
disabled: false
Expand Down
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ sudo: false
language: php

php:
- 7.3
- 7.4snapshot
- 7.4
- nightly

cache:
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@ use Zend\Diactoros\StreamFactory;
$middleware = ContentTypeMiddleware::fromRecommendedSettings(
// First argument is the list of formats you want to support:
[
'json' => [
'extension' => ['json'],
'mime-type' => ['application/json', 'text/json', 'application/x-json'],
'charset' => true,
],
'json',
// You may also specify the full configuration of the format.
// That's handy if you need to add extensions or mime-types:
'html' => [
'extension' => ['html', 'htm', 'php'],
'mime-type' => ['text/html', 'application/xhtml+xml'],
Expand Down
21 changes: 11 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
},
"require": {
"php": "^7.3",
"php": "^7.4 || ^8.0",
"ext-json": "*",
"fig/http-message-util": "^1.1",
"psr/http-factory": "^1.0",
Expand All @@ -28,24 +28,25 @@
"require-dev": {
"infection/infection": "^0.15",
"jms/serializer": "^3.5",
"lcobucci/coding-standard": "^3.1",
"laminas/laminas-diactoros": "^2.2",
"lcobucci/coding-standard": "^4.0",
"league/plates": "^3.3",
"middlewares/negotiation": "^1.1",
"phpstan/phpstan": "^0.11",
"phpstan/phpstan-deprecation-rules": "^0.11",
"phpstan/phpstan-phpunit": "^0.11",
"phpstan/phpstan-strict-rules": "^0.11",
"middlewares/negotiation": "^2.0",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-deprecation-rules": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"phpstan/phpstan-strict-rules": "^0.12",
"phpunit/phpunit": "^9.0",
"squizlabs/php_codesniffer": "^3.5",
"twig/twig": "^2.12",
"zendframework/zend-diactoros": "^2.2"
"twig/twig": "^3.0"
},
"suggest": {
"jms/serializer": "For content formatting using a more flexible serializer",
"league/plates": "For content formatting using Plates as template engine",
"middlewares/negotiation": "For acceptable format identification",
"twig/twig": "For content formatting using Twig as template engine",
"zendframework/zend-diactoros": "For concrete implementation of PSR-7"
"laminas/laminas-diactoros": "For concrete implementation of PSR-7"
},
"autoload": {
"psr-4": {
Expand Down
8 changes: 2 additions & 6 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon

parameters:
level: 7
paths:
Expand All @@ -13,3 +7,5 @@ parameters:
-
message: '#Variable method call on#'
path: tests/UnformattedResponseTest.php

- '#static\(Lcobucci\\ContentNegotiation\\UnformattedResponse\) but returns Lcobucci\\ContentNegotiation\\UnformattedResponse#'
13 changes: 3 additions & 10 deletions src/ContentTypeMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,13 @@

final class ContentTypeMiddleware implements MiddlewareInterface
{
/**
* @var MiddlewareInterface
*/
private $negotiator;

/**
* @var StreamFactoryInterface
*/
private $streamFactory;
private MiddlewareInterface $negotiator;
private StreamFactoryInterface $streamFactory;

/**
* @var Formatter[]
*/
private $formatters;
private array $formatters;

/**
* @param Formatter[] $formatters
Expand Down
11 changes: 2 additions & 9 deletions src/Formatter/JmsSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,8 @@

final class JmsSerializer implements Formatter
{
/**
* @var SerializerInterface
*/
private $serializer;

/**
* @var string
*/
private $format;
private SerializerInterface $serializer;
private string $format;

public function __construct(SerializerInterface $serializer, string $format)
{
Expand Down
16 changes: 4 additions & 12 deletions src/Formatter/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,20 @@
use Lcobucci\ContentNegotiation\ContentCouldNotBeFormatted;
use Lcobucci\ContentNegotiation\Formatter;
use Throwable;
use function json_encode;
use function sprintf;
use const JSON_HEX_AMP;
use const JSON_HEX_APOS;
use const JSON_HEX_QUOT;
use const JSON_HEX_TAG;
use const JSON_THROW_ON_ERROR;
use const JSON_UNESCAPED_SLASHES;
use function assert;
use function is_string;
use function json_encode;
use function sprintf;

final class Json implements Formatter
{
private const DEFAULT_FLAGS = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_SLASHES;

/**
* @var int
*/
private $flags;
private int $flags;

public function __construct(int $flags = self::DEFAULT_FLAGS)
{
Expand All @@ -37,10 +32,7 @@ public function __construct(int $flags = self::DEFAULT_FLAGS)
public function format($content, array $attributes = []): string
{
try {
$content = json_encode($content, $this->flags | JSON_THROW_ON_ERROR);
assert(is_string($content));

return $content;
return json_encode($content, $this->flags | JSON_THROW_ON_ERROR);
} catch (Throwable $exception) {
throw new ContentCouldNotBeFormatted(
sprintf('An exception was thrown during JSON formatting: %s', $exception->getMessage()),
Expand Down
11 changes: 2 additions & 9 deletions src/Formatter/Plates.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,8 @@ final class Plates implements Formatter
{
private const DEFAULT_ATTRIBUTE = 'template';

/**
* @var Engine
*/
private $engine;

/**
* @var string
*/
private $attributeName;
private Engine $engine;
private string $attributeName;

public function __construct(Engine $engine, string $attributeName = self::DEFAULT_ATTRIBUTE)
{
Expand Down
15 changes: 4 additions & 11 deletions src/Formatter/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,17 @@
use Lcobucci\ContentNegotiation\ContentCouldNotBeFormatted;
use Lcobucci\ContentNegotiation\Formatter;
use Throwable;
use Twig_Environment;
use Twig\Environment;

final class Twig implements Formatter
{
private const DEFAULT_ATTRIBUTE = 'template';

/**
* @var Twig_Environment
*/
private $environment;

/**
* @var string
*/
private $attributeName;
private Environment $environment;
private string $attributeName;

public function __construct(
Twig_Environment $environment,
Environment $environment,
string $attributeName = self::DEFAULT_ATTRIBUTE
) {
$this->environment = $environment;
Expand Down
41 changes: 13 additions & 28 deletions src/UnformattedResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,21 @@

final class UnformattedResponse implements ResponseInterface
{
/**
* @var ResponseInterface
*/
private $decoratedResponse;
private ResponseInterface $decoratedResponse;

/**
* @var mixed
*/
private $unformattedContent;

/**
* @var mixed[]
* @var array<string, mixed>
*/
private $attributes;
private array $attributes;

/**
* @param mixed $unformattedContent
* @param mixed[] $attributes
* @param mixed $unformattedContent
* @param array<string, mixed> $attributes
*/
public function __construct(
ResponseInterface $decoratedResponse,
Expand All @@ -45,10 +42,7 @@ public function getUnformattedContent()
return $this->unformattedContent;
}

/**
* {@inheritdoc}
*/
public function getProtocolVersion()
public function getProtocolVersion(): string
{
return $this->decoratedResponse->getProtocolVersion();
}
Expand All @@ -68,15 +62,15 @@ public function withProtocolVersion($version)
/**
* {@inheritdoc}
*/
public function getHeaders()
public function getHeaders(): array
{
return $this->decoratedResponse->getHeaders();
}

/**
* {@inheritdoc}
*/
public function hasHeader($name)
public function hasHeader($name): bool
{
return $this->decoratedResponse->hasHeader($name);
}
Expand All @@ -92,7 +86,7 @@ public function getHeader($name)
/**
* {@inheritdoc}
*/
public function getHeaderLine($name)
public function getHeaderLine($name): string
{
return $this->decoratedResponse->getHeaderLine($name);
}
Expand Down Expand Up @@ -133,10 +127,7 @@ public function withoutHeader($name)
);
}

/**
* {@inheritdoc}
*/
public function getBody()
public function getBody(): StreamInterface
{
return $this->decoratedResponse->getBody();
}
Expand All @@ -153,10 +144,7 @@ public function withBody(StreamInterface $body)
);
}

/**
* {@inheritdoc}
*/
public function getStatusCode()
public function getStatusCode(): int
{
return $this->decoratedResponse->getStatusCode();
}
Expand All @@ -173,10 +161,7 @@ public function withStatus($code, $reasonPhrase = '')
);
}

/**
* {@inheritdoc}
*/
public function getReasonPhrase()
public function getReasonPhrase(): string
{
return $this->decoratedResponse->getReasonPhrase();
}
Expand All @@ -198,7 +183,7 @@ public function withAttribute(string $name, $value): self
/**
* Retrieve the configured attributes
*
* @return mixed[]
* @return array<string, mixed>
*/
public function getAttributes(): array
{
Expand Down
16 changes: 5 additions & 11 deletions tests/ContentTypeMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
namespace Lcobucci\ContentNegotiation\Tests;

use Fig\Http\Message\StatusCodeInterface;
use Laminas\Diactoros\Response;
use Laminas\Diactoros\Response\EmptyResponse;
use Laminas\Diactoros\ServerRequest;
use Laminas\Diactoros\StreamFactory;
use Lcobucci\ContentNegotiation\ContentTypeMiddleware;
use Lcobucci\ContentNegotiation\Formatter;
use Lcobucci\ContentNegotiation\Tests\Formatter\NaiveTemplateEngine;
Expand All @@ -12,10 +16,6 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response;
use Zend\Diactoros\Response\EmptyResponse;
use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\StreamFactory;
use function array_map;

/**
Expand Down Expand Up @@ -184,19 +184,13 @@ private function createRequestHandler(ResponseInterface $response): RequestHandl
{
return new class($response) implements RequestHandlerInterface
{
/**
* @var ResponseInterface
*/
private $response;
private ResponseInterface $response;

public function __construct(ResponseInterface $response)
{
$this->response = $response;
}

/**
* {@inheritdoc}
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
return $this->response;
Expand Down
2 changes: 1 addition & 1 deletion tests/Formatter/JmsSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class JmsSerializerTest extends TestCase
/**
* @var SerializerInterface|MockObject
*/
private $serializer;
private SerializerInterface $serializer;

/**
* @before
Expand Down
2 changes: 1 addition & 1 deletion tests/Formatter/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use Lcobucci\ContentNegotiation\Tests\PersonDto;
use PHPUnit\Framework\TestCase;
use RuntimeException;
use const JSON_UNESCAPED_SLASHES;
use function acos;
use const JSON_UNESCAPED_SLASHES;

/**
* @coversDefaultClass \Lcobucci\ContentNegotiation\Formatter\Json
Expand Down
Loading

0 comments on commit a0ea2ad

Please sign in to comment.