6
6
use SlayerBirden \DataFlow \Data \SimpleBag ;
7
7
use SlayerBirden \DataFlow \IdentificationTrait ;
8
8
use SlayerBirden \DataFlow \Provider \Exception \FileDoesNotExist ;
9
- use SlayerBirden \DataFlow \Provider \Exception \HeaderInvalid ;
9
+ use SlayerBirden \DataFlow \Provider \Exception \RowInvalid ;
10
10
use SlayerBirden \DataFlow \Provider \Exception \HeaderMissing ;
11
11
use SlayerBirden \DataFlow \ProviderInterface ;
12
12
@@ -59,7 +59,7 @@ public function __construct(string $id, string $fileName, bool $headerRow = true
59
59
60
60
/**
61
61
* @inheritdoc
62
- * @throws HeaderInvalid
62
+ * @throws RowInvalid
63
63
*/
64
64
public function getCask (): \Generator
65
65
{
@@ -75,11 +75,11 @@ public function getCask(): \Generator
75
75
while ($ this ->file ->valid ()) {
76
76
$ row = $ this ->file ->current ();
77
77
if (count ($ row ) !== count ($ this ->header )) {
78
- throw new HeaderInvalid (
78
+ throw new RowInvalid (
79
79
sprintf (
80
- 'Invalid header %s for row %s. Column count mismatch. ' ,
81
- json_encode ($ this -> header ),
82
- json_encode ($ row )
80
+ 'Invalid row %s for header %s. Column count mismatch. ' ,
81
+ json_encode ($ row ),
82
+ json_encode ($ this -> header )
83
83
)
84
84
);
85
85
}
@@ -99,7 +99,11 @@ public function getEstimatedSize(): int
99
99
// attempt to reach max (will reach last line);
100
100
$ prevPos = $ this ->file ->key ();
101
101
$ this ->file ->seek (PHP_INT_MAX );
102
- $ numberOfLines = $ this ->file ->key () + 1 ;
102
+ $ numberOfLines = $ this ->file ->key ();
103
+ if ($ this ->file ->valid ()) {
104
+ // this line is not eof
105
+ $ numberOfLines += 1 ;
106
+ }
103
107
if ($ this ->headerRow ) {
104
108
// subtract header row if it's present in the file
105
109
--$ numberOfLines ;
0 commit comments