Skip to content

Commit 92990e3

Browse files
committed
refactor: streamline docblocks for improved clarity and consistency
1 parent 5aeb94c commit 92990e3

File tree

8 files changed

+21
-307
lines changed

8 files changed

+21
-307
lines changed

app-modules/ImportWizard/src/Livewire/Concerns/HasColumnMapping.php

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,10 @@
99
use Livewire\Attributes\Computed;
1010
use Relaticle\ImportWizard\Filament\Imports\BaseImporter;
1111

12-
/**
13-
* Provides column mapping functionality for the Import Wizard.
14-
*
15-
* @property array<\Filament\Actions\Imports\ImportColumn> $importerColumns
16-
*/
12+
/** @property array<\Filament\Actions\Imports\ImportColumn> $importerColumns */
1713
trait HasColumnMapping
1814
{
19-
/**
20-
* Get importer columns for the selected entity type.
21-
* This is a computed property to avoid storing complex objects in Livewire state.
22-
*
23-
* @return array<ImportColumn>
24-
*/
15+
/** @return array<ImportColumn> */
2516
#[Computed]
2617
public function importerColumns(): array
2718
{
@@ -33,9 +24,6 @@ public function importerColumns(): array
3324
return $importerClass::getColumns();
3425
}
3526

36-
/**
37-
* Auto-map CSV columns to importer columns based on guesses.
38-
*/
3927
protected function autoMapColumns(): void
4028
{
4129
if ($this->csvHeaders === [] || $this->importerColumns === []) {
@@ -56,31 +44,21 @@ protected function autoMapColumns(): void
5644
->toArray();
5745
}
5846

59-
/**
60-
* Get the importer class for the selected entity type.
61-
*
62-
* @return class-string<BaseImporter>|null
63-
*/
47+
/** @return class-string<BaseImporter>|null */
6448
protected function getImporterClass(): ?string
6549
{
6650
$entities = $this->getEntities();
6751

6852
return $entities[$this->entityType]['importer'] ?? null;
6953
}
7054

71-
/**
72-
* Check if all required columns are mapped.
73-
*/
7455
public function hasAllRequiredMappings(): bool
7556
{
7657
return collect($this->importerColumns)
7758
->filter(fn (ImportColumn $column): bool => $column->isMappingRequired())
7859
->every(fn (ImportColumn $column): bool => ($this->columnMap[$column->getName()] ?? '') !== '');
7960
}
8061

81-
/**
82-
* Map a CSV column to a field, or unmap if fieldName is empty.
83-
*/
8462
public function mapCsvColumnToField(string $csvColumn, string $fieldName): void
8563
{
8664
// First, find and clear any existing mapping for this CSV column
@@ -96,19 +74,13 @@ public function mapCsvColumnToField(string $csvColumn, string $fieldName): void
9674
}
9775
}
9876

99-
/**
100-
* Unmap a column.
101-
*/
10277
public function unmapColumn(string $fieldName): void
10378
{
10479
if (isset($this->columnMap[$fieldName])) {
10580
$this->columnMap[$fieldName] = '';
10681
}
10782
}
10883

109-
/**
110-
* Get the label for a field name.
111-
*/
11284
public function getFieldLabel(string $fieldName): string
11385
{
11486
$column = collect($this->importerColumns)
@@ -117,9 +89,6 @@ public function getFieldLabel(string $fieldName): string
11789
return $column?->getLabel() ?? Str::title(str_replace('_', ' ', $fieldName));
11890
}
11991

120-
/**
121-
* Check if any unique identifier column is mapped.
122-
*/
12392
protected function hasUniqueIdentifierMapped(): bool
12493
{
12594
$importerClass = $this->getImporterClass();
@@ -144,9 +113,6 @@ protected function hasUniqueIdentifierMapped(): bool
144113
return false;
145114
}
146115

147-
/**
148-
* Get the user-friendly message for missing unique identifiers.
149-
*/
150116
protected function getMissingUniqueIdentifiersMessage(): string
151117
{
152118
$importerClass = $this->getImporterClass();

app-modules/ImportWizard/src/Livewire/Concerns/HasCsvParsing.php

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,8 @@
1111
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
1212
use Relaticle\ImportWizard\Services\CsvReaderFactory;
1313

14-
/**
15-
* Provides CSV file parsing functionality for the Import Wizard.
16-
*/
1714
trait HasCsvParsing
1815
{
19-
/**
20-
* Parse the uploaded file and extract headers and row count.
21-
*/
2216
protected function parseUploadedFile(): void
2317
{
2418
if ($this->uploadedFile === null) {
@@ -68,9 +62,6 @@ protected function parseUploadedFile(): void
6862
}
6963
}
7064

71-
/**
72-
* Persist the uploaded CSV file to storage in a session folder.
73-
*/
7465
protected function persistFile(TemporaryUploadedFile $file): ?string
7566
{
7667
try {
@@ -96,9 +87,6 @@ protected function persistFile(TemporaryUploadedFile $file): ?string
9687
}
9788
}
9889

99-
/**
100-
* Clean up temporary session folder and cache keys.
101-
*/
10290
protected function cleanupTempFile(): void
10391
{
10492
if ($this->sessionId === null) {
@@ -115,11 +103,7 @@ protected function cleanupTempFile(): void
115103
Cache::forget("import:{$this->sessionId}:team");
116104
}
117105

118-
/**
119-
* Get preview values for a specific CSV column.
120-
*
121-
* @return array<int, string>
122-
*/
106+
/** @return array<int, string> */
123107
public function getColumnPreviewValues(string $csvColumn, int $limit = 5): array
124108
{
125109
if ($this->persistedFilePath === null) {

app-modules/ImportWizard/src/Livewire/Concerns/HasImportPreview.php

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,11 @@
1515
use Relaticle\ImportWizard\Services\ImportRecordResolver;
1616
use Relaticle\ImportWizard\Services\PreviewChunkService;
1717

18-
/**
19-
* Provides import preview functionality for the Import Wizard's Preview step.
20-
*
21-
* Uses a hybrid approach:
22-
* - First batch processed synchronously for instant feedback
23-
* - Remaining rows processed in background job
24-
* - Progress tracked via Cache
25-
*
26-
* @property ImportPreviewResult|null $previewResult
27-
*/
18+
/** @property ImportPreviewResult|null $previewResult */
2819
trait HasImportPreview
2920
{
3021
private const int INITIAL_BATCH_SIZE = 50;
3122

32-
/**
33-
* Generate a preview of what the import will do.
34-
*
35-
* Processes first batch synchronously, then dispatches background job for the rest.
36-
*/
3723
protected function generateImportPreview(): void
3824
{
3925
$importerClass = $this->getImporterClass();
@@ -145,11 +131,7 @@ protected function generateImportPreview(): void
145131
}
146132
}
147133

148-
/**
149-
* Write the initial enriched CSV with header and first batch.
150-
*
151-
* @param array<int, array<string, mixed>> $rows
152-
*/
134+
/** @param array<int, array<string, mixed>> $rows */
153135
private function writeInitialEnrichedCsv(string $path, array $rows, PreviewChunkService $service): void
154136
{
155137
$writer = Writer::createFromPath($path, 'w');
@@ -161,9 +143,6 @@ private function writeInitialEnrichedCsv(string $path, array $rows, PreviewChunk
161143
}
162144
}
163145

164-
/**
165-
* Set preview progress in cache.
166-
*/
167146
private function setPreviewProgress(int $processed, int $creates, int $updates): void
168147
{
169148
Cache::put(
@@ -178,9 +157,6 @@ private function setPreviewProgress(int $processed, int $creates, int $updates):
178157
);
179158
}
180159

181-
/**
182-
* Get the preview processing status.
183-
*/
184160
public function getPreviewStatus(): string
185161
{
186162
if ($this->sessionId === null) {
@@ -190,11 +166,7 @@ public function getPreviewStatus(): string
190166
return Cache::get("import:{$this->sessionId}:status", 'pending');
191167
}
192168

193-
/**
194-
* Get the preview processing progress.
195-
*
196-
* @return array{processed: int, creates: int, updates: int, total: int}
197-
*/
169+
/** @return array{processed: int, creates: int, updates: int, total: int} */
198170
public function getPreviewProgress(): array
199171
{
200172
if ($this->sessionId === null) {
@@ -214,17 +186,11 @@ public function getPreviewProgress(): array
214186
]);
215187
}
216188

217-
/**
218-
* Check if preview processing is complete.
219-
*/
220189
public function isPreviewReady(): bool
221190
{
222191
return $this->getPreviewStatus() === 'ready';
223192
}
224193

225-
/**
226-
* Get preview result as DTO (computed from stored array data).
227-
*/
228194
#[Computed]
229195
public function previewResult(): ?ImportPreviewResult
230196
{
@@ -240,27 +206,18 @@ public function previewResult(): ?ImportPreviewResult
240206
return ImportPreviewResult::from($this->previewResultData);
241207
}
242208

243-
/**
244-
* Check if the preview indicates any records will be imported.
245-
*/
246209
public function hasRecordsToImport(): bool
247210
{
248211
return ($this->previewResultData['totalRows'] ?? 0) > 0;
249212
}
250213

251-
/**
252-
* Get the count of new records to be created.
253-
*/
254214
public function getCreateCount(): int
255215
{
256216
$progress = $this->getPreviewProgress();
257217

258218
return $progress['creates'];
259219
}
260220

261-
/**
262-
* Get the count of existing records to be updated.
263-
*/
264221
public function getUpdateCount(): int
265222
{
266223
$progress = $this->getPreviewProgress();

0 commit comments

Comments
 (0)