Skip to content

Commit 9f909ea

Browse files
naimsolonggithub-actions[bot]
authored andcommitted
Fix styling
1 parent 3a5936c commit 9f909ea

File tree

10 files changed

+35
-67
lines changed

10 files changed

+35
-67
lines changed

config/data-extractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@
3838
'sanitize' => [
3939
'password',
4040
'remember_token',
41-
]
41+
],
4242
];

src/Builder/BaseBuilder.php

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,21 @@ abstract class BaseBuilder
66
{
77
/**
88
* The name of the schema.
9-
*
10-
* @var string
119
*/
1210
protected string $schemaName;
1311

1412
/**
1513
* The columns available on schema.
16-
*
17-
* @var array
1814
*/
1915
protected array $columns;
2016

2117
/**
2218
* The data to be processed.
23-
*
24-
* @var array
2519
*/
2620
protected array $data;
2721

2822
/**
2923
* Get the schema name.
30-
*
31-
* @return string
3224
*/
3325
public function getSchemaName(): string
3426
{
@@ -37,9 +29,6 @@ public function getSchemaName(): string
3729

3830
/**
3931
* Set the schema name.
40-
*
41-
* @param string $schemaName
42-
* @return self
4332
*/
4433
public function setSchemaName(string $schemaName): self
4534
{
@@ -50,8 +39,6 @@ public function setSchemaName(string $schemaName): self
5039

5140
/**
5241
* Get the columns.
53-
*
54-
* @return array
5542
*/
5643
public function getColumns(): array
5744
{
@@ -60,9 +47,6 @@ public function getColumns(): array
6047

6148
/**
6249
* Set the columns.
63-
*
64-
* @param array $columns
65-
* @return self
6650
*/
6751
public function setColumns(array $columns): self
6852
{
@@ -73,8 +57,6 @@ public function setColumns(array $columns): self
7357

7458
/**
7559
* Get the data.
76-
*
77-
* @return array
7860
*/
7961
public function getData(): array
8062
{
@@ -83,14 +65,11 @@ public function getData(): array
8365

8466
/**
8567
* Set the data.
86-
*
87-
* @param array $data
88-
* @return self
8968
*/
9069
public function setData(array $data): self
9170
{
9271
$this->data = $data;
93-
72+
9473
return $this;
9574
}
9675

@@ -100,4 +79,4 @@ public function setData(array $data): self
10079
* @return mixed
10180
*/
10281
abstract public function build();
103-
}
82+
}

src/Builder/CsvBuilder.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,25 @@ class CsvBuilder extends BaseBuilder
66
{
77
/**
88
* Build the data as CSV format.
9-
*
10-
* @return string
119
*/
1210
public function build(): string
1311
{
1412
$csv = '';
15-
13+
1614
// Add header row
17-
$csv .= implode(',', $this->columns) . "\n";
18-
15+
$csv .= implode(',', $this->columns)."\n";
16+
1917
// Add data rows
2018
foreach ($this->data as $row) {
2119
$csvRow = [];
2220
foreach ($this->columns as $column) {
2321
$value = $row[$column] ?? '';
2422
// Escape CSV values
25-
$csvRow[] = '"' . str_replace('"', '""', $value) . '"';
23+
$csvRow[] = '"'.str_replace('"', '""', $value).'"';
2624
}
27-
$csv .= implode(',', $csvRow) . "\n";
25+
$csv .= implode(',', $csvRow)."\n";
2826
}
29-
27+
3028
return $csv;
3129
}
32-
}
30+
}

src/Builder/ExtractBuilder.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
class ExtractBuilder
99
{
1010
public const FORMAT_CSV = 'csv';
11+
1112
public const FORMAT_SQL = 'sql';
1213

1314
public const DEFAULT_FORMAT = self::FORMAT_SQL;
@@ -19,22 +20,20 @@ class ExtractBuilder
1920

2021
/**
2122
* The model instance.
22-
*
23-
* @var mixed
2423
*/
2524
protected mixed $model;
2625

2726
protected CsvBuilder|SqlBuilder $builder;
2827

2928
public function createBuilder(string $type): self
3029
{
31-
if (!in_array($type, self::FORMATS, true)) {
30+
if (! in_array($type, self::FORMATS, true)) {
3231
throw new InvalidArgumentException("Invalid builder type: {$type}");
3332
}
3433

3534
$this->builder = match ($type) {
36-
self::FORMAT_CSV => new CsvBuilder(),
37-
self::FORMAT_SQL => new SqlBuilder(),
35+
self::FORMAT_CSV => new CsvBuilder,
36+
self::FORMAT_SQL => new SqlBuilder,
3837
default => throw new InvalidArgumentException("Unsupported builder type: {$type}"),
3938
};
4039

@@ -53,8 +52,6 @@ public function asSql(): self
5352

5453
/**
5554
* Get the model instance.
56-
*
57-
* @return mixed
5855
*/
5956
public function getModel(): mixed
6057
{
@@ -63,9 +60,6 @@ public function getModel(): mixed
6360

6461
/**
6562
* Set the model instance.
66-
*
67-
* @param mixed $model
68-
* @return self
6963
*/
7064
public function setModel(mixed $model): self
7165
{
@@ -76,11 +70,11 @@ public function setModel(mixed $model): self
7670

7771
public function build(): string
7872
{
79-
if (!isset($this->builder)) {
73+
if (! isset($this->builder)) {
8074
throw new RuntimeException('Builder not initialized. Call asCsv() or asSql() first.');
8175
}
8276

83-
if (!isset($this->model)) {
77+
if (! isset($this->model)) {
8478
throw new RuntimeException('Model not set. Use setModel() to set the model before building.');
8579
}
8680

@@ -91,4 +85,4 @@ public function build(): string
9185

9286
return $this->builder->build();
9387
}
94-
}
88+
}

src/Builder/SqlBuilder.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ class SqlBuilder extends BaseBuilder
66
{
77
/**
88
* Build the data as SQL INSERT statements.
9-
*
10-
* @return string
119
*/
1210
public function build(): string
1311
{
1412
$sql = '';
15-
13+
1614
foreach ($this->data as $row) {
1715
$values = [];
1816
foreach ($this->columns as $column) {
@@ -21,7 +19,7 @@ public function build(): string
2119
if (is_array($value)) {
2220
$values[] = "'".json_encode($value, JSON_UNESCAPED_UNICODE)."'";
2321
} elseif (is_null($value)) {
24-
$values[] = "NULL";
22+
$values[] = 'NULL';
2523
} elseif (is_numeric($value)) {
2624
$values[] = $value;
2725
} elseif (is_bool($value)) {
@@ -30,10 +28,10 @@ public function build(): string
3028
$values[] = "'".addslashes($value)."'";
3129
}
3230
}
33-
34-
$sql .= "INSERT INTO {$this->schemaName} (" . implode(', ', $this->columns) . ") VALUES (" . implode(', ', $values) . ");\n";
31+
32+
$sql .= "INSERT INTO {$this->schemaName} (".implode(', ', $this->columns).') VALUES ('.implode(', ', $values).");\n";
3533
}
36-
34+
3735
return $sql;
3836
}
39-
}
37+
}

src/Dto/Export.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace NaimSolong\DataExtractor\Dto;
44

5-
use InvalidArgumentException;
6-
75
readonly class Export
86
{
97
public function __construct(
@@ -29,4 +27,4 @@ public function toArray(): array
2927
'disk' => $this->disk,
3028
];
3129
}
32-
}
30+
}

src/Dto/Instruction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ public function toArray(): array
3535
'export' => $this->export->toArray(),
3636
];
3737
}
38-
}
38+
}

src/Dto/Source.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ public function toArray(): array
2727
'relationships' => $this->relationships,
2828
];
2929
}
30-
}
30+
}

src/Extract.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
use Illuminate\Database\Eloquent\ModelNotFoundException;
66
use NaimSolong\DataExtractor\Builder\ExtractBuilder;
77

8-
class Extract {
8+
class Extract
9+
{
910
protected int $queryId;
1011

1112
protected InstructionsResolver $instructions;
12-
13+
1314
protected ExtractBuilder $builder;
1415

1516
public function __construct()
@@ -50,7 +51,7 @@ public function query(string $format): string
5051
$data = $query->first();
5152

5253
ray($data);
53-
54+
5455
return $this->builder
5556
->setModel($data)
5657
->build();

src/InstructionsResolver.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use NaimSolong\DataExtractor\Dto\Instruction;
88
use NaimSolong\DataExtractor\Dto\Source;
99

10-
class InstructionsResolver {
11-
10+
class InstructionsResolver
11+
{
1212
protected array $instructions = [];
1313

1414
protected Instruction $instruction;
@@ -47,15 +47,15 @@ public function set(int|string $value): self
4747

4848
return $this;
4949
}
50-
50+
5151
if (is_string($value)) {
52-
$this->instruction = array_filter($this->instructions, function($instruction) use ($value) {
52+
$this->instruction = array_filter($this->instructions, function ($instruction) use ($value) {
5353
return $instruction->name === $value;
5454
})[0];
5555

5656
return $this;
5757
}
58-
58+
5959
throw new InvalidArgumentException("Invalid instruction value: {$value}");
6060
}
6161

0 commit comments

Comments
 (0)