Skip to content

Commit

Permalink
Simplify and flip 'if' and inline the method
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Jan 8, 2023
1 parent 83483c5 commit 5703683
Showing 1 changed file with 1 addition and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function fromArray(array $array): static
public function __construct(PublicationFieldTypes|string $type, string $name, array $rules = [], ?string $tagGroup = null)
{
$this->type = $type instanceof PublicationFieldTypes ? $type : PublicationFieldTypes::from(strtolower($type));
$this->name = $this->normalizeName($name);
$this->name = str_contains($name, ' ') ? Str::kebab($name) : Str::ascii($name);
$this->rules = $rules;
$this->tagGroup = $tagGroup;
}
Expand All @@ -60,17 +60,4 @@ public function getRules(): array
{
return array_merge($this->type->rules(), $this->rules);
}

/** Normalize the selected field name to ensure it's consistent and readable */
protected function normalizeName(string $name): string
{
// As long as the name doesn't contain any spaces it should be fine as-is,
// and this allows the user to use any case convention they want.
if (! str_contains($name, ' ')) {
return Str::ascii($name);
} else {
// Otherwise we normalize it to snake_case to ensure it's readable
return Str::kebab($name);
}
}
}

0 comments on commit 5703683

Please sign in to comment.