Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
coolsam726 authored and github-actions[bot] committed Apr 14, 2024
1 parent a43c6bb commit 0ba81b7
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 64 deletions.
29 changes: 15 additions & 14 deletions src/Commands/ModuleMakeFilamentPageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ public function handle(): int

if ($hasSoftDeletes) {
$modifyQueryUsing .= '->modifyQueryUsing(fn (Builder $query) => $query->withoutGlobalScopes([';
$modifyQueryUsing .= PHP_EOL.' SoftDeletingScope::class,';
$modifyQueryUsing .= PHP_EOL.']))';
$modifyQueryUsing .= PHP_EOL . ' SoftDeletingScope::class,';
$modifyQueryUsing .= PHP_EOL . ']))';

$tableBulkActions[] = 'Tables\Actions\RestoreBulkAction::make(),';
$tableBulkActions[] = 'Tables\Actions\ForceDeleteBulkAction::make(),';
Expand All @@ -195,7 +195,8 @@ public function handle(): int
$namespace = (count($pageNamespaces) > 1) ?
select(
label: 'Which namespace would you like to create this in?',
options: $pageNamespaces, required: true
options: $pageNamespaces,
required: true
) :
(Arr::first($pageNamespaces) ?? $module->appNamespace('Filament\\Pages'));
$path = (count($pageDirectories) > 1) ?
Expand All @@ -219,24 +220,24 @@ public function handle(): int
$view = str(str($page)
->prepend(
(string) str(empty($resource) ? "{$namespace}\\" : "{$resourceNamespace}\\{$resource}\\pages\\")
->replaceFirst($module->appNamespace().'\\', '')
->replaceFirst($module->appNamespace() . '\\', '')
)
->replace('\\', '/')
->ltrim('/')
->explode('/')
->map(fn ($segment) => Str::lower(Str::kebab($segment)))
->implode('.'))->prepend($module->getLowerName().'::');
->implode('.'))->prepend($module->getLowerName() . '::');

$path = (string) str($page)
->prepend('/')
->prepend(empty($resource) ? $path : $resourcePath."\\{$resource}\\Pages\\")
->prepend(empty($resource) ? $path : $resourcePath . "\\{$resource}\\Pages\\")
->replace('\\', '/')
->replace('//', '/')
->append('.php');

$viewPath = $module->resourcesPath(
(string) str($view)
->replace($module->getLowerName().'::', '')
->replace($module->getLowerName() . '::', '')
->replace('.', '/')
->prepend('views/')
->append('.blade.php'),
Expand All @@ -260,24 +261,24 @@ public function handle(): int
class_exists($potentialCluster) &&
is_subclass_of($potentialCluster, Cluster::class)
) {
$clusterAssignment = $this->indentString(PHP_EOL.PHP_EOL.'protected static ?string $cluster = '.class_basename($potentialCluster).'::class;');
$clusterImport = "use {$potentialCluster};".PHP_EOL;
$clusterAssignment = $this->indentString(PHP_EOL . PHP_EOL . 'protected static ?string $cluster = ' . class_basename($potentialCluster) . '::class;');
$clusterImport = "use {$potentialCluster};" . PHP_EOL;
}

if (empty($resource)) {
$this->copyStubToApp('Page', $path, [
'class' => $pageClass,
'clusterAssignment' => $clusterAssignment,
'clusterImport' => $clusterImport,
'namespace' => $namespace.($pageNamespace !== '' ? "\\{$pageNamespace}" : ''),
'namespace' => $namespace . ($pageNamespace !== '' ? "\\{$pageNamespace}" : ''),
'view' => $view,
]);
} elseif ($resourcePage === 'ManageRelatedRecords') {
$this->copyStubToApp('ResourceManageRelatedRecordsPage', $path, [
'baseResourcePage' => "Filament\\Resources\\Pages\\{$resourcePage}",
'baseResourcePageClass' => $resourcePage,
'modifyQueryUsing' => filled($modifyQueryUsing ?? null) ? PHP_EOL.$this->indentString($modifyQueryUsing, 3) : $modifyQueryUsing ?? '',
'namespace' => "{$resourceNamespace}\\{$resource}\\Pages".($pageNamespace !== '' ? "\\{$pageNamespace}" : ''),
'modifyQueryUsing' => filled($modifyQueryUsing ?? null) ? PHP_EOL . $this->indentString($modifyQueryUsing, 3) : $modifyQueryUsing ?? '',
'namespace' => "{$resourceNamespace}\\{$resource}\\Pages" . ($pageNamespace !== '' ? "\\{$pageNamespace}" : ''),
'recordTitleAttribute' => $recordTitleAttribute ?? null,
'relationship' => $relationship ?? null,
'resource' => "{$resourceNamespace}\\{$resource}",
Expand All @@ -295,9 +296,9 @@ class_exists($potentialCluster) &&
]);
} else {
$this->copyStubToApp($resourcePage === 'custom' ? 'CustomResourcePage' : 'ResourcePage', $path, [
'baseResourcePage' => 'Filament\\Resources\\Pages\\'.($resourcePage === 'custom' ? 'Page' : $resourcePage),
'baseResourcePage' => 'Filament\\Resources\\Pages\\' . ($resourcePage === 'custom' ? 'Page' : $resourcePage),
'baseResourcePageClass' => $resourcePage === 'custom' ? 'Page' : $resourcePage,
'namespace' => "{$resourceNamespace}\\{$resource}\\Pages".($pageNamespace !== '' ? "\\{$pageNamespace}" : ''),
'namespace' => "{$resourceNamespace}\\{$resource}\\Pages" . ($pageNamespace !== '' ? "\\{$pageNamespace}" : ''),
'resource' => "{$resourceNamespace}\\{$resource}",
'resourceClass' => $resourceClass,
'resourcePageClass' => $pageClass,
Expand Down
52 changes: 26 additions & 26 deletions src/Commands/ModuleMakeFilamentResourceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,16 @@ public function handle(): int
}

$pages = '';
$pages .= '\'index\' => Pages\\'.($this->option('simple') ? $manageResourcePageClass : $listResourcePageClass).'::route(\'/\'),';
$pages .= '\'index\' => Pages\\' . ($this->option('simple') ? $manageResourcePageClass : $listResourcePageClass) . '::route(\'/\'),';

if (! $this->option('simple')) {
$pages .= PHP_EOL."'create' => Pages\\{$createResourcePageClass}::route('/create'),";
$pages .= PHP_EOL . "'create' => Pages\\{$createResourcePageClass}::route('/create'),";

if ($this->option('view')) {
$pages .= PHP_EOL."'view' => Pages\\{$viewResourcePageClass}::route('/{record}'),";
$pages .= PHP_EOL . "'view' => Pages\\{$viewResourcePageClass}::route('/{record}'),";
}

$pages .= PHP_EOL."'edit' => Pages\\{$editResourcePageClass}::route('/{record}/edit'),";
$pages .= PHP_EOL . "'edit' => Pages\\{$editResourcePageClass}::route('/{record}/edit'),";
}

$tableActions = [];
Expand All @@ -162,12 +162,12 @@ public function handle(): int
$tableActions[] = 'Tables\Actions\RestoreAction::make(),';
}
} else {
$relations .= PHP_EOL.'public static function getRelations(): array';
$relations .= PHP_EOL.'{';
$relations .= PHP_EOL.' return [';
$relations .= PHP_EOL.' //';
$relations .= PHP_EOL.' ];';
$relations .= PHP_EOL.'}'.PHP_EOL;
$relations .= PHP_EOL . 'public static function getRelations(): array';
$relations .= PHP_EOL . '{';
$relations .= PHP_EOL . ' return [';
$relations .= PHP_EOL . ' //';
$relations .= PHP_EOL . ' ];';
$relations .= PHP_EOL . '}' . PHP_EOL;
}

$tableActions = implode(PHP_EOL, $tableActions);
Expand All @@ -182,13 +182,13 @@ public function handle(): int
$tableBulkActions[] = 'Tables\Actions\ForceDeleteBulkAction::make(),';
$tableBulkActions[] = 'Tables\Actions\RestoreBulkAction::make(),';

$eloquentQuery .= PHP_EOL.PHP_EOL.'public static function getEloquentQuery(): Builder';
$eloquentQuery .= PHP_EOL.'{';
$eloquentQuery .= PHP_EOL.' return parent::getEloquentQuery()';
$eloquentQuery .= PHP_EOL.' ->withoutGlobalScopes([';
$eloquentQuery .= PHP_EOL.' SoftDeletingScope::class,';
$eloquentQuery .= PHP_EOL.' ]);';
$eloquentQuery .= PHP_EOL.'}';
$eloquentQuery .= PHP_EOL . PHP_EOL . 'public static function getEloquentQuery(): Builder';
$eloquentQuery .= PHP_EOL . '{';
$eloquentQuery .= PHP_EOL . ' return parent::getEloquentQuery()';
$eloquentQuery .= PHP_EOL . ' ->withoutGlobalScopes([';
$eloquentQuery .= PHP_EOL . ' SoftDeletingScope::class,';
$eloquentQuery .= PHP_EOL . ' ]);';
$eloquentQuery .= PHP_EOL . '}';
}

$tableBulkActions = implode(PHP_EOL, $tableBulkActions);
Expand All @@ -201,16 +201,16 @@ public function handle(): int
class_exists($potentialCluster) &&
is_subclass_of($potentialCluster, Cluster::class)
) {
$clusterAssignment = $this->indentString(PHP_EOL.PHP_EOL.'protected static ?string $cluster = '.class_basename($potentialCluster).'::class;');
$clusterImport = "use {$potentialCluster};".PHP_EOL;
$clusterAssignment = $this->indentString(PHP_EOL . PHP_EOL . 'protected static ?string $cluster = ' . class_basename($potentialCluster) . '::class;');
$clusterImport = "use {$potentialCluster};" . PHP_EOL;
}

$this->copyStubToApp('Resource', $resourcePath, [
'clusterAssignment' => $clusterAssignment,
'clusterImport' => $clusterImport,
'eloquentQuery' => $this->indentString($eloquentQuery, 1),
'formSchema' => $this->indentString($this->option('generate') ? $this->getResourceFormSchema(
$modelNamespace.($modelSubNamespace !== '' ? "\\{$modelSubNamespace}" : '').'\\'.$modelClass,
$modelNamespace . ($modelSubNamespace !== '' ? "\\{$modelSubNamespace}" : '') . '\\' . $modelClass,
) : '//', 4),
'model' => ($model === 'Resource') ? "{$modelNamespace}\\Resource as ResourceModel" : "{$modelNamespace}\\{$model}",
'modelClass' => ($model === 'Resource') ? 'ResourceModel' : $modelClass,
Expand All @@ -222,7 +222,7 @@ class_exists($potentialCluster) &&
'tableActions' => $this->indentString($tableActions, 4),
'tableBulkActions' => $this->indentString($tableBulkActions, 5),
'tableColumns' => $this->indentString($this->option('generate') ? $this->getResourceTableColumns(
$modelNamespace.($modelSubNamespace !== '' ? "\\{$modelSubNamespace}" : '').'\\'.$modelClass,
$modelNamespace . ($modelSubNamespace !== '' ? "\\{$modelSubNamespace}" : '') . '\\' . $modelClass,
) : '//', 4),
'tableFilters' => $this->indentString(
$this->option('soft-deletes') ? 'Tables\Filters\TrashedFilter::make(),' : '//',
Expand All @@ -232,7 +232,7 @@ class_exists($potentialCluster) &&

if ($this->option('simple')) {
$this->copyStubToApp('ResourceManagePage', $manageResourcePagePath, [
'baseResourcePage' => 'Filament\\Resources\\Pages\\ManageRecords'.($needsAlias ? ' as BaseManageRecords' : ''),
'baseResourcePage' => 'Filament\\Resources\\Pages\\ManageRecords' . ($needsAlias ? ' as BaseManageRecords' : ''),
'baseResourcePageClass' => $needsAlias ? 'BaseManageRecords' : 'ManageRecords',
'namespace' => "{$namespace}\\{$resourceClass}\\Pages",
'resource' => "{$namespace}\\{$resourceClass}",
Expand All @@ -241,7 +241,7 @@ class_exists($potentialCluster) &&
]);
} else {
$this->copyStubToApp('ResourceListPage', $listResourcePagePath, [
'baseResourcePage' => 'Filament\\Resources\\Pages\\ListRecords'.($needsAlias ? ' as BaseListRecords' : ''),
'baseResourcePage' => 'Filament\\Resources\\Pages\\ListRecords' . ($needsAlias ? ' as BaseListRecords' : ''),
'baseResourcePageClass' => $needsAlias ? 'BaseListRecords' : 'ListRecords',
'namespace' => "{$namespace}\\{$resourceClass}\\Pages",
'resource' => "{$namespace}\\{$resourceClass}",
Expand All @@ -250,7 +250,7 @@ class_exists($potentialCluster) &&
]);

$this->copyStubToApp('ResourcePage', $createResourcePagePath, [
'baseResourcePage' => 'Filament\\Resources\\Pages\\CreateRecord'.($needsAlias ? ' as BaseCreateRecord' : ''),
'baseResourcePage' => 'Filament\\Resources\\Pages\\CreateRecord' . ($needsAlias ? ' as BaseCreateRecord' : ''),
'baseResourcePageClass' => $needsAlias ? 'BaseCreateRecord' : 'CreateRecord',
'namespace' => "{$namespace}\\{$resourceClass}\\Pages",
'resource' => "{$namespace}\\{$resourceClass}",
Expand All @@ -262,7 +262,7 @@ class_exists($potentialCluster) &&

if ($this->option('view')) {
$this->copyStubToApp('ResourceViewPage', $viewResourcePagePath, [
'baseResourcePage' => 'Filament\\Resources\\Pages\\ViewRecord'.($needsAlias ? ' as BaseViewRecord' : ''),
'baseResourcePage' => 'Filament\\Resources\\Pages\\ViewRecord' . ($needsAlias ? ' as BaseViewRecord' : ''),
'baseResourcePageClass' => $needsAlias ? 'BaseViewRecord' : 'ViewRecord',
'namespace' => "{$namespace}\\{$resourceClass}\\Pages",
'resource' => "{$namespace}\\{$resourceClass}",
Expand All @@ -283,7 +283,7 @@ class_exists($potentialCluster) &&
$editPageActions = implode(PHP_EOL, $editPageActions);

$this->copyStubToApp('ResourceEditPage', $editResourcePagePath, [
'baseResourcePage' => 'Filament\\Resources\\Pages\\EditRecord'.($needsAlias ? ' as BaseEditRecord' : ''),
'baseResourcePage' => 'Filament\\Resources\\Pages\\EditRecord' . ($needsAlias ? ' as BaseEditRecord' : ''),
'baseResourcePageClass' => $needsAlias ? 'BaseEditRecord' : 'EditRecord',
'actions' => $this->indentString($editPageActions, 3),
'namespace' => "{$namespace}\\{$resourceClass}\\Pages",
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/ModulesFilamentInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function getModule(): \Nwidart\Modules\Module
{
try {
return Module::findOrFail($this->moduleName);
} catch (ModuleNotFoundException|\Throwable $exception) {
} catch (ModuleNotFoundException | \Throwable $exception) {
if (confirm("Module $this->moduleName does not exist. Would you like to generate it?", true)) {
$this->call('module:make', ['name' => [$this->moduleName]]);

Expand Down Expand Up @@ -131,7 +131,7 @@ protected function createDefaultFilamentPlugin(): void
{
$module = $this->getModule();
$this->call('module:make:filament-plugin', [
'name' => $module->getStudlyName().'Plugin',
'name' => $module->getStudlyName() . 'Plugin',
'module' => $module->getStudlyName(),
]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Concerns/CanManipulateFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected function checkForCollision(array $paths): bool
continue;
}

if (! confirm(basename($path).' already exists, do you want to overwrite it?')) {
if (! confirm(basename($path) . ' already exists, do you want to overwrite it?')) {
$this->components->error("{$path} already exists, aborting.");

return true;
Expand All @@ -39,7 +39,7 @@ protected function copyStubToApp(string $stub, string $targetPath, array $replac
{
$filesystem = app(Filesystem::class);

$stubPath = $this->getDefaultStubPath()."/{$stub}.stub";
$stubPath = $this->getDefaultStubPath() . "/{$stub}.stub";

$stub = str($filesystem->get($stubPath));

Expand Down
10 changes: 5 additions & 5 deletions src/Concerns/GeneratesModularFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected function getArguments(): array

protected function resolveStubPath($stub): string
{
return FilamentModules::packagePath('src/Commands/'.trim($stub, DIRECTORY_SEPARATOR));
return FilamentModules::packagePath('src/Commands/' . trim($stub, DIRECTORY_SEPARATOR));
}

public function getModule(): Module
Expand All @@ -29,7 +29,7 @@ public function getModule(): Module

protected function getDefaultNamespace($rootNamespace): string
{
return trim($rootNamespace, '\\').'\\'.trim(Str::replace(DIRECTORY_SEPARATOR, '\\', $this->getRelativeNamespace()), '\\');
return trim($rootNamespace, '\\') . '\\' . trim(Str::replace(DIRECTORY_SEPARATOR, '\\', $this->getRelativeNamespace()), '\\');
}

abstract protected function getRelativeNamespace(): string;
Expand All @@ -43,7 +43,7 @@ protected function getPath($name): string
{
$name = Str::replaceFirst($this->rootNamespace(), '', $name);

return $this->getModule()->getExtraPath(str_replace('\\', '/', $name).'.php');
return $this->getModule()->getExtraPath(str_replace('\\', '/', $name) . '.php');
}

protected function possibleModels()
Expand All @@ -61,7 +61,7 @@ protected function viewPath($path = ''): string
{
$views = $this->getModule()->resourcesPath('views');

return $views.($path ? DIRECTORY_SEPARATOR.$path : $path);
return $views . ($path ? DIRECTORY_SEPARATOR . $path : $path);
}

protected function buildClass($name)
Expand Down Expand Up @@ -89,7 +89,7 @@ protected function promptForMissingArgumentsUsing(): array
{
return [
'name' => [
'What should the '.strtolower($this->type ?: 'class').' be named?',
'What should the ' . strtolower($this->type ?: 'class') . ' be named?',
match ($this->type) {
'Cast' => 'E.g. Json',
'Channel' => 'E.g. OrderChannel',
Expand Down
8 changes: 4 additions & 4 deletions src/Concerns/ModuleFilamentPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ public function register(Panel $panel): void
$module = $this->getModule();
$useClusters = config('filament-modules.clusters.enabled', false);
$panel->discoverPages(
in: $module->appPath('Filament'.DIRECTORY_SEPARATOR.'Pages'),
in: $module->appPath('Filament' . DIRECTORY_SEPARATOR . 'Pages'),
for: $module->appNamespace('\\Filament\\Pages')
);
$panel->discoverResources(
in: $module->appPath('Filament'.DIRECTORY_SEPARATOR.'Resources'),
in: $module->appPath('Filament' . DIRECTORY_SEPARATOR . 'Resources'),
for: $module->appNamespace('\\Filament\\Resources')
);
$panel->discoverWidgets(
in: $module->appPath('Filament'.DIRECTORY_SEPARATOR.'Widgets'),
in: $module->appPath('Filament' . DIRECTORY_SEPARATOR . 'Widgets'),
for: $module->appNamespace('\\Filament\\Widgets')
);

Expand All @@ -37,7 +37,7 @@ public function register(Panel $panel): void
);

if ($useClusters) {
$path = $module->appPath('Filament'.DIRECTORY_SEPARATOR.'Clusters');
$path = $module->appPath('Filament' . DIRECTORY_SEPARATOR . 'Clusters');
$namespace = $module->appNamespace('\\Filament\\Clusters');
$panel->discoverClusters(
in: $path,
Expand Down
2 changes: 1 addition & 1 deletion src/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public function execCommand(string $command, ?Command $artisan = null): void
public function packagePath(string $path = ''): string
{
//return the base path of this package
return dirname(__DIR__.'../').($path ? DIRECTORY_SEPARATOR.trim($path, DIRECTORY_SEPARATOR) : '');
return dirname(__DIR__ . '../') . ($path ? DIRECTORY_SEPARATOR . trim($path, DIRECTORY_SEPARATOR) : '');
}
}
2 changes: 1 addition & 1 deletion src/ModulesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function getModulePlugins(): array
}
// get a glob of all Filament plugins
$basePath = str(config('modules.paths.modules', 'Modules'));
$pattern = $basePath.'/*/App/Filament/*Plugin.php';
$pattern = $basePath . '/*/App/Filament/*Plugin.php';
$pluginPaths = glob($pattern);

return collect($pluginPaths)->map(fn ($path) => FilamentModules::convertPathToNamespace($path))->toArray();
Expand Down
Loading

0 comments on commit 0ba81b7

Please sign in to comment.