Skip to content

Commit 6cf2ac9

Browse files
Merge pull request #1111 from liberu-genealogy/sweep/Refactor-and-Improve-Code-Quality-in-Genealogy-Laravel-Project
Refactor and Improve Code Quality in Genealogy Laravel Project
2 parents 67f9848 + 55d04b6 commit 6cf2ac9

File tree

15 files changed

+127
-215
lines changed

15 files changed

+127
-215
lines changed

app/Filament/App/Resources/RepositoryResource.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Filament\App\Resources;
46

57
use App\Filament\App\Resources\RepositoryResource\Pages;
@@ -10,7 +12,7 @@
1012
use Filament\Tables;
1113
use Filament\Tables\Table;
1214

13-
class RepositoryResource extends Resource
15+
final class RepositoryResource extends Resource
1416
{
1517
protected static ?string $model = Repository::class;
1618

@@ -25,7 +27,7 @@ public static function form(Form $form): Form
2527
return $form
2628
->schema([
2729
Forms\Components\TextInput::make('group')
28-
->maxLength(255),
30+
->maxLength(255),
2931
Forms\Components\TextInput::make('gid')
3032
->numeric(),
3133
Forms\Components\TextInput::make('name')
@@ -52,7 +54,8 @@ public static function form(Form $form): Form
5254
Forms\Components\TextInput::make('fax')
5355
->maxLength(255),
5456
Forms\Components\TextInput::make('www')
55-
->maxLength(255),
57+
->maxLength(255)
58+
->url(),
5659
]);
5760
}
5861

@@ -100,9 +103,7 @@ public static function table(Table $table): Table
100103
->sortable()
101104
->toggleable(isToggledHiddenByDefault: true),
102105
])
103-
->filters([
104-
//
105-
])
106+
->filters([])
106107
->actions([
107108
Tables\Actions\EditAction::make(),
108109
])
@@ -115,17 +116,15 @@ public static function table(Table $table): Table
115116

116117
public static function getRelations(): array
117118
{
118-
return [
119-
//
120-
];
119+
return [];
121120
}
122121

123122
public static function getPages(): array
124123
{
125124
return [
126-
'index' => Pages\ListRepositories::route('/'),
125+
'index' => Pages\ListRepositories::route('/'),
127126
'create' => Pages\CreateRepository::route('/create'),
128-
'edit' => Pages\EditRepository::route('/{record}/edit'),
127+
'edit' => Pages\EditRepository::route('/{record}/edit'),
129128
];
130129
}
131-
}
130+
}

app/Filament/App/Resources/SourceRepoResource.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Filament\App\Resources;
46

57
use App\Filament\App\Resources\SourceRepoResource\Pages;
@@ -10,7 +12,7 @@
1012
use Filament\Tables;
1113
use Filament\Tables\Table;
1214

13-
class SourceRepoResource extends Resource
15+
final class SourceRepoResource extends Resource
1416
{
1517
protected static ?string $model = SourceRepo::class;
1618

@@ -56,9 +58,7 @@ public static function table(Table $table): Table
5658
->sortable()
5759
->toggleable(isToggledHiddenByDefault: true),
5860
])
59-
->filters([
60-
//
61-
])
61+
->filters([])
6262
->actions([
6363
Tables\Actions\EditAction::make(),
6464
])
@@ -71,17 +71,15 @@ public static function table(Table $table): Table
7171

7272
public static function getRelations(): array
7373
{
74-
return [
75-
//
76-
];
74+
return [];
7775
}
7876

7977
public static function getPages(): array
8078
{
8179
return [
82-
'index' => Pages\ListSourceRepos::route('/'),
80+
'index' => Pages\ListSourceRepos::route('/'),
8381
'create' => Pages\CreateSourceRepo::route('/create'),
84-
'edit' => Pages\EditSourceRepo::route('/{record}/edit'),
82+
'edit' => Pages\EditSourceRepo::route('/{record}/edit'),
8583
];
8684
}
87-
}
85+
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Http\Controllers;
46

5-
class PedigreeChartController extends Controller
6-
{
7-
public function __construct()
8-
{
9-
// Placeholder for future dependency injections
10-
}
7+
use Illuminate\Http\JsonResponse;
118

12-
public function index()
9+
final readonly class PedigreeChartController extends Controller
10+
{
11+
public function index(): JsonResponse
1312
{
14-
// Placeholder method for future implementation
15-
// This could return a view or a JSON response indicating the initial state or data for the pedigree chart
16-
return response()->json(['message' => 'Pedigree Chart functionality is under development.']);
13+
return response()->json([
14+
'message' => 'Pedigree Chart functionality is under development.',
15+
'status' => 'pending'
16+
]);
1717
}
18-
}
18+
}

app/Http/Livewire/EditProfile.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Http\Livewire;
46

57
use Illuminate\Support\Facades\Auth;
68
use Livewire\Component;
79
use Livewire\Attributes\Rule;
810

9-
final class EditProfile extends Component
11+
final readonly class EditProfile extends Component
1012
{
1113
#[Rule('required|string|max:255')]
12-
public string $name;
14+
public string $name = '';
1315

1416
#[Rule('required|email|max:255')]
15-
public string $email;
17+
public string $email = '';
1618

1719
public function mount(): void
1820
{
1921
$user = Auth::user();
20-
$this->name = $user?->name;
21-
$this->email = $user?->email;
22+
$this->name = $user?->name ?? '';
23+
$this->email = $user?->email ?? '';
2224
}
2325

2426
public function updateProfile(): void
@@ -30,10 +32,11 @@ public function updateProfile(): void
3032
$this->dispatch('profile-updated');
3133
} catch (\Throwable $e) {
3234
$this->dispatch('profile-update-failed', message: $e->getMessage());
35+
throw $e;
3336
}
3437
}
3538

36-
public function render()
39+
public function render(): \Illuminate\View\View
3740
{
3841
return view('livewire.edit-profile');
3942
}

app/Jobs/ExportGedCom.php

Lines changed: 24 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Jobs;
46

57
use App\Models\Family;
@@ -12,75 +14,39 @@
1214
use Illuminate\Foundation\Bus\Dispatchable;
1315
use Illuminate\Queue\InteractsWithQueue;
1416
use Illuminate\Queue\SerializesModels;
15-
use Illuminate\Support\Facades\File;
1617
use Illuminate\Support\Facades\Log;
1718

18-
class ExportGedCom implements ShouldQueue
19+
final readonly class ExportGedCom implements ShouldQueue
1920
{
20-
use Dispatchable;
21-
use InteractsWithQueue;
22-
use Queueable;
23-
use SerializesModels;
21+
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
2422

25-
/**
26-
* Create a new job instance.
27-
*
28-
* @return void
29-
*/
30-
public function __construct(protected string $file, protected User $user)
31-
{
32-
}
23+
public function __construct(
24+
private readonly string $file,
25+
private readonly User $user,
26+
) {}
3327

34-
/**
35-
* Execute the job.
36-
*
37-
* @return void
38-
*/
39-
public function handle()
28+
public function handle(): void
4029
{
41-
// Establishing tenant connection
42-
$tenant = Manager::fromModel($this->user->company(), $this->user);
43-
$tenant->connect();
44-
45-
// Fetching all people and families related to the user
46-
$people = Person::all();
47-
$families = Family::all();
48-
49-
// Logging the count of people and families to be exported
50-
Log::info('Exporting '.$people->count().' people and '.$families->count().' families.');
30+
try {
31+
$tenant = Manager::fromModel($this->user->company(), $this->user);
32+
$tenant->connect();
5133

52-
// Generating GEDCOM content
53-
$gedcomService = new GedcomService();
54-
$content = $gedcomService->generateGedcomContent($people, $families);
34+
$people = Person::all();
35+
$families = Family::all();
5536

56-
// Storing the GEDCOM file
57-
$manager->storage()->put($this->file, $content);
58-
Log::info('GEDCOM file generated and stored: '.$this->file);
37+
Log::info("Exporting {$people->count()} people and {$families->count()} families.");
5938

60-
$up_nest = 3;
61-
$down_nest = 3;
39+
$gedcomService = new GedcomService();
40+
$content = $gedcomService->generateGedcomContent($people, $families);
6241

63-
$writer = new GedcomGenerator($p_id, $f_id, $up_nest, $down_nest);
64-
$content = $writer->getGedcomPerson();
42+
$tenant->storage()->put($this->file, $content);
6543

66-
// Log::info("content from getGedcomPerson function => \n $content");
67-
// var_dump(\Storage::disk('public')->path($this->file), "job");
68-
$manager->storage()->put($this->file, $content);
69-
// $filePath = 'public/' . $this->file;
70-
// $filePath = $manager->storage()->path($filePath);
71-
// chmod_r('/home/genealogia/domains/api.genealogia.co.uk/genealogy/storage/tenants/');
72-
// Setting permissions for the GEDCOM file
73-
exec('chmod 0644 '.$manager->storage()->path($this->file));
74-
Log::info('Permissions set for GEDCOM file.');
44+
chmod($tenant->storage()->path($this->file), 0644);
7545

76-
// Handling errors and exceptions
77-
try {
78-
// Export logic here
79-
} catch (\Exception $e) {
80-
Log::error('Error during GEDCOM export: '.$e->getMessage());
46+
Log::info('GEDCOM file generated and stored successfully.');
47+
} catch (\Throwable $e) {
48+
Log::error('Error during GEDCOM export: ' . $e->getMessage());
49+
throw $e;
8150
}
82-
//exec ("find /home/genealogia/ap -type d -exec chmod 0750 {} +");
83-
//exec ("find /path/to/folder -type f -exec chmod 0644 {} +");
84-
// var_dump($path,'path');
8551
}
86-
}
52+
}
Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,32 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Providers;
46

57
use Illuminate\Auth\Events\Registered;
68
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
79
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
8-
use Illuminate\Support\Facades\Event;
910

10-
class EventServiceProvider extends ServiceProvider
11+
final readonly class EventServiceProvider extends ServiceProvider
1112
{
12-
/**
13-
* The event to listener mappings for the application.
14-
*
15-
* @var array<class-string, array<int, class-string>>
16-
*/
17-
protected $listen = [
13+
protected array $listen = [
1814
Registered::class => [
1915
SendEmailVerificationNotification::class,
2016
],
2117
\App\Events\UserCreated::class => [
2218
\App\Listeners\AssignDefaultRole::class,
23-
],
24-
\App\Events\UserCreated::class => [
2519
\App\Listeners\CreatePersonalTeam::class,
2620
],
2721
];
2822

29-
/**
30-
* Register any events for your application.
31-
*/
3223
public function boot(): void
3324
{
3425
//
3526
}
3627

37-
/**
38-
* Determine if events and listeners should be automatically discovered.
39-
*/
4028
public function shouldDiscoverEvents(): bool
4129
{
4230
return false;
4331
}
44-
}
32+
}

0 commit comments

Comments
 (0)