Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ CONTRIBUTING.md export-ignore
pint.json export-ignore
phpstan.neon.dist export-ignore
phpunit.xml.dist export-ignore
structarmed.php export-ignore
testbench.yaml export-ignore
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"illuminate/support": "^12.0 || ^13.0"
},
"require-dev": {
"boundwize/structarmed": "^0.19.3",
"calebdw/phpstan-laravel": "^1.0",
"laravel/pint": "^1.16.2",
"orchestra/testbench": "^10.0 || ^11.0",
Expand Down Expand Up @@ -74,6 +75,7 @@
"test:lint": "pint --test",
"test:lint-fix": "pint",
"test:static": "phpstan analyze --ansi -v",
"test:architecture": "structarmed analyze",
"test:unit": "@php -d zend.assertions=1 vendor/bin/pest --no-coverage",
"test:coverage": [
"@putenv XDEBUG_MODE=coverage",
Expand All @@ -82,6 +84,7 @@
"test": [
"@test:lint",
"@test:static",
"@test:architecture",
"@test:coverage"
],
"lint": [
Expand Down
14 changes: 7 additions & 7 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ public function boot(): void
Event::subscribe(SyncSqlEntities::class);
}

$this->app->afterResolving(Schedule::class, function (Schedule $schedule) {
$this->app->afterResolving(Schedule::class, static function (Schedule $schedule) {
$manager = resolve(SqlEntityManager::class);

$manager->entities
->filter(fn ($entity) => $entity instanceof MaterializedView)
->each(function ($entity) use ($schedule) {
->filter(static fn ($entity) => $entity instanceof MaterializedView)
->each(static function ($entity) use ($schedule) {
$frequency = $entity->schedule(new Frequency());

if ($frequency === null) {
Expand All @@ -92,10 +92,10 @@ protected function getEntities(Application $app): Collection
->in($app->basePath())
->path('database/entities'),
))
->map(fn ($file) => (string) $file->getRealPath())
->pipe(fn ($files) => collect($composer->classFromFile($files->all())))
->filter(fn ($class) => is_subclass_of($class, SqlEntity::class))
->map(fn ($class) => $app->make($class))
->map(static fn ($file) => (string) $file->getRealPath())
->pipe(static fn ($files) => collect($composer->classFromFile($files->all())))
->filter(static fn ($class) => is_subclass_of($class, SqlEntity::class))
->map(static fn ($class) => $app->make($class))
->values();
}
}
22 changes: 11 additions & 11 deletions src/SqlEntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ public function __construct(
protected DatabaseManager $db,
protected TopologicalSorter $sorter,
) {
$this->entities = $entities->keyBy(fn ($e) => $e::class);
$this->entities = $entities->keyBy(static fn ($e) => $e::class);

$sorted = $this->sorter->sort(
$this->entities,
fn ($e) => collect($e->dependencies())->map($this->get(...)),
fn ($e) => $e::class,
static fn ($e) => $e::class,
);

$this->entities = collect($sorted)->keyBy(fn ($e) => $e::class);
$this->entities = collect($sorted)->keyBy(static fn ($e) => $e::class);
}

/**
Expand Down Expand Up @@ -203,8 +203,8 @@ public function dropAll(
->reverse()
->when($connections, $this->filterByConnections(...))
->when($types, $this->filterByTypes(...))
->when(! $force && $types === null, fn ($entities) => $entities->reject(
fn ($entity) => $entity instanceof RequiresExplicitDrop,
->when(! $force && $types === null, static fn ($entities) => $entities->reject(
static fn ($entity) => $entity instanceof RequiresExplicitDrop,
))
->each($this->drop(...));
}
Expand Down Expand Up @@ -246,7 +246,7 @@ public function refreshMaterializedData(
$this->entities
->when($connections, $this->filterByConnections(...))
->when($entities, $this->filterByTypes(...))
->filter(fn ($entity) => $entity instanceof MaterializedView)
->filter(static fn ($entity) => $entity instanceof MaterializedView)
->each(function ($entity) use ($concurrent) {
$connection = $this->connection($entity->connectionName());
$grammar = $this->grammar($connection);
Expand Down Expand Up @@ -277,10 +277,10 @@ public function withoutEntities(
$groups = $this->entities
->when($connections, $this->filterByConnections(...))
->when($types, $this->filterByTypes(...))
->when(! $force && $types === null, fn ($entities) => $entities->reject(
fn ($entity) => $entity instanceof RequiresExplicitDrop,
->when(! $force && $types === null, static fn ($entities) => $entities->reject(
static fn ($entity) => $entity instanceof RequiresExplicitDrop,
))
->groupBy(fn ($e) => $e->connectionName() ?? $defaultConnection);
->groupBy(static fn ($e) => $e->connectionName() ?? $defaultConnection);

foreach ($groups as $connectionName => $entities) {
$connection = $this->connection($connectionName);
Expand Down Expand Up @@ -325,7 +325,7 @@ protected function filterByTypes(
Collection $entities,
array|string $types,
): Collection {
return $entities->filter(function ($entity) use ($types) {
return $entities->filter(static function ($entity) use ($types) {
foreach (Arr::wrap($types) as $type) {
if (is_a($entity, $type, allow_string: false)) {
return true;
Expand All @@ -349,7 +349,7 @@ protected function filterByConnections(
): Collection {
$default = $this->db->getDefaultConnection();

return $entities->filter(function ($entity) use ($connections, $default) {
return $entities->filter(static function ($entity) use ($connections, $default) {
$name = $entity->connectionName() ?? $default;

return in_array($name, Arr::wrap($connections), strict: true);
Expand Down
2 changes: 1 addition & 1 deletion src/Support/TopologicalSorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function sort(iterable $nodes, callable $edges, ?callable $getKey = null)
{
$sorted = [];
$visited = [];
$getKey ??= fn ($node) => $node;
$getKey ??= static fn ($node) => $node;

foreach ($nodes as $node) {
$this->visit($node, $edges, $sorted, $visited, $getKey);
Expand Down
42 changes: 42 additions & 0 deletions structarmed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

use Boundwize\StructArmed\Architecture;
use Boundwize\StructArmed\Preset\Preset;

return Architecture::define()
->layer('Source', 'src')
->withPresets(Preset::PSR4(), Preset::CODEQUALITY())
->layer('Contracts', 'src/Contracts')
->layer('Support', 'src/Support')
->layer('Attributes', 'src/Attributes')
->layer('Concerns', 'src/Concerns')
->layer('Entity', [
'src/Function_.php',
'src/MaterializedView.php',
'src/Procedure.php',
'src/Trigger.php',
'src/View.php',
])
->layer('Grammars', 'src/Grammars')
->layer('Manager', 'src/SqlEntityManager.php')
->layer('Console', 'src/Console')
->layer('Facades', 'src/Facades')
->layer('Listeners', 'src/Listeners')
->layer('PHPStan', 'src/PHPStan')
->layer('ServiceProvider', 'src/ServiceProvider.php')
->ruleset([
'Contracts' => [],
'Support' => [],
'Attributes' => ['Contracts'],
'Concerns' => ['+Attributes'],
'Entity' => ['+Concerns', 'Support'],
'Grammars' => ['+Entity'],
'Manager' => ['+Grammars'],
'Console' => ['+Manager'],
'Facades' => ['+Manager'],
'Listeners' => ['+Manager'],
'PHPStan' => ['+Entity'],
'ServiceProvider' => ['+Console', '+Listeners'],
]);