Skip to content

Commit 3a62a46

Browse files
committed
Fix #317 - added missing check/init
1 parent 3bd4017 commit 3a62a46

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/shared/FileInfoCollection.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class FileInfoCollection implements \Iterator, \Countable {
1616
/**
1717
* @var int
1818
*/
19-
private $pos;
19+
private $pos = 0;
2020

2121
/**
2222
* @param FileInfo $file
@@ -27,8 +27,12 @@ public function add(FileInfo $file) {
2727

2828
/**
2929
* @return FileInfo
30+
* @throws \TheSeer\phpDox\FileInfoCollectionException
3031
*/
3132
public function current() {
33+
if (!isset($this->data[$this->pos])) {
34+
throw new FileInfoCollectionException('Empty collection');
35+
}
3236
return $this->data[$this->pos];
3337
}
3438

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace TheSeer\phpDox;
4+
5+
class FileInfoCollectionException extends \Exception {
6+
7+
}

0 commit comments

Comments
 (0)