From 141873d8452d8fb69d9ca4ced7a5344652e212fe Mon Sep 17 00:00:00 2001 From: Petr Kessler Date: Sun, 17 Sep 2023 19:21:26 +0200 Subject: [PATCH] fixed typing errors reported by phpstan --- src/TwiGrid/Components/Translator.php | 5 ++++- src/TwiGrid/DataGrid.php | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/TwiGrid/Components/Translator.php b/src/TwiGrid/Components/Translator.php index 69e09a0..a8ed0e3 100644 --- a/src/TwiGrid/Components/Translator.php +++ b/src/TwiGrid/Components/Translator.php @@ -49,7 +49,10 @@ public function addDictionary(array $dictionary): self } - /** @param string ...$parameters */ + /** + * @param string $message + * @param string ...$parameters + */ public function translate($message, ...$parameters): string { assert(is_string($message)); diff --git a/src/TwiGrid/DataGrid.php b/src/TwiGrid/DataGrid.php index 0534fcf..fa8997b 100644 --- a/src/TwiGrid/DataGrid.php +++ b/src/TwiGrid/DataGrid.php @@ -12,6 +12,7 @@ namespace TwiGrid; +use Nette\Utils\Arrays; use Nette\Application\UI\Link; use Nette\Http\SessionSection; use TwiGrid\Components\Action; @@ -293,7 +294,7 @@ public function setTranslator(ITranslator $translator): self public function translate(string $s, int $count = null): string { - return $this->getTranslator()->translate($s, $count); + return (string) $this->getTranslator()->translate($s, $count); } @@ -502,7 +503,20 @@ private function getRecordHandler(): RecordHandler /** @param string|string[] $primaryKey */ public function setPrimaryKey($primaryKey): self { - $this->getRecordHandler()->setPrimaryKey(is_array($primaryKey) ? $primaryKey : func_get_args()); + if (is_array($primaryKey)) { + $keys = $primaryKey; + + } else { + /** @var string[] $keys */ + $keys = func_get_args(); + + assert(Arrays::every($keys, function ($s): bool { + return is_string($s); + + }), 'Primary keys must be an array of strings.'); + } + + $this->getRecordHandler()->setPrimaryKey($keys); return $this; }