Skip to content

Commit

Permalink
Adds WriterTemplate trait instead of AbstractWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
sagikazarmark committed May 20, 2015
1 parent 1a0c3dd commit efe2891
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 95 deletions.
10 changes: 2 additions & 8 deletions src/Writer/AbstractStreamWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/
abstract class AbstractStreamWriter implements WriterInterface
{
use WriterTemplate;

/**
* @var resource
*/
Expand Down Expand Up @@ -65,14 +67,6 @@ public function getStream()
return $this->stream;
}

/**
* {@inheritdoc}
*/
public function prepare()
{
return $this;
}

/**
* {@inheritdoc}
*/
Expand Down
37 changes: 0 additions & 37 deletions src/Writer/AbstractWriter.php

This file was deleted.

12 changes: 4 additions & 8 deletions src/Writer/ArrayWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/
class ArrayWriter implements WriterInterface
{
use WriterTemplate;

/**
* @var array
*/
Expand All @@ -28,6 +30,8 @@ public function __construct(array &$data)
public function prepare()
{
$this->data = [];

return $this;
}

/**
Expand All @@ -37,12 +41,4 @@ public function writeItem(array $item)
{
$this->data[] = $item;
}

/**
* {@inheritdoc}
*/
public function finish()
{

}
}
18 changes: 2 additions & 16 deletions src/Writer/CallbackWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/
class CallbackWriter implements WriterInterface
{
use WriterTemplate;

/**
* @var callable
*/
Expand All @@ -22,14 +24,6 @@ public function __construct(callable $callback)
$this->callback = $callback;
}

/**
* {@inheritdoc}
*/
public function prepare()
{
return $this;
}

/**
* {@inheritdoc}
*/
Expand All @@ -39,12 +33,4 @@ public function writeItem(array $item)

return $this;
}

/**
* {@inheritdoc}
*/
public function finish()
{
return $this;
}
}
2 changes: 1 addition & 1 deletion src/Writer/ConsoleProgressWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* @author David de Boer <david@ddeboer.nl>
*/
class ConsoleProgressWriter extends AbstractWriter
class ConsoleProgressWriter implements WriterInterface
{
/**
* @var OutputInterface
Expand Down
9 changes: 2 additions & 7 deletions src/Writer/ConsoleTableWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
class ConsoleTableWriter implements WriterInterface
{
use WriterTemplate;

/**
* @var OutputInterface
*/
Expand All @@ -34,13 +36,6 @@ public function __construct(OutputInterface $output, Table $table) {
$this->table = $table;
}

/**
* {@inheritdoc}
*/
public function prepare() {

}

/**
* {@inheritdoc}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Writer/DoctrineWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @author David de Boer <david@ddeboer.nl>
*/
class DoctrineWriter extends AbstractWriter
class DoctrineWriter implements WriterInterface
{
/**
* @var EntityManagerInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Writer/ExcelWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @author David de Boer <david@ddeboer.nl>
*/
class ExcelWriter extends AbstractWriter
class ExcelWriter implements WriterInterface
{
/**
* @var string
Expand Down
18 changes: 2 additions & 16 deletions src/Writer/PdoWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
class PdoWriter implements WriterInterface
{
use WriterTemplate;

/**
* @var \PDO
*/
Expand Down Expand Up @@ -44,14 +46,6 @@ public function __construct(\PDO $pdo, $tableName)
$this->tableName = $tableName;
}

/**
* {@inheritdoc}
*/
public function prepare()
{
return $this;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -86,12 +80,4 @@ public function writeItem(array $item)

return $this;
}

/**
* {@inheritdoc}
*/
public function finish()
{
return $this;
}
}
27 changes: 27 additions & 0 deletions src/Writer/WriterTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Ddeboer\DataImport\Writer;

/**
* This template can be overridden in concrete implementations
*
* @author David de Boer <david@ddeboer.nl>
*/
trait WriterTemplate
{
/**
* {@inheritdoc}
*/
public function prepare()
{
return $this;
}

/**
* {@inheritdoc}
*/
public function finish()
{
return $this;
}
}

0 comments on commit efe2891

Please sign in to comment.