From 5b00f058987cfb676439b670771d71db1ba7faea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Tvrd=C3=ADk?= Date: Wed, 8 Mar 2023 12:57:30 +0100 Subject: [PATCH] increase phpstan level to 8 --- phpstan.neon | 2 +- src/Schema/Message.php | 2 +- src/Schema/Processor.php | 15 ++++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index bccf823..9239b06 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 6 + level: 8 checkMissingIterableValueType: false paths: diff --git a/src/Schema/Message.php b/src/Schema/Message.php index 66bff79..437d19b 100644 --- a/src/Schema/Message.php +++ b/src/Schema/Message.php @@ -95,6 +95,6 @@ public function toString(): string return preg_replace_callback('~( ?)%(\w+)%~', function ($m) use ($vars) { [, $space, $key] = $m; return $vars[$key] === null ? '' : $space . $vars[$key]; - }, $this->message); + }, $this->message) ?? throw new Nette\InvalidStateException(preg_last_error_msg()); } } diff --git a/src/Schema/Processor.php b/src/Schema/Processor.php index 7280548..2f2f8a7 100644 --- a/src/Schema/Processor.php +++ b/src/Schema/Processor.php @@ -20,7 +20,7 @@ final class Processor use Nette\SmartObject; public array $onNewContext = []; - private ?Context $context; + private Context $context; private bool $skipDefaults = false; @@ -36,7 +36,7 @@ public function skipDefaults(bool $value = true): void */ public function process(Schema $schema, mixed $data): mixed { - $this->createContext(); + $this->context = $this->createContext(); $data = $schema->normalize($data, $this->context); $this->throwsErrors(); $data = $schema->complete($data, $this->context); @@ -51,7 +51,7 @@ public function process(Schema $schema, mixed $data): mixed */ public function processMultiple(Schema $schema, array $dataset): mixed { - $this->createContext(); + $this->context = $this->createContext(); $flatten = null; $first = true; foreach ($dataset as $data) { @@ -89,10 +89,11 @@ private function throwsErrors(): void } - private function createContext(): void + private function createContext(): Context { - $this->context = new Context; - $this->context->skipDefaults = $this->skipDefaults; - Nette\Utils\Arrays::invoke($this->onNewContext, $this->context); + $context = new Context; + $context->skipDefaults = $this->skipDefaults; + Nette\Utils\Arrays::invoke($this->onNewContext, $context); + return $context; } }