diff --git a/.gitignore b/.gitignore index fc595dc..746f9e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .DS_Store +.idea /composer.lock /vendor /build \ No newline at end of file diff --git a/src/Nacha/Batch.php b/src/Nacha/Batch.php index 4d87032..c94921a 100644 --- a/src/Nacha/Batch.php +++ b/src/Nacha/Batch.php @@ -6,7 +6,12 @@ use Nacha\Record\BatchFooter; use Nacha\Record\DebitEntry; use Nacha\Record\CcdEntry; +use Nacha\Record\Entry; +/** + * Class Batch + * @package Nacha + */ class Batch { // Service Class Codes @@ -15,9 +20,13 @@ class Batch { const DEBITS_ONLY = 225; private $header; - private $debitEntries = []; + + /** @var DebitEntry[] */ private $creditEntries = []; + /** @var CcdEntry[] */ + private $debitEntries = []; + public function __construct() { $this->header = new BatchHeader(); } @@ -53,13 +62,15 @@ public function addCreditEntry(CcdEntry $entry) { public function getEntryHash() { $hash = 0; + /** @var Entry[] $entries */ $entries = array_merge($this->debitEntries, $this->creditEntries); foreach ($entries as $entry) { $hash += $entry->getHashable(); } - return substr((string)$hash, -10); // only take 10 digits from end of string to 10 + $hashStr = substr((string)$hash, -10); // only take 10 digits from end of string to 10 + return intval($hashStr); } public function __toString() { diff --git a/src/Nacha/Field/Number.php b/src/Nacha/Field/Number.php index 1dd98bf..3c122e5 100644 --- a/src/Nacha/Field/Number.php +++ b/src/Nacha/Field/Number.php @@ -11,17 +11,17 @@ public function __construct($value, $length) { $this->value = (int)$value; $this->length = $length; - if (strlen($value) > $length) { - throw new InvalidFieldException('Length of "' . $value . '" must be '.$length.'.'); - } - if (!is_int($this->value)) { throw new InvalidFieldException('Value "' . $value . '" must be an integer.'); } + + if (strlen($value) > $length) { + throw new InvalidFieldException('Length of "' . $value . '" must be '.$length.'.'); + } } public function __toString() { - return sprintf('%0' . $this->length . 'd', $this->value); + return sprintf("%0{$this->length}d", $this->value); } } \ No newline at end of file diff --git a/src/Nacha/Field/String.php b/src/Nacha/Field/String.php index 96839bc..837ef2d 100644 --- a/src/Nacha/Field/String.php +++ b/src/Nacha/Field/String.php @@ -22,5 +22,4 @@ public function __construct($value, $length) { public function __toString() { return sprintf('%-' . $this->length . 's', $this->value); } - } \ No newline at end of file diff --git a/src/Nacha/File.php b/src/Nacha/File.php index 87c8919..a706a8a 100644 --- a/src/Nacha/File.php +++ b/src/Nacha/File.php @@ -9,6 +9,7 @@ class File { private $header; + /** @var Batch[] */ private $batches = []; public function __construct() { diff --git a/src/Nacha/Record/Entry.php b/src/Nacha/Record/Entry.php index ceaecbc..ab6c4ea 100644 --- a/src/Nacha/Record/Entry.php +++ b/src/Nacha/Record/Entry.php @@ -2,7 +2,6 @@ namespace Nacha\Record; -use Nacha\Field\String; use Nacha\Field\Number; use Nacha\Field\TransactionCode; use Nacha\Field\Amount; diff --git a/src/Nacha/Record/FileHeader.php b/src/Nacha/Record/FileHeader.php index 5bc0d8c..a71ab02 100644 --- a/src/Nacha/Record/FileHeader.php +++ b/src/Nacha/Record/FileHeader.php @@ -29,7 +29,7 @@ public function __construct() { $this->setBlockingFactor(10); $this->setFormatCode(1); $this->setFileIdModifier('A'); - $this->setFileCreationDate(date('ymd', time())); + $this->setFileCreationDate(date('ymd')); // optional $this->setImmediateDestinationName(''); diff --git a/test/Nacha/BatchTest.php b/test/Nacha/BatchTest.php index ab994f2..09f600b 100644 --- a/test/Nacha/BatchTest.php +++ b/test/Nacha/BatchTest.php @@ -5,8 +5,15 @@ use Nacha\Record\DebitEntry; use Nacha\Record\CcdEntry; +/** + * Class BatchTest + * @package Nacha + */ class BatchTest extends \PHPUnit_Framework_TestCase { + /** @var Batch */ + private $batch; + public function setup() { $this->batch = new Batch(); $this->batch->getHeader()->setBatchNumber(1) diff --git a/test/Nacha/Field/AmountTest.php b/test/Nacha/Field/AmountTest.php index 216d298..18c225f 100644 --- a/test/Nacha/Field/AmountTest.php +++ b/test/Nacha/Field/AmountTest.php @@ -5,14 +5,14 @@ class AmountTest extends \PHPUnit_Framework_TestCase { /** - * @expectedException Nacha\Field\InvalidFieldException + * @expectedException \Nacha\Field\InvalidFieldException */ public function testInvalidLength_Float() { new Amount(100000000.00); // only accepts $99M } /** - * @expectedException Nacha\Field\InvalidFieldException + * @expectedException \Nacha\Field\InvalidFieldException */ public function testInvalidLength_String() { new Amount('100000000.00'); // only accepts $99M diff --git a/test/Nacha/Field/NumberTest.php b/test/Nacha/Field/NumberTest.php index 0a3daf2..7267144 100644 --- a/test/Nacha/Field/NumberTest.php +++ b/test/Nacha/Field/NumberTest.php @@ -12,11 +12,26 @@ public function testPadding() { $this->assertEquals('0000000101', (string)$nbr); } + public function testMaxPadding() { + // given + $nbr = new Number(1234567891, 10); + + // then + $this->assertEquals('1234567891', (string)$nbr); + } + /** - * @expectedException Nacha\Field\InvalidFieldException + * @expectedException \Nacha\Field\InvalidFieldException */ public function testTruncation() { new Number(111101, 5); } + /** + * @expectedException \Nacha\Field\InvalidFieldException + */ + public function testNotNumber() { + new Number("testme", 5); + } + } \ No newline at end of file diff --git a/test/Nacha/Field/RoutingNumberTest.php b/test/Nacha/Field/RoutingNumberTest.php index 2626bdf..952ee7c 100644 --- a/test/Nacha/Field/RoutingNumberTest.php +++ b/test/Nacha/Field/RoutingNumberTest.php @@ -12,4 +12,11 @@ public function testLength() { $this->assertEquals('001243123', (string)$nbr); } + /** + * @expectedException \Nacha\Field\InvalidFieldException + */ + public function testInvalidLength() { + new RoutingNumber(111101); + } + } \ No newline at end of file diff --git a/test/Nacha/Field/StringTest.php b/test/Nacha/Field/StringTest.php index e5881c0..7ffaf51 100644 --- a/test/Nacha/Field/StringTest.php +++ b/test/Nacha/Field/StringTest.php @@ -12,4 +12,17 @@ public function testPadding() { $this->assertEquals('Hello World ', (string)$str); } + /** + * @expectedException \Nacha\Field\InvalidFieldException + */ + public function testNotString() { + new String(12, 32); + } + + /** + * @expectedException \Nacha\Field\InvalidFieldException + */ + public function testInvalidCharacter() { + new String("!testtext", 32); + } } \ No newline at end of file