Skip to content

Commit

Permalink
Merge pull request #11 from rawilk/chore/update_pint
Browse files Browse the repository at this point in the history
Update pint config
  • Loading branch information
rawilk authored Mar 6, 2024
2 parents 341c0e5 + 7e5b778 commit 3b236fd
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
ref: ${{ github.head_ref }}

- name: Laravel pint
uses: aglipanci/[email protected].0
uses: aglipanci/[email protected].1
with:
preset: laravel

Expand Down
2 changes: 2 additions & 0 deletions config/human-keys.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

return [
/*
|--------------------------------------------------------------------------
Expand Down
32 changes: 31 additions & 1 deletion pint.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,36 @@
"types_spaces": {
"space": "none"
},
"single_trait_insert_per_statement": true
"combine_consecutive_issets": true,
"combine_consecutive_unsets": true,
"declare_parentheses": true,
"declare_strict_types": true,
"explicit_string_variable": true,
"single_trait_insert_per_statement": true,
"ordered_class_elements": {
"order": [
"use_trait",
"case",
"constant",
"constant_public",
"constant_protected",
"constant_private",
"property_public",
"property_protected",
"property_private",
"construct",
"destruct",
"magic",
"phpunit",
"method_abstract",
"method_public_static",
"method_public",
"method_protected_static",
"method_protected",
"method_private_static",
"method_private"
],
"sort_algorithm": "none"
}
}
}
34 changes: 17 additions & 17 deletions src/Concerns/HasHumanKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
/** @mixin \Illuminate\Database\Eloquent\Model */
trait HasHumanKey
{
public function initializeHasHumanKey(): void
{
if (in_array($this->getKeyName(), $this->humanKeys(), true)) {
$this->keyType = 'string';
$this->incrementing = false;
}
}

public static function bootHasHumanKey(): void
{
static::creating(static function (Model $model) {
Expand All @@ -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.
*/
Expand All @@ -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();
}
}
2 changes: 2 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use Rawilk\HumanKeys\Tests\TestCase;

uses(TestCase::class)->in(__DIR__);

0 comments on commit 3b236fd

Please sign in to comment.