Skip to content

Commit

Permalink
Removes fluent interface from writer methods
Browse files Browse the repository at this point in the history
Removes fluent interface from filters

Removes fluent interface from readers

Preserves fluent interface in Steps for now

Preserves fluent interface in Workflow for now

Based on the reference from PHPDoc, $this can be used to indicate fluent interfaces
  • Loading branch information
sagikazarmark committed May 28, 2015
1 parent 38db381 commit 7b79829
Show file tree
Hide file tree
Showing 28 changed files with 75 additions and 213 deletions.
29 changes: 16 additions & 13 deletions src/Filter/DateTimeThresholdFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,39 @@
use Ddeboer\DataImport\ValueConverter\DateTimeValueConverter;

/**
* This filter can be used to filter out some items from a specific date. Useful
* to do incremental imports
* This filter can be used to filter out some items from a specific date.
*
* Useful to do incremental imports
*
* @author Grégoire Paris
*/
class DateTimeThresholdFilter
{
/**
* @var \DateTime threshold dates strictly before this date will be filtered out.
* defaults to null
* Threshold dates strictly before this date will be filtered out
*
* @var \DateTime|null
*/
protected $threshold;

/**
* @var DateTimeValueConverter used to convert the values in the time column
* Used to convert the values in the time column
*
* @var DateTimeValueConverter
*/
protected $valueConverter;

/**
* @var string the name of the column that should contain the value the
* filter will compare the threshold with. Defaults to "updated_at"
* The name of the column that should contain the value the filter will compare the threshold with
*
* @var string
*/
protected $timeColumnName;
protected $timeColumnName = 'updated_at';

/**
* @var integer priority the filter priority. Defaults to 512.
* @var integer
*/
protected $priority;
protected $priority = 512;

/**
* @param DateTimeValueConverter $valueConverter
Expand Down Expand Up @@ -70,12 +75,10 @@ public function __invoke(array $item)
* Useful if you build a filter service, and want to set the threshold
* dynamically afterwards.
*
* @return $this
* @param \DateTime $value
*/
public function setThreshold(\DateTime $value)
{
$this->threshold = $value;

return $this;
}
}
11 changes: 1 addition & 10 deletions src/Reader/CsvReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,11 @@ public function getColumnHeaders()
* Set column headers
*
* @param array $columnHeaders
*
* @return CsvReader
*/
public function setColumnHeaders(array $columnHeaders)
{
$this->columnHeaders = array_count_values($columnHeaders);
$this->headersCount = count($columnHeaders);

return $this;
}

/**
Expand All @@ -179,7 +175,6 @@ public function setColumnHeaders(array $columnHeaders)
* values for duplicate headers into an array
* (dup => [value1, value2, value3])
*
* @return CsvReader
* @throws DuplicateHeadersException If duplicate headers are encountered
* and no duplicate handling has been
* specified
Expand All @@ -190,7 +185,7 @@ public function setHeaderRowNumber($rowNumber, $duplicates = null)
$this->headerRowNumber = $rowNumber;
$headers = $this->readHeaderRow($rowNumber);

return $this->setColumnHeaders($headers);
$this->setColumnHeaders($headers);
}

/**
Expand Down Expand Up @@ -317,14 +312,10 @@ public function isStrict()
* Set strict parsing
*
* @param boolean $strict
*
* @return CsvReader
*/
public function setStrict($strict)
{
$this->strict = $strict;

return $this;
}

/**
Expand Down
12 changes: 0 additions & 12 deletions src/Reader/DbalReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,10 @@ public function __construct(Connection $connection, $sql, array $params = [])
* Do calculate row count?
*
* @param boolean $calculate
*
* @return $this
*/
public function setRowCountCalculated($calculate = true)
{
$this->rowCountCalculated = (bool) $calculate;

return $this;
}

/**
Expand Down Expand Up @@ -105,33 +101,25 @@ public function getFields()
*
* @param string $sql
* @param array $params
*
* @return $this
*/
public function setSql($sql, array $params = [])
{
$this->sql = (string) $sql;

$this->setSqlParameters($params);

return $this;
}

/**
* Set SQL parameters
*
* @param array $params
*
* @return $this
*/
public function setSqlParameters(array $params)
{
$this->params = $params;

$this->stmt = null;
$this->rowCount = null;

return $this;
}

/**
Expand Down
8 changes: 0 additions & 8 deletions src/Reader/ExcelReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,10 @@ public function getColumnHeaders()
* Set column headers
*
* @param array $columnHeaders
*
* @return $this
*/
public function setColumnHeaders(array $columnHeaders)
{
$this->columnHeaders = $columnHeaders;

return $this;
}

/**
Expand All @@ -134,15 +130,11 @@ public function rewind()
* Set header row number
*
* @param integer $rowNumber Number of the row that contains column header names
*
* @return $this
*/
public function setHeaderRowNumber($rowNumber)
{
$this->headerRowNumber = $rowNumber;
$this->columnHeaders = $this->worksheet[$rowNumber];

return $this;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Step/ConverterStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public function __construct(array $converters = [])

/**
* @param callable $converter
*
* @return $this
*/
public function add(callable $converter)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Step/FilterStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public function __construct()
/**
* @param callable $filter
* @param integer $priority
*
* @return $this
*/
public function add(callable $filter, $priority = null)
{
Expand Down
4 changes: 0 additions & 4 deletions src/Step/ValidatorStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,10 @@ public function add($field, Constraint $constraint)

/**
* @param boolean $flag
*
* @return $this
*/
public function throwExceptions($flag = true)
{
$this->throwExceptions = $flag;

return $this;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Step/ValueConverterStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class ValueConverterStep implements Step
/**
* @param string $property
* @param callable $converter
*
* @return $this
*/
public function add($property, callable $converter)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Workflow/StepAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __construct(Reader $reader, LoggerInterface $logger = null, $nam
* @param Step $step
* @param integer|null $priority
*
* @return Workflow
* @return $this
*/
public function addStep(Step $step, $priority = null)
{
Expand All @@ -93,7 +93,7 @@ public function addStep(Step $step, $priority = null)
*
* @param Writer $writer
*
* @return Workflow
* @return $this
*/
public function addWriter(Writer $writer)
{
Expand Down
6 changes: 0 additions & 6 deletions src/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,18 @@ interface Writer
{
/**
* Prepare the writer before writing the items
*
* @return $this
*/
public function prepare();

/**
* Write one data item
*
* @param array $item The data item with converted values
*
* @return $this
*/
public function writeItem(array $item);

/**
* Wrap up the writer after all items have been written
*
* @return $this
*/
public function finish();
}
2 changes: 0 additions & 2 deletions src/Writer/AbstractStreamWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ public function finish()
if (is_resource($this->stream) && $this->getCloseStreamOnFinish()) {
fclose($this->stream);
}

return $this;
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/Writer/ArrayWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public function __construct(array &$data)
public function prepare()
{
$this->data = [];

return $this;
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/Writer/CallbackWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,5 @@ public function __construct(callable $callback)
public function writeItem(array $item)
{
call_user_func($this->callback, $item);

return $this;
}
}
6 changes: 0 additions & 6 deletions src/Writer/ConsoleProgressWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ public function prepare()
$this->progress->setFormat($this->verbosity);
$this->progress->setRedrawFrequency($this->redrawFrequency);
$this->progress->start();

return $this;
}

/**
Expand All @@ -76,8 +74,6 @@ public function prepare()
public function writeItem(array $item)
{
$this->progress->advance();

return $this;
}

/**
Expand All @@ -86,8 +82,6 @@ public function writeItem(array $item)
public function finish()
{
$this->progress->finish();

return $this;
}

/**
Expand Down
4 changes: 0 additions & 4 deletions src/Writer/CsvWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public function prepare()
if ($this->utf8Encoding) {
fprintf($this->getStream(), chr(0xEF) . chr(0xBB) . chr(0xBF));
}

return $this;
}

/**
Expand All @@ -57,7 +55,5 @@ public function prepare()
public function writeItem(array $item)
{
fputcsv($this->getStream(), $item, $this->delimiter, $this->enclosure);

return $this;
}
}
6 changes: 0 additions & 6 deletions src/Writer/DoctrineWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ public function prepare()
if (true === $this->truncate) {
$this->truncateTable();
}

return $this;
}

/**
Expand Down Expand Up @@ -204,8 +202,6 @@ public function finish()
$this->entityManager->flush();
$this->entityManager->clear($this->entityName);
$this->reEnableLogging();

return $this;
}

/**
Expand All @@ -224,8 +220,6 @@ public function writeItem(array $item)
if (($this->counter % $this->batchSize) == 0) {
$this->flushAndClear();
}

return $this;
}

/**
Expand Down
6 changes: 0 additions & 6 deletions src/Writer/ExcelWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public function prepare()
}
$this->excel->setActiveSheetIndexByName($this->sheet);
}

return $this;
}

/**
Expand All @@ -85,8 +83,6 @@ public function writeItem(array $item)
}

$this->row++;

return $this;
}

/**
Expand All @@ -96,7 +92,5 @@ public function finish()
{
$writer = \PHPExcel_IOFactory::createWriter($this->excel, $this->type);
$writer->save($this->filename);

return $this;
}
}
Loading

0 comments on commit 7b79829

Please sign in to comment.