#232 simplified things a bit

This commit is contained in:
Dominik Liebler 2016-09-22 08:47:57 +02:00
parent 1ff4203beb
commit 57c2e4f025

View File

@ -7,7 +7,7 @@ class BookList implements \Countable, \Iterator
/**
* @var Book[]
*/
private $books;
private $books = [];
/**
* @var int
@ -22,11 +22,12 @@ class BookList implements \Countable, \Iterator
public function removeBook(Book $bookToRemove)
{
foreach ($this->books as $key => $book) {
/** @var Book $book */
if ($book->getAuthorAndTitle() === $bookToRemove->getAuthorAndTitle()) {
unset($this->books[$key]);
}
}
$this->books = array_values($this->books);
}
public function count(): int
@ -36,12 +37,12 @@ class BookList implements \Countable, \Iterator
public function current(): Book
{
return $this->books[array_keys($this->books)[$this->currentIndex]];
return $this->books[$this->currentIndex];
}
public function key(): int
{
return array_keys($this->books)[$this->currentIndex];
return $this->currentIndex;
}
public function next()
@ -56,6 +57,6 @@ class BookList implements \Countable, \Iterator
public function valid(): bool
{
return isset(array_keys($this->books)[$this->currentIndex]);
return isset($this->books[$this->currentIndex]);
}
}