Skip to content

Commit

Permalink
Added CountableRecordsTrait for existing Countable*Records.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilge committed Aug 9, 2016
1 parent b90b2d5 commit 6585ae4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
9 changes: 2 additions & 7 deletions src/Porter/Collection/CountableMappedRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class CountableMappedRecords extends MappedRecords implements \Countable
{
private $count;
use CountableRecordsTrait;

/**
* @param \Iterator $records
Expand All @@ -14,11 +14,6 @@ public function __construct(\Iterator $records, $count, RecordCollection $previo
{
parent::__construct($records, $previousCollection);

$this->count = $count|0;
}

public function count()
{
return $this->count;
$this->setCount($count);
}
}
9 changes: 2 additions & 7 deletions src/Porter/Collection/CountablePorterRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class CountablePorterRecords extends PorterRecords implements \Countable
{
private $count;
use CountableRecordsTrait;

/**
* @param RecordCollection $records
Expand All @@ -16,11 +16,6 @@ public function __construct(RecordCollection $records, $count, ImportSpecificati
{
parent::__construct($records, $specification);

$this->count = $count|0;
}

public function count()
{
return $this->count;
$this->setCount($count);
}
}
9 changes: 2 additions & 7 deletions src/Porter/Collection/CountableProviderRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class CountableProviderRecords extends ProviderRecords implements \Countable
{
private $count;
use CountableRecordsTrait;

/**
* @param \Iterator $providerRecords
Expand All @@ -16,11 +16,6 @@ public function __construct(\Iterator $providerRecords, $count, ProviderDataSour
{
parent::__construct($providerRecords, $dataSource);

$this->count = $count|0;
}

public function count()
{
return $this->count;
$this->setCount($count);
}
}
18 changes: 18 additions & 0 deletions src/Porter/Collection/CountableRecordsTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
namespace ScriptFUSION\Porter\Collection;

trait CountableRecordsTrait
{
/** @var int */
private $count;

public function count()
{
return $this->count;
}

private function setCount($count)
{
$this->count = $count|0;
}
}
2 changes: 1 addition & 1 deletion test/Integration/Porter/PorterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function testImportAndFilterCountableRecords()
);

// Innermost collection.
self::assertInstanceOf(\Countable::class, $first = $records->findFirstCollection());
self::assertInstanceOf(\Countable::class, $records->findFirstCollection());

// Outermost collection.
self::assertNotInstanceOf(\Countable::class, $records);
Expand Down

0 comments on commit 6585ae4

Please sign in to comment.