Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gammamatrix committed Dec 28, 2024
1 parent e1b7a0a commit 0d3db1d
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
3 changes: 3 additions & 0 deletions src/Models/Concerns/WithModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
namespace Playground\Models\Concerns;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;

/**
Expand All @@ -15,6 +16,8 @@ trait WithModifier
{
/**
* Access the modifier of this model.
*
* @return HasOne<Model>
*/
public function modifier(): HasOne
{
Expand Down
7 changes: 5 additions & 2 deletions src/Models/Concerns/WithParent.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

declare(strict_types=1);
/**
* Playground
*/

declare(strict_types=1);
namespace Playground\Models\Concerns;

use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Model;

/**
* \Playground\Models\Concerns\WithParent
Expand All @@ -15,6 +16,8 @@ trait WithParent
{
/**
* Access the parent of this model.
*
* @return HasOne<Model>
*/
public function parent(): HasOne
{
Expand Down
4 changes: 2 additions & 2 deletions src/Models/Contracts/WithParent.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

declare(strict_types=1);
/**
* Playground
*/

declare(strict_types=1);
namespace Playground\Models\Contracts;

use Illuminate\Database\Eloquent\Model;
Expand Down
25 changes: 21 additions & 4 deletions src/Models/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Playground\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Carbon;
Expand All @@ -29,15 +30,17 @@
* @property ?scalar $owned_by_id
* @property string $matrix
* @property ?double $r
* @property ?double $θ
* @property ?double $ρ
* @property ?double $φ
* @property ?double $theta
* @property ?double $rho
* @property ?double $phi
* @property ?double $elevation
* @property ?double $latitude
* @property ?double $longitude
* @property ?int $x
* @property ?int $y
* @property ?int $z
*
* @mixin UuidModel
*/
abstract class Model extends UuidModel implements
Contracts\WithChildren,
Expand All @@ -52,14 +55,28 @@ abstract class Model extends UuidModel implements
use Concerns\WithModifier;
use Concerns\WithOwner;
use Concerns\WithParent;
use HasFactory;
use Scopes\ScopeFilterColumns;
use Scopes\ScopeFilterDates;
use Scopes\ScopeFilterFlags;
use Scopes\ScopeFilterIds;
use Scopes\ScopeFilterTrash;
use Scopes\ScopeSort;
use Scopes\ScopeIsActive;
use Scopes\ScopeIsNotClosed;
use SoftDeletes;

protected $perPage = 15;

/**
* @return Attribute<string, string>
*/
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'];
// },
);
}
}
28 changes: 28 additions & 0 deletions src/Models/Scopes/ScopeIsActive.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Playground
*/

declare(strict_types=1);
namespace Playground\Models\Scopes;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
* \Playground\Models\Scopes\ScopeIsActive
*/
trait ScopeIsActive
{
/**
* @param Builder<Model> $query
* @return Builder<Model>
*/
public static function scopeIsActive(
Builder $query,
): Builder {
$query->where('active', 1);

return $query;
}
}
28 changes: 28 additions & 0 deletions src/Models/Scopes/ScopeIsNotClosed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Playground
*/

declare(strict_types=1);
namespace Playground\Models\Scopes;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
* \Playground\Models\Scopes\ScopeIsNotClosed
*/
trait ScopeIsNotClosed
{
/**
* @param Builder<Model> $query
* @return Builder<Model>
*/
public static function scopeIsNotClosed(
Builder $query,
): Builder {
$query->whereNull('closed_at');

return $query;
}
}
28 changes: 28 additions & 0 deletions src/Models/Scopes/ScopeIsPublished.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Playground
*/

declare(strict_types=1);
namespace Playground\Models\Scopes;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
* \Playground\Models\Scopes\ScopeIsPublished
*/
trait ScopeIsPublished
{
/**
* @param Builder<Model> $query
* @return Builder<Model>
*/
public static function scopeIsPublished(
Builder $query,
): Builder {
$query->whereNotNull('published_at');

return $query;
}
}
4 changes: 2 additions & 2 deletions src/Models/Scopes/ScopeSort.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

declare(strict_types=1);
/**
* Playground
*/

declare(strict_types=1);
namespace Playground\Models\Scopes;

use Illuminate\Database\Eloquent\Builder;
Expand Down
2 changes: 2 additions & 0 deletions src/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
namespace Playground\Models;

use Database\Factories\Playground\Models\UserFactory;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
Expand Down Expand Up @@ -97,6 +98,7 @@ class User extends Authenticatable implements
use Concerns\Role;
use Concerns\WithCreator;
use Concerns\WithModifier;
/** @use HasFactory<UserFactory> */
use HasFactory;
use HasUuids;
use Notifiable;
Expand Down
1 change: 1 addition & 0 deletions src/Models/UuidModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 0d3db1d

Please sign in to comment.