From a1160c9cbdd129297440b6a7cd33ab3030699045 Mon Sep 17 00:00:00 2001 From: Sebastian Meyer Date: Thu, 11 Jan 2024 14:49:43 +0100 Subject: [PATCH] Set spec as default name for sets --- src/Console/CsvImportCommand.php | 4 ++-- src/Entity/Set.php | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Console/CsvImportCommand.php b/src/Console/CsvImportCommand.php index cb68452..0e7169c 100644 --- a/src/Console/CsvImportCommand.php +++ b/src/Console/CsvImportCommand.php @@ -149,9 +149,9 @@ class CsvImportCommand extends Console } if (isset($columns['setColumn'])) { $sets = $row[$columns['setColumn']]; - foreach (explode(',', trim($sets)) as $set) { + foreach (explode(',', $sets) as $set) { /** @var Set */ - $setSpec = Database::getInstance()->getEntityManager()->getReference(Set::class, $set); + $setSpec = Database::getInstance()->getEntityManager()->getReference(Set::class, trim($set)); $record->addSet($setSpec); } } diff --git a/src/Entity/Set.php b/src/Entity/Set.php index 7ada955..e79457c 100644 --- a/src/Entity/Set.php +++ b/src/Entity/Set.php @@ -166,25 +166,25 @@ class Set extends Entity /** * Set the name for this set. * - * @param string $name The name + * @param ?string $name The name (defaults to spec) * * @return void */ - public function setName(string $name): void + public function setName(?string $name): void { - $this->name = trim($name); + $this->name = $name ?? $this->getSpec(); } /** * Get new entity of set. * * @param string $spec The set spec - * @param string $name The name of the set + * @param ?string $name The name of the set (defaults to spec) * @param string $description The description of the set * * @throws ValidationFailedException */ - public function __construct(string $spec, string $name, string $description = '') + public function __construct(string $spec, ?string $name = null, string $description = '') { try { $this->spec = $this->validateRegEx($spec, '/^([A-Za-z0-9\-_\.!~\*\'\(\)])+(:[A-Za-z0-9\-_\.!~\*\'\(\)]+)*$/');