From a676e397b9c4a090c729f21abc1862fd628a4bc6 Mon Sep 17 00:00:00 2001 From: JSweers Date: Mon, 29 Dec 2025 23:12:53 +0100 Subject: [PATCH] Refactoring of Options to Option array --- composer.json | 2 +- src/Poll/Model/Options.php | 83 ------------------------------- src/Poll/Model/Poll.php | 15 +++++- src/Poll/PollDatabaseManager.php | 54 ++++---------------- tests/PollDatabaseManagerTest.php | 10 ++-- 5 files changed, 30 insertions(+), 134 deletions(-) delete mode 100644 src/Poll/Model/Options.php diff --git a/composer.json b/composer.json index 32f379e..5203f63 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "compucie/database", "description": "Library of database managers used by Newton's systems.", - "version": "6.0.1", + "version": "6.1.0", "type": "library", "license": "MIT", "autoload": { diff --git a/src/Poll/Model/Options.php b/src/Poll/Model/Options.php deleted file mode 100644 index 2671033..0000000 --- a/src/Poll/Model/Options.php +++ /dev/null @@ -1,83 +0,0 @@ - $ids - */ - private array $ids; - /** - * @var array $texts - */ - private array $texts; - /** - * @var array $voteCounts - */ - private array $voteCounts; - - /** - * @param array $ids - * @param array $texts - * @param array $voteCounts - */ - public function __construct( - array $ids = array(), - array $texts = array(), - array $voteCounts = array(), - ) { - $this->ids = array(); - $this->texts = array(); - $this->voteCounts = array(); - - foreach ($ids as $id) { - $this->registerId($id); - } - - foreach ($texts as $id => $text) { - $this->setText((int)$id, (string)$text); - } - - foreach ($voteCounts as $id => $count) { - $this->setVoteCount((int)$id, (int)$count); - } - } - - public function getText(int $id): string - { - return $this->texts[$id] ?? ''; - } - - public function getVoteCount(int $id): int - { - return $this->voteCounts[$id] ?? 0; - } - - public function setText(int $id, string $text): void - { - $this->texts[$id] = $text; - $this->registerId($id); - } - - public function setVoteCount(int $id, int $voteCount): void - { - $this->voteCounts[$id] = $voteCount; - $this->registerId($id); - } - - /** - * @return array - */ - public function getIds(): array - { - return $this->ids; - } - - private function registerId(int $id): void - { - if (!in_array($id, $this->ids)) { - $this->ids[] = $id; - } - } -} diff --git a/src/Poll/Model/Poll.php b/src/Poll/Model/Poll.php index 2631e29..7d8b632 100644 --- a/src/Poll/Model/Poll.php +++ b/src/Poll/Model/Poll.php @@ -9,12 +9,20 @@ */ readonly class Poll { + /** + * @param int $id + * @param string $question + * @param DateTime $publishedAt + * @param DateTime $expiresAt + * @param array