Skip to content

Commit

Permalink
Modernize and drop support for outdated versions
Browse files Browse the repository at this point in the history
* Require PHP ^8.0
* Require Symfony ^5.4 or ^6.0
* Require PHPUnit ^9.5
  • Loading branch information
jsor committed Oct 15, 2022
1 parent 78e35da commit d8bc257
Show file tree
Hide file tree
Showing 34 changed files with 276 additions and 255 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
strategy:
matrix:
include:
- php: '7.2'
- php: '8.0'
composer-flags: '--prefer-stable --prefer-lowest'

- php: '7.4'
- php: '8.1'
code-coverage: 'yes'

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.1'
coverage: none
extensions: mbstring
tools: 'cs2pr'
Expand Down
40 changes: 27 additions & 13 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,39 @@
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'linebreak_after_opening_tag' => true,
'native_constant_invocation' => true,
'native_function_invocation' => true,
'no_superfluous_phpdoc_tags' => true,
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_imports' => true,
'array_syntax' => [
'syntax' => 'short',
],
'concat_space' => [
'spacing' => 'one',
],
'declare_strict_types' => true,
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => null,
'import_functions' => true,
],
'native_constant_invocation' => [
'fix_built_in' => false,
],
'ordered_imports' => [
'imports_order' => [
'class',
'function',
'const',
],
],
'php_unit_method_casing' => [
'case' => 'snake_case',
],
'php_unit_test_annotation' => [
'style' => 'annotation',
],
'phpdoc_order' => true,
'semicolon_after_instruction' => true,
'strict_comparison' => true,
'strict_param' => true,
'single_line_throw' => false,
'trailing_comma_in_multiline' => [
'after_heredoc' => true,
'elements' => ['arrays', 'arguments', 'parameters'],
],
])
->setFinder($finder)
;
30 changes: 15 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
}
],
"require": {
"php": "^7.2",
"symfony/http-foundation": "^4.4||^5.0",
"symfony/http-kernel": "^4.4||^5.0",
"php": "^8.0",
"symfony/http-foundation": "^5.4||^6.0",
"symfony/http-kernel": "^5.4||^6.0",
"nocarrier/hal": "^0.9.4"
},
"suggest": {
Expand All @@ -25,23 +25,23 @@
"symfony/serializer": "For using RequestBodyDecoder"
},
"require-dev": {
"roave/security-advisories": "dev-master",
"roave/security-advisories": "dev-latest",

"psr/log": "^1.0",
"psr/log": "^1.0||^3.0",

"symfony/event-dispatcher": "^4.4||^5.0",
"symfony/event-dispatcher": "^5.4||^6.0",

"symfony/config": "^4.4||^5.0",
"symfony/dependency-injection": "^4.4||^5.0",
"symfony/config": "^5.4||^6.0",
"symfony/dependency-injection": "^5.4||^6.0",

"symfony/form": "^4.4||^5.0",
"symfony/translation": "^4.4||^5.0",
"symfony/validator": "^4.4||^5.0",
"symfony/security-core": "^4.4||^5.0",
"symfony/serializer": "^4.4||^5.0",
"symfony/form": "^5.4||^6.0",
"symfony/translation": "^5.4||^6.0",
"symfony/validator": "^5.4||^6.0",
"symfony/security-core": "^5.4||^6.0",
"symfony/serializer": "^5.4||^6.0",

"willdurand/negotiation": "^2.0",
"phpunit/phpunit": "^8.5",
"willdurand/negotiation": "^3.0",
"phpunit/phpunit": "^9.5",

"friendsofphp/php-cs-fixer": "^3.0"
},
Expand Down
12 changes: 6 additions & 6 deletions src/EventListener/ExceptionConversionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@

final class ExceptionConversionListener implements EventSubscriberInterface
{
private $logger;
private $prettyPrint;
private $debug;
private $formats;
private ?LoggerInterface $logger;
private bool $prettyPrint;
private bool $debug;
private ?array $formats;

public function __construct(
LoggerInterface $logger = null,
bool $prettyPrint = true,
bool $debug = false,
array $formats = null
array $formats = null,
) {
$this->logger = $logger;
$this->prettyPrint = $prettyPrint;
Expand All @@ -38,7 +38,7 @@ public function onKernelException(ExceptionEvent $event): void
$this->logger,
$this->prettyPrint,
$this->debug,
$this->formats
$this->formats,
);

if ($response instanceof Response) {
Expand Down
8 changes: 4 additions & 4 deletions src/EventListener/RequestFormatNegotiationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

final class RequestFormatNegotiationListener implements EventSubscriberInterface
{
private $formats;
private $priorities;
private ?array $formats;
private ?array $priorities;

public function __construct(
array $formats = null,
array $priorities = null
array $priorities = null,
) {
$this->formats = $formats;
$this->priorities = $priorities;
Expand All @@ -27,7 +27,7 @@ public function onKernelRequest(RequestEvent $event): void
RequestFormatNegotiator::negotiate(
$event->getRequest(),
$this->formats,
$this->priorities
$this->priorities,
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/EventListener/RequestFormatValidationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

final class RequestFormatValidationListener implements EventSubscriberInterface
{
private $acceptableFormats;
private $exclude;
private ?array $acceptableFormats;
private array | string | null $exclude;

public function __construct(
array $acceptableFormats = null,
$exclude = null
array | string | null $exclude = null,
) {
$this->acceptableFormats = $acceptableFormats;
$this->exclude = $exclude;
Expand All @@ -28,7 +28,7 @@ public function onKernelRequest(RequestEvent $event): void
$response = RequestFormatValidator::intercept(
$event->getRequest(),
$this->acceptableFormats,
$this->exclude
$this->exclude,
);

if ($response instanceof Response) {
Expand Down
8 changes: 4 additions & 4 deletions src/EventListener/ResponseConversionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

final class ResponseConversionListener implements EventSubscriberInterface
{
private $prettyPrint;
private bool $prettyPrint;

public function __construct($prettyPrint = true)
public function __construct(bool $prettyPrint = true)
{
$this->prettyPrint = (bool) $prettyPrint;
$this->prettyPrint = $prettyPrint;
}

public function onKernelView(ViewEvent $event): void
Expand All @@ -25,7 +25,7 @@ public function onKernelView(ViewEvent $event): void

if ($hal instanceof Hal) {
$event->setResponse(
new HalResponse($hal, 200, [], $this->prettyPrint)
new HalResponse($hal, 200, [], $this->prettyPrint),
);
}
}
Expand Down
16 changes: 9 additions & 7 deletions src/Exception/ErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@

use Nocarrier\Hal;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Throwable;
use function is_array;

final class ErrorException extends BadRequestHttpException implements HalException
{
private $errors;
private $logref;
private array $errors;
private mixed $logref;

public function __construct(
array $errors,
$message = null,
$logref = null,
\Throwable $previous = null,
$code = 0
string $message = '',
mixed $logref = null,
Throwable $previous = null,
int $code = 0,
) {
parent::__construct($message, $previous, $code);

Expand Down Expand Up @@ -45,7 +47,7 @@ public function getHal(): Hal
private function appendErrors(Hal $hal, array $errors): void
{
foreach ($errors as $error) {
if (!\is_array($error)) {
if (!is_array($error)) {
$error = [
'message' => (string) $error,
];
Expand Down
15 changes: 8 additions & 7 deletions src/Exception/FormErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Throwable;

final class FormErrorException extends BadRequestHttpException implements HalException
{
private $form;
private $logref;
private FormInterface $form;
private mixed $logref;

public function __construct(
FormInterface $form,
$message = null,
$logref = null,
\Throwable $previous = null,
$code = 0
string $message = '',
mixed $logref = null,
Throwable $previous = null,
int $code = 0,
) {
parent::__construct($message, $previous, $code);

Expand Down Expand Up @@ -97,6 +98,6 @@ private function getPath(FormInterface $form): string
// Remove root form
array_shift($path);

return '/'.implode('/', $path);
return '/' . implode('/', $path);
}
}
15 changes: 8 additions & 7 deletions src/Exception/ValidationErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
use Nocarrier\Hal;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\ConstraintViolationListInterface;
use Throwable;

final class ValidationErrorException extends BadRequestHttpException implements HalException
{
private $violationList;
private $logref;
private ConstraintViolationListInterface $violationList;
private mixed $logref;

public function __construct(
ConstraintViolationListInterface $violationList,
$message = null,
$logref = null,
\Throwable $previous = null,
$code = 0
string $message = '',
mixed $logref = null,
Throwable $previous = null,
int $code = 0,
) {
parent::__construct($message, $previous, $code);

Expand All @@ -40,7 +41,7 @@ public function getHal(): Hal

foreach ($this->violationList as $violation) {
$path = str_replace('][', '/', $violation->getPropertyPath());
$path = '/'.trim($path, '[]');
$path = '/' . trim($path, '[]');

$data = [
'message' => $violation->getMessage(),
Expand Down

0 comments on commit d8bc257

Please sign in to comment.