Skip to content

Commit

Permalink
update dependencies, min php 8.1, support for 8.2,8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
dakorpar committed Mar 13, 2024
1 parent 45bf097 commit a3dbde4
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 49 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/main.yml
Expand Up @@ -23,7 +23,7 @@ jobs:

strategy:
matrix:
php-version: ["8.0"]
php-version: ["8.3"]
operating-system: ["ubuntu-latest"]
fail-fast: false

Expand Down Expand Up @@ -80,14 +80,14 @@ jobs:
runs-on: "${{ matrix.operating-system }}"
strategy:
matrix:
php-version: ["8.0"]
php-version: ["8.3"]
operating-system: ["ubuntu-latest"]
composer-args: [ "" ]
include:
- php-version: "8.0"
- php-version: "8.1"
operating-system: "ubuntu-latest"
composer-args: "--prefer-lowest"
- php-version: "8.0"
- php-version: "8.3"
operating-system: "ubuntu-latest"
composer-args: "--ignore-platform-reqs"
fail-fast: false
Expand Down Expand Up @@ -147,7 +147,7 @@ jobs:

strategy:
matrix:
php-version: ["8.0"]
php-version: ["8.3"]
operating-system: ["ubuntu-latest"]
fail-fast: false

Expand Down Expand Up @@ -203,7 +203,7 @@ jobs:

strategy:
matrix:
php-version: ["8.0"]
php-version: ["8.3"]
operating-system: ["ubuntu-latest"]
fail-fast: false

Expand Down
16 changes: 8 additions & 8 deletions composer.json
Expand Up @@ -3,21 +3,21 @@
"description": "rest api",
"license": ["MIT"],
"require": {
"php": "^8.0",
"php": "^8.1",
"psr/log": "^1.1",
"nette/di": "^3.0",
"nette/application": "^3.0",
"nette/forms": "^3.1.2",
"wedo/utilities": "^2.0"
"wedo/utilities": "^2.0.4"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-deprecation-rules": "^0.12",
"phpstan/phpstan-dibi": "^0.12",
"phpstan/phpstan-nette": "^0.12",
"phpstan/phpstan-strict-rules": "^0.12",
"contributte/qa": "^0.1"
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-dibi": "^1.0",
"phpstan/phpstan-nette": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
"contributte/qa": "^0.3"
},
"autoload": {
"psr-4": {
Expand Down
44 changes: 21 additions & 23 deletions src/Controllers/Controller.php
Expand Up @@ -49,7 +49,24 @@ class Controller implements IPresenter

private IResponse $httpResponse;

private IResponse $response;
final public function getHttpRequest(): IRequest
{
return $this->httpRequest;
}

final public function getHttpResponse(): IResponse
{
return $this->httpResponse;
}

final public function injectRequestAndResponse(
IRequest $httpRequest,
IResponse $httpResponse
): void
{
$this->httpRequest = $httpRequest;
$this->httpResponse = $httpResponse;
}

/**
* @return JsonResponse
Expand All @@ -76,7 +93,7 @@ public function run(Request $request): Response

$result ??= $this->payload;

$this->setTranslatorOnJsonTranslatable($result);
$this->setTranslatorOnJsonTranslatable($result); //@phpstan-ignore-line

return new JsonResponse($result ?? $this->payload);
}
Expand All @@ -87,25 +104,6 @@ public function injectTranslator(Translator $translator): void
$this->translator = $translator;
}

final public function getHttpRequest(): IRequest
{
return $this->httpRequest;
}

final public function getHttpResponse(): IResponse
{
return $this->httpResponse;
}

final public function injectRequestAndResponse(
IRequest $httpRequest,
IResponse $httpResponse
): void
{
$this->httpRequest = $httpRequest;
$this->httpResponse = $httpResponse;
}

public function sendJson(mixed $item): void
{
$this->payload = $item;
Expand Down Expand Up @@ -185,14 +183,14 @@ protected function createParams(array $params, array $methodParams): array

$params[$key] = $reflectionClass->newInstance();
$inputData = Json::decode($post, Json::FORCE_ARRAY);
$params[$key]->buildForm($inputData);
$params[$key]->buildForm($inputData); //@phpstan-ignore-line
$params[$key]->validate();

break;
}

if ($reflectionClass->getName() === JsonDateTime::class) {
$params[$key] = new JsonDateTime($this->getHttpRequest()->getQuery($key));
$params[$key] = new JsonDateTime($this->getHttpRequest()->getQuery($key)); //@phpstan-ignore-line
}
}

Expand Down
1 change: 1 addition & 0 deletions src/DI/ApiExtension.php
Expand Up @@ -18,6 +18,7 @@ class ApiExtension extends CompilerExtension
{

/** @var ApiExtensionConfig */
// @phpstan-ignore-next-line
protected $config; //phpcs:ignore

public function __construct()
Expand Down
8 changes: 4 additions & 4 deletions src/Exceptions/ResponseException.php
Expand Up @@ -3,13 +3,13 @@
namespace Wedo\Api\Exceptions;

use Exception;
use Nette\Localization\ITranslator;
use Nette\Localization\Translator;
use Throwable;

class ResponseException extends Exception
{

/** @var string[] */
/** @var mixed[] */
protected array $parameters;

/** @var ResponseException[] */
Expand All @@ -22,7 +22,7 @@ public function __construct(string $message = '', int $code = 500, ?Throwable $p
parent::__construct($message, $code, $previous);
}

public function getTranslatedMessage(ITranslator $translator): string
public function getTranslatedMessage(Translator $translator): string
{
return $translator->translate($this->getMessage(), $this->parameters);
}
Expand Down Expand Up @@ -50,7 +50,7 @@ public function getAll(): array
}

/**
* @return string[]
* @return mixed[]
*/
public function getParameters(): array
{
Expand Down
3 changes: 2 additions & 1 deletion src/Helpers/FormBuilder.php
Expand Up @@ -43,6 +43,7 @@ public function createForm(array $properties, BaseRequest $request, Container $f
continue;
}

/** @var Container[] $values */
$values = $data[$property->getName()];

$requestTypeAttributes = $property->getAttributes(ContainerType::class);
Expand All @@ -61,7 +62,7 @@ public function createForm(array $properties, BaseRequest $request, Container $f
/** @var Container $container */
$container = $control->addContainer($key);
$item = new $requestType();
$item->buildForm($value, $container, $item);
$item->buildForm($value, $container, $item); // @phpstan-ignore-line
/** @phpstan-ignore-next-line */
$request->{$property->getName()}[] = $item;
}
Expand Down
12 changes: 8 additions & 4 deletions src/Helpers/RequestHydrator.php
Expand Up @@ -22,18 +22,22 @@ public static function castValueToBuiltInType(mixed $value, string $type, bool $
{
switch ($type) {
case 'int':
return (int) $value;
return (int) (is_numeric($value) ? $value : 0);
case 'float':
return (float) $value;
return (float) (is_numeric($value) ? $value : 0);
case 'bool':
return (bool) $value;
case 'DateTimeInterface':
if ((trim($value ?? '') === '') && $allowsNull) {
if ($value === null || (is_string($value) && trim($value) === '') && $allowsNull) {
return null;
}

return new DateTimeImmutable($value);
return new DateTimeImmutable($value); //@phpstan-ignore-line
default:
if (!is_scalar($value)) {
return null;
}

return (string) $value;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Routing/ApiRoute.php
Expand Up @@ -2,9 +2,9 @@

namespace Wedo\Api\Routing;

use Nette;
use Nette\Application\Routers\Route;
use Nette\Http\IRequest;
use Nette\Http\UrlScript;
use Nette\Routing\Router;
use Nette\Utils\Strings;

Expand Down Expand Up @@ -66,14 +66,14 @@ public function match(IRequest $context): ?array
*
* @param mixed[] $appRequest
*/
public function constructUrl(array $appRequest, Nette\Http\UrlScript $refUrl): ?string
public function constructUrl(array $appRequest, UrlScript $refUrl): ?string
{
return null;
}

/**
* @param mixed[] $paramsPart
* @return array<int, array|string|false> [$presenter, $action, mixed]
* @return array<int, array<mixed>|string|false>|null [$presenter, $action, mixed]
*/
private function getPresenterAndAction(string $url, array $paramsPart = []): ?array
{
Expand Down

0 comments on commit a3dbde4

Please sign in to comment.