Skip to content

Commit 2fddd26

Browse files
naimsolonggithub-actions[bot]
authored andcommitted
Fix styling
1 parent 36d1d05 commit 2fddd26

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

config/data-extractor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
'file_path' => 'data-extractor',
1919
'disk' => 'local',
2020
],
21-
]
21+
],
2222
],
2323

2424
'source' => [
@@ -28,6 +28,6 @@
2828
'relationships' => [
2929
'mainProfile',
3030
],
31-
]
32-
]
31+
],
32+
],
3333
];

src/Commands/DataExtractorCommand.php

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ public function __construct()
2222

2323
public function handle(): int
2424
{
25-
if (!config('data-extractor.allow_production') && app()->environment('production')) {
25+
if (! config('data-extractor.allow_production') && app()->environment('production')) {
2626
$this->error('Data extraction is not allowed in production environment.');
27+
2728
return self::FAILURE;
2829
}
2930

@@ -34,14 +35,15 @@ public function handle(): int
3435
$selectedInstructions = $this->promptInstructions();
3536

3637
$id = $this->promptModelId($selectedInstructions);
37-
38+
3839
if ($id <= 0) {
3940
return self::FAILURE;
4041
}
4142

4243
$selectedSource = $selectedInstructions['source'] ?? null;
43-
if (!$selectedSource) {
44+
if (! $selectedSource) {
4445
$this->error('No source specified in the selected instruction.');
46+
4547
return self::FAILURE;
4648
}
4749
$source = config("data-extractor.source.$selectedSource", []);
@@ -51,28 +53,28 @@ public function handle(): int
5153
->with($source['relationships'] ?? [])
5254
->where('id', $id);
5355

54-
55-
if (!$query->exists()) {
56+
if (! $query->exists()) {
5657
$this->error("No record found with ID {$id} in the {$source['model']} model.");
58+
5759
return self::FAILURE;
5860
}
5961

6062
$data = $query->first();
61-
63+
6264
$insertSql = $this->generateInsertSql($data);
6365

6466
$this->line("<info>Generated SQL Insert Statement:</info>\n$insertSql");
6567

6668
// Get loaded relationships
6769
$loadedRelations = $data->getRelations();
68-
70+
6971
// Debug: Show loaded relations context
70-
$this->line("<comment>Loaded Relations:</comment>");
72+
$this->line('<comment>Loaded Relations:</comment>');
7173
foreach ($loadedRelations as $relationName => $relationData) {
72-
$this->line(" - {$relationName}: " . (is_countable($relationData) ? count($relationData) . ' records' : 'single record'));
74+
$this->line(" - {$relationName}: ".(is_countable($relationData) ? count($relationData).' records' : 'single record'));
7375

7476
$this->line("<comment>Generated SQL for relation '{$relationName}':</comment>");
75-
if(is_countable($relationData)){
77+
if (is_countable($relationData)) {
7678
foreach ($relationData as $relation) {
7779
$insertSql = $this->generateInsertSql($relation);
7880
$this->line("\n$insertSql");
@@ -103,22 +105,22 @@ protected function validateInstructions(): bool
103105
return false;
104106
}
105107

106-
if (!in_array($instruction['export']['format'], Export::FORMATS)) {
107-
$this->error('Invalid export format in instruction: ' . $instruction['name']);
108+
if (! in_array($instruction['export']['format'], Export::FORMATS)) {
109+
$this->error('Invalid export format in instruction: '.$instruction['name']);
108110

109111
return false;
110112
}
111113

112-
if (!isset($instruction['source']) || !is_string($instruction['source']) || !in_array($instruction['source'], $sourceConnections)) {
113-
$this->error('Invalid source specified in instruction: ' . $instruction['name']);
114+
if (! isset($instruction['source']) || ! is_string($instruction['source']) || ! in_array($instruction['source'], $sourceConnections)) {
115+
$this->error('Invalid source specified in instruction: '.$instruction['name']);
114116

115117
return false;
116118
}
117119

118120
$selectedSource = config("data-extractor.source.{$instruction['source']}", []);
119121

120-
if (!isset($selectedSource['model'])) {
121-
$this->error('Invalid model configuration in source: ' . $instruction['source']);
122+
if (! isset($selectedSource['model'])) {
123+
$this->error('Invalid model configuration in source: '.$instruction['source']);
122124

123125
return false;
124126
}
@@ -141,7 +143,7 @@ protected function promptInstructions(): array
141143
);
142144

143145
$instructionNames = array_column($this->instructions, 'name');
144-
146+
145147
$selectedKey = array_keys($this->choice(
146148
'Select an instruction to execute',
147149
$instructionNames,
@@ -157,15 +159,15 @@ protected function promptModelId($instruction): int
157159
{
158160
$source = $instruction['source'] ?? null;
159161

160-
if (!$source || !is_string($source)) {
162+
if (! $source || ! is_string($source)) {
161163
$this->error('Invalid source specified in the instruction.');
162164

163165
return 0;
164166
}
165167

166168
$modelClass = config("data-extractor.source.$source.model");
167169

168-
if (!$modelClass || !class_exists($modelClass)) {
170+
if (! $modelClass || ! class_exists($modelClass)) {
169171
$this->error('Invalid model class specified in the instruction source.');
170172

171173
return 0;
@@ -184,18 +186,18 @@ protected function generateInsertSql($data): string
184186
$dataArray = $data->toArray();
185187
foreach ($dataArray as $key => $value) {
186188
if (is_array($value)) {
187-
$insertString[] = "`$key` = '" . json_encode($value, JSON_UNESCAPED_UNICODE) . "'";
189+
$insertString[] = "`$key` = '".json_encode($value, JSON_UNESCAPED_UNICODE)."'";
188190
} elseif (is_null($value)) {
189191
$insertString[] = "`$key` = NULL";
190192
} elseif (is_numeric($value)) {
191193
$insertString[] = "`$key` = $value";
192194
} elseif (is_bool($value)) {
193-
$insertString[] = "`$key` = " . ($value ? '1' : '0');
195+
$insertString[] = "`$key` = ".($value ? '1' : '0');
194196
} else {
195-
$insertString[] = "`$key` = '" . addslashes($value) . "'";
197+
$insertString[] = "`$key` = '".addslashes($value)."'";
196198
}
197199
}
198200

199-
return "INSERT INTO `{$data->getTable()}` VALUE (" . implode(', ', $insertString) . ');';
201+
return "INSERT INTO `{$data->getTable()}` VALUE (".implode(', ', $insertString).');';
200202
}
201203
}

0 commit comments

Comments
 (0)