Skip to content

Commit b7b0afe

Browse files
author
Sujan Mahmud
committed
generator code refactored
1 parent 70d425e commit b7b0afe

File tree

6 files changed

+15
-22
lines changed

6 files changed

+15
-22
lines changed

src/Contracts/ExporterContract.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44
namespace Sujan\Exporter\Contracts;
55

66

7-
8-
use Generator;
9-
107
interface ExporterContract
118
{
12-
public function set(): Generator;
13-
public function get(): void;
9+
public function makeGenerator(): \Generator;
10+
public function export(): void;
1411
}

src/Export.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
namespace Sujan\Exporter;
55

66

7-
87
class Export
98
{
109
/**
@@ -17,7 +16,7 @@ class Export
1716
*/
1817
protected $columns;
1918

20-
/*
19+
/**
2120
* @var array
2221
*/
2322
private $heading = [];
@@ -27,15 +26,15 @@ class Export
2726
*/
2827
protected $filename;
2928

30-
/*
29+
/**
3130
* Array of content types
3231
*/
3332
private $contentTypes = [
3433
'csv' => 'application/csv',
3534
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
3635
];
3736

38-
/*
37+
/**
3938
* Content type
4039
*/
4140
private $contentType;

src/ExportFromArray.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct(array $model, array $columns, string $filename)
2121
/**
2222
* @return Generator
2323
*/
24-
public function set(): Generator
24+
public function makeGenerator(): Generator
2525
{
2626
$this->openOutputStream();
2727

@@ -35,9 +35,9 @@ public function set(): Generator
3535
/**
3636
* Get data out of generator
3737
*/
38-
public function get(): void
38+
public function export(): void
3939
{
40-
$generator = $this->set();
40+
$generator = $this->makeGenerator();
4141

4242
while ($generator->valid()) {
4343
$generator->next();

src/ExportFromPDOStatement.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(PDOStatement $model, array $columns, string $filenam
2222
/**
2323
* @return Generator
2424
*/
25-
public function set(): Generator
25+
public function makeGenerator(): Generator
2626
{
2727
$this->openOutputStream();
2828

@@ -36,9 +36,9 @@ public function set(): Generator
3636
/**
3737
* Get data from PDO statement
3838
*/
39-
public function get(): void
39+
public function export(): void
4040
{
41-
$generator = $this->set();
41+
$generator = $this->makeGenerator();
4242

4343
while ($generator->valid()) {
4444
$generator->next();

src/ExportFromQueryBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(Builder $model, array $columns, string $filename)
2222
/**
2323
* @return Generator
2424
*/
25-
public function set(): Generator
25+
public function makeGenerator(): Generator
2626
{
2727
$this->openOutputStream();
2828

@@ -36,9 +36,9 @@ public function set(): Generator
3636
/*
3737
* Get data from query builder
3838
*/
39-
public function get(): void
39+
public function export(): void
4040
{
41-
$generator = $this->set();
41+
$generator = $this->makeGenerator();
4242

4343
while ($generator->valid()) {
4444
$generator->next();

src/Exporter.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Exception;
88
use Illuminate\Database\Eloquent\Builder;
99
use PDOStatement;
10-
use Sujan\Exporter\Contracts\ExporterContract;
1110

1211
class Exporter
1312
{
@@ -62,8 +61,6 @@ private function setExporter($model, $columns, $filename)
6261
throw new Exception('Type unknown');
6362
}
6463

65-
$this->exporter->set();
66-
6764
return $this;
6865
}
6966

@@ -72,6 +69,6 @@ private function setExporter($model, $columns, $filename)
7269
*/
7370
public function export(): void
7471
{
75-
$this->exporter->get();
72+
$this->exporter->export();
7673
}
7774
}

0 commit comments

Comments
 (0)