From d0ccc8b7c432b2bd3c5634bcb326395165acb321 Mon Sep 17 00:00:00 2001 From: rawilk Date: Wed, 6 Mar 2024 16:31:14 +0000 Subject: [PATCH] PHP Linting (Pint) --- config/human-keys.php | 2 ++ src/Concerns/HasHumanKey.php | 34 +++++++++++++++++----------------- tests/Pest.php | 2 ++ 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/config/human-keys.php b/config/human-keys.php index 03d296e..d3bfd51 100644 --- a/config/human-keys.php +++ b/config/human-keys.php @@ -1,5 +1,7 @@ getKeyName(), $this->humanKeys(), true)) { - $this->keyType = 'string'; - $this->incrementing = false; - } - } - public static function bootHasHumanKey(): void { static::creating(static function (Model $model) { @@ -34,6 +26,23 @@ public static function bootHasHumanKey(): void }); } + public static function humanKeyPrefix(): string + { + return Str::of(static::class) + ->classBasename() + ->lower() + ->limit(3, '') + ->toString(); + } + + public function initializeHasHumanKey(): void + { + if (in_array($this->getKeyName(), $this->humanKeys(), true)) { + $this->keyType = 'string'; + $this->incrementing = false; + } + } + /** * Get the columns that should receive human-readable keys. */ @@ -46,13 +55,4 @@ public function newHumanKey(): string { return HumanKeys::generate(static::humanKeyPrefix()); } - - public static function humanKeyPrefix(): string - { - return Str::of(static::class) - ->classBasename() - ->lower() - ->limit(3, '') - ->toString(); - } } diff --git a/tests/Pest.php b/tests/Pest.php index 20fe91f..26fd523 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -1,5 +1,7 @@ in(__DIR__);