From 0d3db1db67452cb2d00b5f68c0e98142edc16d0f Mon Sep 17 00:00:00 2001 From: Jeremy Postlethwaite Date: Sat, 28 Dec 2024 11:06:54 -0800 Subject: [PATCH] GH-27 --- .github/workflows/ci.yml | 2 +- README.md | 2 +- composer.json | 2 +- src/Models/Concerns/WithModifier.php | 3 +++ src/Models/Concerns/WithParent.php | 7 +++++-- src/Models/Contracts/WithParent.php | 4 ++-- src/Models/Model.php | 25 +++++++++++++++++++---- src/Models/Scopes/ScopeIsActive.php | 28 ++++++++++++++++++++++++++ src/Models/Scopes/ScopeIsNotClosed.php | 28 ++++++++++++++++++++++++++ src/Models/Scopes/ScopeIsPublished.php | 28 ++++++++++++++++++++++++++ src/Models/Scopes/ScopeSort.php | 4 ++-- src/Models/User.php | 2 ++ src/Models/UuidModel.php | 1 + 13 files changed, 123 insertions(+), 13 deletions(-) create mode 100644 src/Models/Scopes/ScopeIsActive.php create mode 100644 src/Models/Scopes/ScopeIsNotClosed.php create mode 100644 src/Models/Scopes/ScopeIsPublished.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5cd1999..48f0438 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -127,7 +127,7 @@ jobs: user_email: 'github-actions[bot]@users.noreply.github.com' - uses: php-actions/phpstan@v3 with: - level: 9 + level: 2 php_version: "8.2" path: config/ database/ src/ tests/Feature/ tests/Unit/ args: --verbose --debug diff --git a/README.md b/README.md index 9ee3944..79008a8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Playground CI Workflow](https://github.com/gammamatrix/playground/actions/workflows/ci.yml/badge.svg?branch=develop)](https://raw.githubusercontent.com/gammamatrix/playground/testing/develop/testdox.txt) [![Test Coverage](https://raw.githubusercontent.com/gammamatrix/playground/testing/develop/coverage.svg)](tests) -[![PHPStan Level 9 src and tests](https://img.shields.io/badge/PHPStan-level%209-brightgreen)](.github/workflows/ci.yml#L120) +[![PHPStan Level 2 src and tests](https://img.shields.io/badge/PHPStan-level%202-brightgreen)](.github/workflows/ci.yml#L128) This is the base package for Playground. diff --git a/composer.json b/composer.json index 4f32fd5..1cb8c58 100644 --- a/composer.json +++ b/composer.json @@ -69,6 +69,6 @@ "analyse": "vendor/bin/phpstan analyse --verbose --debug --level max", "cloc": "cloc --exclude-dir=output,vendor .", "format": "vendor/bin/php-cs-fixer fix", - "test": "vendor/bin/phpunit" + "test": "vendor/bin/testbench package:test" } } diff --git a/src/Models/Concerns/WithModifier.php b/src/Models/Concerns/WithModifier.php index 53e7e88..83174df 100644 --- a/src/Models/Concerns/WithModifier.php +++ b/src/Models/Concerns/WithModifier.php @@ -6,6 +6,7 @@ */ namespace Playground\Models\Concerns; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasOne; /** @@ -15,6 +16,8 @@ trait WithModifier { /** * Access the modifier of this model. + * + * @return HasOne */ public function modifier(): HasOne { diff --git a/src/Models/Concerns/WithParent.php b/src/Models/Concerns/WithParent.php index 6c3fd2c..1e1a96f 100644 --- a/src/Models/Concerns/WithParent.php +++ b/src/Models/Concerns/WithParent.php @@ -1,12 +1,13 @@ */ public function parent(): HasOne { diff --git a/src/Models/Contracts/WithParent.php b/src/Models/Contracts/WithParent.php index 5099aa9..ccebc5c 100644 --- a/src/Models/Contracts/WithParent.php +++ b/src/Models/Contracts/WithParent.php @@ -1,9 +1,9 @@ + */ + protected function labelOrTitle(): Attribute + { + return Attribute::make( + get: fn (mixed $value, array $attributes) => $attributes['label'] ?: $attributes['title'], + // get: function (string|null $value, array $attributes) { + // return $attributes['label'] ?: $attributes['title']; + // }, + ); + } } diff --git a/src/Models/Scopes/ScopeIsActive.php b/src/Models/Scopes/ScopeIsActive.php new file mode 100644 index 0000000..4e2ce1b --- /dev/null +++ b/src/Models/Scopes/ScopeIsActive.php @@ -0,0 +1,28 @@ + $query + * @return Builder + */ + public static function scopeIsActive( + Builder $query, + ): Builder { + $query->where('active', 1); + + return $query; + } +} diff --git a/src/Models/Scopes/ScopeIsNotClosed.php b/src/Models/Scopes/ScopeIsNotClosed.php new file mode 100644 index 0000000..2265066 --- /dev/null +++ b/src/Models/Scopes/ScopeIsNotClosed.php @@ -0,0 +1,28 @@ + $query + * @return Builder + */ + public static function scopeIsNotClosed( + Builder $query, + ): Builder { + $query->whereNull('closed_at'); + + return $query; + } +} diff --git a/src/Models/Scopes/ScopeIsPublished.php b/src/Models/Scopes/ScopeIsPublished.php new file mode 100644 index 0000000..6001a9a --- /dev/null +++ b/src/Models/Scopes/ScopeIsPublished.php @@ -0,0 +1,28 @@ + $query + * @return Builder + */ + public static function scopeIsPublished( + Builder $query, + ): Builder { + $query->whereNotNull('published_at'); + + return $query; + } +} diff --git a/src/Models/Scopes/ScopeSort.php b/src/Models/Scopes/ScopeSort.php index f4d755a..6984f5c 100644 --- a/src/Models/Scopes/ScopeSort.php +++ b/src/Models/Scopes/ScopeSort.php @@ -1,9 +1,9 @@ */ use HasFactory; use HasUuids; use Notifiable; diff --git a/src/Models/UuidModel.php b/src/Models/UuidModel.php index c41f1e6..e0715f4 100644 --- a/src/Models/UuidModel.php +++ b/src/Models/UuidModel.php @@ -13,6 +13,7 @@ * \Playground\Models\UuidModel * * Models that extend this class use a UUID for a primary key. + * @mixin Model */ abstract class UuidModel extends Model {