From d5b8a5642536bfbdda7c37eb2842e09228ab3f82 Mon Sep 17 00:00:00 2001 From: Dominik Liebler Date: Wed, 21 Sep 2016 14:34:24 +0200 Subject: [PATCH 1/4] #232 removed Iterator classes --- Behavioral/Iterator/Book.php | 14 +- Behavioral/Iterator/BookList.php | 44 +- Behavioral/Iterator/BookListIterator.php | 86 --- .../Iterator/BookListReverseIterator.php | 87 --- Behavioral/Iterator/README.rst | 17 +- Behavioral/Iterator/Tests/IteratorTest.php | 94 +-- composer.json | 5 +- composer.lock | 577 ++++++++++++++---- 8 files changed, 562 insertions(+), 362 deletions(-) delete mode 100644 Behavioral/Iterator/BookListIterator.php delete mode 100644 Behavioral/Iterator/BookListReverseIterator.php diff --git a/Behavioral/Iterator/Book.php b/Behavioral/Iterator/Book.php index b1adf7f..bb9abeb 100644 --- a/Behavioral/Iterator/Book.php +++ b/Behavioral/Iterator/Book.php @@ -4,27 +4,33 @@ namespace DesignPatterns\Behavioral\Iterator; class Book { + /** + * @var string + */ private $author; + /** + * @var string + */ private $title; - public function __construct($title, $author) + public function __construct(string $title, string $author) { $this->author = $author; $this->title = $title; } - public function getAuthor() + public function getAuthor(): string { return $this->author; } - public function getTitle() + public function getTitle(): string { return $this->title; } - public function getAuthorAndTitle() + public function getAuthorAndTitle(): string { return $this->getTitle().' by '.$this->getAuthor(); } diff --git a/Behavioral/Iterator/BookList.php b/Behavioral/Iterator/BookList.php index 6cc5e5e..e69825f 100644 --- a/Behavioral/Iterator/BookList.php +++ b/Behavioral/Iterator/BookList.php @@ -2,18 +2,17 @@ namespace DesignPatterns\Behavioral\Iterator; -class BookList implements \Countable +class BookList implements \Countable, \Iterator { + /** + * @var Book[] + */ private $books; - public function getBook($bookNumberToGet) - { - if (isset($this->books[$bookNumberToGet])) { - return $this->books[$bookNumberToGet]; - } - - return; - } + /** + * @var int + */ + private $currentIndex = 0; public function addBook(Book $book) { @@ -30,8 +29,33 @@ class BookList implements \Countable } } - public function count() + public function count(): int { return count($this->books); } + + public function current(): Book + { + return $this->books[array_keys($this->books)[$this->currentIndex]]; + } + + public function key(): int + { + return array_keys($this->books)[$this->currentIndex]; + } + + public function next() + { + $this->currentIndex++; + } + + public function rewind() + { + $this->currentIndex = 0; + } + + public function valid(): bool + { + return isset(array_keys($this->books)[$this->currentIndex]); + } } diff --git a/Behavioral/Iterator/BookListIterator.php b/Behavioral/Iterator/BookListIterator.php deleted file mode 100644 index ecedba6..0000000 --- a/Behavioral/Iterator/BookListIterator.php +++ /dev/null @@ -1,86 +0,0 @@ -bookList = $bookList; - } - - /** - * Return the current book. - * - * @link http://php.net/manual/en/iterator.current.php - * - * @return Book Can return any type. - */ - public function current() - { - return $this->bookList->getBook($this->currentBook); - } - - /** - * (PHP 5 >= 5.0.0)
- * Move forward to next element. - * - * @link http://php.net/manual/en/iterator.next.php - * - * @return void Any returned value is ignored. - */ - public function next() - { - $this->currentBook++; - } - - /** - * (PHP 5 >= 5.0.0)
- * Return the key of the current element. - * - * @link http://php.net/manual/en/iterator.key.php - * - * @return mixed scalar on success, or null on failure. - */ - public function key() - { - return $this->currentBook; - } - - /** - * (PHP 5 >= 5.0.0)
- * Checks if current position is valid. - * - * @link http://php.net/manual/en/iterator.valid.php - * - * @return bool The return value will be casted to boolean and then evaluated. - * Returns true on success or false on failure. - */ - public function valid() - { - return null !== $this->bookList->getBook($this->currentBook); - } - - /** - * (PHP 5 >= 5.0.0)
- * Rewind the Iterator to the first element. - * - * @link http://php.net/manual/en/iterator.rewind.php - * - * @return void Any returned value is ignored. - */ - public function rewind() - { - $this->currentBook = 0; - } -} diff --git a/Behavioral/Iterator/BookListReverseIterator.php b/Behavioral/Iterator/BookListReverseIterator.php deleted file mode 100644 index 94f34d9..0000000 --- a/Behavioral/Iterator/BookListReverseIterator.php +++ /dev/null @@ -1,87 +0,0 @@ -bookList = $bookList; - $this->currentBook = $this->bookList->count() - 1; - } - - /** - * Return the current book. - * - * @link http://php.net/manual/en/iterator.current.php - * - * @return Book Can return any type. - */ - public function current() - { - return $this->bookList->getBook($this->currentBook); - } - - /** - * (PHP 5 >= 5.0.0)
- * Move forward to next element. - * - * @link http://php.net/manual/en/iterator.next.php - * - * @return void Any returned value is ignored. - */ - public function next() - { - $this->currentBook--; - } - - /** - * (PHP 5 >= 5.0.0)
- * Return the key of the current element. - * - * @link http://php.net/manual/en/iterator.key.php - * - * @return mixed scalar on success, or null on failure. - */ - public function key() - { - return $this->currentBook; - } - - /** - * (PHP 5 >= 5.0.0)
- * Checks if current position is valid. - * - * @link http://php.net/manual/en/iterator.valid.php - * - * @return bool The return value will be casted to boolean and then evaluated. - * Returns true on success or false on failure. - */ - public function valid() - { - return null !== $this->bookList->getBook($this->currentBook); - } - - /** - * (PHP 5 >= 5.0.0)
- * Rewind the Iterator to the first element. - * - * @link http://php.net/manual/en/iterator.rewind.php - * - * @return void Any returned value is ignored. - */ - public function rewind() - { - $this->currentBook = $this->bookList->count() - 1; - } -} diff --git a/Behavioral/Iterator/README.rst b/Behavioral/Iterator/README.rst index 9398350..cb7134b 100644 --- a/Behavioral/Iterator/README.rst +++ b/Behavioral/Iterator/README.rst @@ -4,8 +4,7 @@ Purpose ------- -To make an object iterable and to make it appear like a collection of -objects. +To make an object iterable and to make it appear like a collection of objects. Examples -------- @@ -45,18 +44,6 @@ BookList.php :language: php :linenos: -BookListIterator.php - -.. literalinclude:: BookListIterator.php - :language: php - :linenos: - -BookListReverseIterator.php - -.. literalinclude:: BookListReverseIterator.php - :language: php - :linenos: - Test ---- @@ -67,4 +54,4 @@ Tests/IteratorTest.php :linenos: .. _`GitHub`: https://github.com/domnikl/DesignPatternsPHP/tree/master/Behavioral/Iterator -.. __: http://en.wikipedia.org/wiki/Iterator_pattern \ No newline at end of file +.. __: http://en.wikipedia.org/wiki/Iterator_pattern diff --git a/Behavioral/Iterator/Tests/IteratorTest.php b/Behavioral/Iterator/Tests/IteratorTest.php index db386f0..78ba617 100644 --- a/Behavioral/Iterator/Tests/IteratorTest.php +++ b/Behavioral/Iterator/Tests/IteratorTest.php @@ -9,66 +9,68 @@ use DesignPatterns\Behavioral\Iterator\BookListReverseIterator; class IteratorTest extends \PHPUnit_Framework_TestCase { - /** - * @var BookList - */ - protected $bookList; - - protected function setUp() + public function testCanIterateOverBookList() { - $this->bookList = new BookList(); - $this->bookList->addBook(new Book('Learning PHP Design Patterns', 'William Sanders')); - $this->bookList->addBook(new Book('Professional Php Design Patterns', 'Aaron Saray')); - $this->bookList->addBook(new Book('Clean Code', 'Robert C. Martin')); - } + $bookList = new BookList(); + $bookList->addBook(new Book('Learning PHP Design Patterns', 'William Sanders')); + $bookList->addBook(new Book('Professional Php Design Patterns', 'Aaron Saray')); + $bookList->addBook(new Book('Clean Code', 'Robert C. Martin')); - public function expectedAuthors() - { - return array( - array( - array( - 'Learning PHP Design Patterns by William Sanders', - 'Professional Php Design Patterns by Aaron Saray', - 'Clean Code by Robert C. Martin', - ), - ), + $books = []; + + foreach ($bookList as $book) { + $books[] = $book->getAuthorAndTitle(); + } + + $this->assertEquals( + [ + 'Learning PHP Design Patterns by William Sanders', + 'Professional Php Design Patterns by Aaron Saray', + 'Clean Code by Robert C. Martin', + ], + $books ); } - /** - * @dataProvider expectedAuthors - */ - public function testUseAIteratorAndValidateAuthors($expected) + public function testCanIterateOverBookListAfterRemovingBook() { - $iterator = new BookListIterator($this->bookList); + $book = new Book('Clean Code', 'Robert C. Martin'); + $book2 = new Book('Professional Php Design Patterns', 'Aaron Saray'); - while ($iterator->valid()) { - $expectedBook = array_shift($expected); - $this->assertEquals($expectedBook, $iterator->current()->getAuthorAndTitle()); - $iterator->next(); + $bookList = new BookList(); + $bookList->addBook($book); + $bookList->addBook($book2); + $bookList->removeBook($book); + + $books = []; + foreach ($bookList as $book) { + $books[] = $book->getAuthorAndTitle(); } + + $this->assertEquals( + ['Professional Php Design Patterns by Aaron Saray'], + $books + ); } - /** - * @dataProvider expectedAuthors - */ - public function testUseAReverseIteratorAndValidateAuthors($expected) + public function testCanAddBookToList() { - $iterator = new BookListReverseIterator($this->bookList); + $book = new Book('Clean Code', 'Robert C. Martin'); - while ($iterator->valid()) { - $expectedBook = array_pop($expected); - $this->assertEquals($expectedBook, $iterator->current()->getAuthorAndTitle()); - $iterator->next(); - } + $bookList = new BookList(); + $bookList->addBook($book); + + $this->assertCount(1, $bookList); } - /** - * Test BookList Remove. - */ - public function testBookRemove() + public function testCanRemoveBookFromList() { - $this->bookList->removeBook($this->bookList->getBook(0)); - $this->assertEquals($this->bookList->count(), 2); + $book = new Book('Clean Code', 'Robert C. Martin'); + + $bookList = new BookList(); + $bookList->addBook($book); + $bookList->removeBook($book); + + $this->assertCount(0, $bookList); } } diff --git a/composer.json b/composer.json index 71610e4..3bac6dc 100644 --- a/composer.json +++ b/composer.json @@ -8,8 +8,11 @@ } ], "minimum-stability": "stable", + "require": { + "php": ">=7.0" + }, "require-dev": { - "phpunit/phpunit": "^4.6", + "phpunit/phpunit": ">=5.5.4", "squizlabs/php_codesniffer": "1.5.*" }, "autoload": { diff --git a/composer.lock b/composer.lock index 202b73e..2f6aac1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "ccc9bc820717ca4dc310248ad4a69f21", - "content-hash": "f9ca7d34db86fa55e8dc649f84d8b4c7", + "hash": "fc06bf31eb6cf4b21a7923e186abfb9d", + "content-hash": "c829a84cbe749d776139a3e9ebdd3094", "packages": [], "packages-dev": [ { @@ -63,38 +63,129 @@ "time": "2015-06-14 21:17:01" }, { - "name": "phpdocumentor/reflection-docblock", - "version": "2.0.4", + "name": "myclabs/deep-copy", + "version": "1.5.4", "source": { "type": "git", - "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8" + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "ea74994a3dc7f8d2f65a06009348f2d63c81e61f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8", - "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/ea74994a3dc7f8d2f65a06009348f2d63c81e61f", + "reference": "ea74994a3dc7f8d2f65a06009348f2d63c81e61f", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=5.4.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "doctrine/collections": "1.*", + "phpunit/phpunit": "~4.1" }, - "suggest": { - "dflydev/markdown": "~1.0", - "erusev/parsedown": "~1.0" + "type": "library", + "autoload": { + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "homepage": "https://github.com/myclabs/DeepCopy", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "time": "2016-09-16 13:37:59" + }, + { + "name": "phpdocumentor/reflection-common", + "version": "1.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "1.0.x-dev" } }, "autoload": { - "psr-0": { - "phpDocumentor": [ + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2015-12-27 11:43:31" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "9270140b940ff02e58ec577c237274e92cd40cdd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/9270140b940ff02e58ec577c237274e92cd40cdd", + "reference": "9270140b940ff02e58ec577c237274e92cd40cdd", + "shasum": "" + }, + "require": { + "php": ">=5.5", + "phpdocumentor/reflection-common": "^1.0@dev", + "phpdocumentor/type-resolver": "^0.2.0", + "webmozart/assert": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^4.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ "src/" ] } @@ -106,37 +197,87 @@ "authors": [ { "name": "Mike van Riel", - "email": "mike.vanriel@naenius.com" + "email": "me@mikevanriel.com" } ], - "time": "2015-02-03 12:10:50" + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "time": "2016-06-10 09:48:41" }, { - "name": "phpspec/prophecy", - "version": "v1.5.0", + "name": "phpdocumentor/type-resolver", + "version": "0.2", "source": { "type": "git", - "url": "https://github.com/phpspec/prophecy.git", - "reference": "4745ded9307786b730d7a60df5cb5a6c43cf95f7" + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "b39c7a5b194f9ed7bd0dd345c751007a41862443" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4745ded9307786b730d7a60df5cb5a6c43cf95f7", - "reference": "4745ded9307786b730d7a60df5cb5a6c43cf95f7", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/b39c7a5b194f9ed7bd0dd345c751007a41862443", + "reference": "b39c7a5b194f9ed7bd0dd345c751007a41862443", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.0.2", - "phpdocumentor/reflection-docblock": "~2.0", - "sebastian/comparator": "~1.1" + "php": ">=5.5", + "phpdocumentor/reflection-common": "^1.0" }, "require-dev": { - "phpspec/phpspec": "~2.0" + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^5.2||^4.8.24" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4.x-dev" + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "time": "2016-06-10 07:14:17" + }, + { + "name": "phpspec/prophecy", + "version": "v1.6.1", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "58a8137754bc24b25740d4281399a4a3596058e0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/58a8137754bc24b25740d4281399a4a3596058e0", + "reference": "58a8137754bc24b25740d4281399a4a3596058e0", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^5.3|^7.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2", + "sebastian/comparator": "^1.1", + "sebastian/recursion-context": "^1.0" + }, + "require-dev": { + "phpspec/phpspec": "^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.6.x-dev" } }, "autoload": { @@ -169,43 +310,44 @@ "spy", "stub" ], - "time": "2015-08-13 10:07:40" + "time": "2016-06-07 08:13:47" }, { "name": "phpunit/php-code-coverage", - "version": "2.2.4", + "version": "4.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979" + "reference": "5f3f7e736d6319d5f1fc402aff8b026da26709a3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/eabf68b476ac7d0f73793aada060f1c1a9bf8979", - "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/5f3f7e736d6319d5f1fc402aff8b026da26709a3", + "reference": "5f3f7e736d6319d5f1fc402aff8b026da26709a3", "shasum": "" }, "require": { - "php": ">=5.3.3", + "php": "^5.6 || ^7.0", "phpunit/php-file-iterator": "~1.3", "phpunit/php-text-template": "~1.2", - "phpunit/php-token-stream": "~1.3", - "sebastian/environment": "^1.3.2", - "sebastian/version": "~1.0" + "phpunit/php-token-stream": "^1.4.2", + "sebastian/code-unit-reverse-lookup": "~1.0", + "sebastian/environment": "^1.3.2 || ^2.0", + "sebastian/version": "~1.0|~2.0" }, "require-dev": { "ext-xdebug": ">=2.1.4", - "phpunit/phpunit": "~4" + "phpunit/phpunit": "^5.4" }, "suggest": { "ext-dom": "*", - "ext-xdebug": ">=2.2.1", + "ext-xdebug": ">=2.4.0", "ext-xmlwriter": "*" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.2.x-dev" + "dev-master": "4.0.x-dev" } }, "autoload": { @@ -231,7 +373,7 @@ "testing", "xunit" ], - "time": "2015-10-06 15:47:00" + "time": "2016-07-26 14:39:29" }, { "name": "phpunit/php-file-iterator", @@ -323,21 +465,24 @@ }, { "name": "phpunit/php-timer", - "version": "1.0.7", + "version": "1.0.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b" + "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3e82f4e9fc92665fafd9157568e4dcb01d014e5b", - "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/38e9124049cf1a164f1e4537caf19c99bf1eb260", + "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260", "shasum": "" }, "require": { "php": ">=5.3.3" }, + "require-dev": { + "phpunit/phpunit": "~4|~5" + }, "type": "library", "autoload": { "classmap": [ @@ -360,7 +505,7 @@ "keywords": [ "timer" ], - "time": "2015-06-21 08:01:12" + "time": "2016-05-12 18:03:57" }, { "name": "phpunit/php-token-stream", @@ -413,16 +558,16 @@ }, { "name": "phpunit/phpunit", - "version": "4.8.18", + "version": "5.5.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "fa33d4ad96481b91df343d83e8c8aabed6b1dfd3" + "reference": "3e6e88e56c912133de6e99b87728cca7ed70c5f5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fa33d4ad96481b91df343d83e8c8aabed6b1dfd3", - "reference": "fa33d4ad96481b91df343d83e8c8aabed6b1dfd3", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3e6e88e56c912133de6e99b87728cca7ed70c5f5", + "reference": "3e6e88e56c912133de6e99b87728cca7ed70c5f5", "shasum": "" }, "require": { @@ -431,21 +576,27 @@ "ext-pcre": "*", "ext-reflection": "*", "ext-spl": "*", - "php": ">=5.3.3", + "myclabs/deep-copy": "~1.3", + "php": "^5.6 || ^7.0", "phpspec/prophecy": "^1.3.1", - "phpunit/php-code-coverage": "~2.1", + "phpunit/php-code-coverage": "^4.0.1", "phpunit/php-file-iterator": "~1.4", "phpunit/php-text-template": "~1.2", - "phpunit/php-timer": ">=1.0.6", - "phpunit/phpunit-mock-objects": "~2.3", + "phpunit/php-timer": "^1.0.6", + "phpunit/phpunit-mock-objects": "^3.2", "sebastian/comparator": "~1.1", "sebastian/diff": "~1.2", - "sebastian/environment": "~1.3", + "sebastian/environment": "^1.3 || ^2.0", "sebastian/exporter": "~1.2", "sebastian/global-state": "~1.0", - "sebastian/version": "~1.0", + "sebastian/object-enumerator": "~1.0", + "sebastian/resource-operations": "~1.0", + "sebastian/version": "~1.0|~2.0", "symfony/yaml": "~2.1|~3.0" }, + "conflict": { + "phpdocumentor/reflection-docblock": "3.0.2" + }, "suggest": { "phpunit/php-invoker": "~1.1" }, @@ -455,7 +606,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.8.x-dev" + "dev-master": "5.5.x-dev" } }, "autoload": { @@ -481,30 +632,33 @@ "testing", "xunit" ], - "time": "2015-11-11 11:32:49" + "time": "2016-08-26 07:11:44" }, { "name": "phpunit/phpunit-mock-objects", - "version": "2.3.8", + "version": "3.2.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983" + "reference": "546898a2c0c356ef2891b39dd7d07f5d82c8ed0a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/ac8e7a3db35738d56ee9a76e78a4e03d97628983", - "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/546898a2c0c356ef2891b39dd7d07f5d82c8ed0a", + "reference": "546898a2c0c356ef2891b39dd7d07f5d82c8ed0a", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", - "php": ">=5.3.3", - "phpunit/php-text-template": "~1.2", - "sebastian/exporter": "~1.2" + "php": "^5.6 || ^7.0", + "phpunit/php-text-template": "^1.2", + "sebastian/exporter": "^1.2" + }, + "conflict": { + "phpunit/phpunit": "<5.4.0" }, "require-dev": { - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^5.4" }, "suggest": { "ext-soap": "*" @@ -512,7 +666,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.3.x-dev" + "dev-master": "3.2.x-dev" } }, "autoload": { @@ -537,7 +691,52 @@ "mock", "xunit" ], - "time": "2015-10-02 06:51:40" + "time": "2016-09-06 16:07:45" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "c36f5e7cfce482fde5bf8d10d41a53591e0198fe" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/c36f5e7cfce482fde5bf8d10d41a53591e0198fe", + "reference": "c36f5e7cfce482fde5bf8d10d41a53591e0198fe", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "phpunit/phpunit": "~5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "time": "2016-02-13 06:45:14" }, { "name": "sebastian/comparator", @@ -605,28 +804,28 @@ }, { "name": "sebastian/diff", - "version": "1.3.0", + "version": "1.4.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3" + "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3", - "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/13edfd8706462032c2f52b4b862974dd46b71c9e", + "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e", "shasum": "" }, "require": { "php": ">=5.3.3" }, "require-dev": { - "phpunit/phpunit": "~4.2" + "phpunit/phpunit": "~4.8" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.3-dev" + "dev-master": "1.4-dev" } }, "autoload": { @@ -649,31 +848,31 @@ } ], "description": "Diff implementation", - "homepage": "http://www.github.com/sebastianbergmann/diff", + "homepage": "https://github.com/sebastianbergmann/diff", "keywords": [ "diff" ], - "time": "2015-02-22 15:13:53" + "time": "2015-12-08 07:14:41" }, { "name": "sebastian/environment", - "version": "1.3.2", + "version": "1.3.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "6324c907ce7a52478eeeaede764f48733ef5ae44" + "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6324c907ce7a52478eeeaede764f48733ef5ae44", - "reference": "6324c907ce7a52478eeeaede764f48733ef5ae44", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/be2c607e43ce4c89ecd60e75c6a85c126e754aea", + "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^5.3.3 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^4.8 || ^5.0" }, "type": "library", "extra": { @@ -703,20 +902,20 @@ "environment", "hhvm" ], - "time": "2015-08-03 06:14:51" + "time": "2016-08-18 05:49:44" }, { "name": "sebastian/exporter", - "version": "1.2.1", + "version": "1.2.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "7ae5513327cb536431847bcc0c10edba2701064e" + "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/7ae5513327cb536431847bcc0c10edba2701064e", - "reference": "7ae5513327cb536431847bcc0c10edba2701064e", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/42c4c2eec485ee3e159ec9884f95b431287edde4", + "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4", "shasum": "" }, "require": { @@ -724,12 +923,13 @@ "sebastian/recursion-context": "~1.0" }, "require-dev": { + "ext-mbstring": "*", "phpunit/phpunit": "~4.4" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2.x-dev" + "dev-master": "1.3.x-dev" } }, "autoload": { @@ -769,7 +969,7 @@ "export", "exporter" ], - "time": "2015-06-21 07:55:53" + "time": "2016-06-17 09:04:28" }, { "name": "sebastian/global-state", @@ -823,17 +1023,63 @@ "time": "2015-10-12 03:26:01" }, { - "name": "sebastian/recursion-context", - "version": "1.0.1", + "name": "sebastian/object-enumerator", + "version": "1.0.0", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "994d4a811bafe801fb06dccbee797863ba2792ba" + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "d4ca2fb70344987502567bc50081c03e6192fb26" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/994d4a811bafe801fb06dccbee797863ba2792ba", - "reference": "994d4a811bafe801fb06dccbee797863ba2792ba", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/d4ca2fb70344987502567bc50081c03e6192fb26", + "reference": "d4ca2fb70344987502567bc50081c03e6192fb26", + "shasum": "" + }, + "require": { + "php": ">=5.6", + "sebastian/recursion-context": "~1.0" + }, + "require-dev": { + "phpunit/phpunit": "~5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "time": "2016-01-28 13:25:10" + }, + { + "name": "sebastian/recursion-context", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "913401df809e99e4f47b27cdd781f4a258d58791" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/913401df809e99e4f47b27cdd781f4a258d58791", + "reference": "913401df809e99e4f47b27cdd781f4a258d58791", "shasum": "" }, "require": { @@ -873,23 +1119,73 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2015-06-21 08:04:50" + "time": "2015-11-11 19:50:13" }, { - "name": "sebastian/version", - "version": "1.0.6", + "name": "sebastian/resource-operations", + "version": "1.0.0", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/version.git", - "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6" + "url": "https://github.com/sebastianbergmann/resource-operations.git", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", - "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", "shasum": "" }, + "require": { + "php": ">=5.6.0" + }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides a list of PHP built-in functions that operate on resources", + "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "time": "2015-07-28 20:34:47" + }, + { + "name": "sebastian/version", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "c829badbd8fdf16a0bad8aa7fa7971c029f1b9c5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c829badbd8fdf16a0bad8aa7fa7971c029f1b9c5", + "reference": "c829badbd8fdf16a0bad8aa7fa7971c029f1b9c5", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, "autoload": { "classmap": [ "src/" @@ -908,7 +1204,7 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2015-06-21 13:59:46" + "time": "2016-02-04 12:56:52" }, { "name": "squizlabs/php_codesniffer", @@ -987,31 +1283,34 @@ }, { "name": "symfony/yaml", - "version": "v2.7.6", + "version": "v3.1.4", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "eca9019c88fbe250164affd107bc8057771f3f4d" + "reference": "f291ed25eb1435bddbe8a96caaef16469c2a092d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/eca9019c88fbe250164affd107bc8057771f3f4d", - "reference": "eca9019c88fbe250164affd107bc8057771f3f4d", + "url": "https://api.github.com/repos/symfony/yaml/zipball/f291ed25eb1435bddbe8a96caaef16469c2a092d", + "reference": "f291ed25eb1435bddbe8a96caaef16469c2a092d", "shasum": "" }, "require": { - "php": ">=5.3.9" + "php": ">=5.5.9" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.7-dev" + "dev-master": "3.1-dev" } }, "autoload": { "psr-4": { "Symfony\\Component\\Yaml\\": "" - } + }, + "exclude-from-classmap": [ + "/Tests/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -1029,7 +1328,57 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2015-10-11 09:39:48" + "time": "2016-09-02 02:12:52" + }, + { + "name": "webmozart/assert", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/webmozart/assert.git", + "reference": "bb2d123231c095735130cc8f6d31385a44c7b308" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozart/assert/zipball/bb2d123231c095735130cc8f6d31385a44c7b308", + "reference": "bb2d123231c095735130cc8f6d31385a44c7b308", + "shasum": "" + }, + "require": { + "php": "^5.3.3|^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.6", + "sebastian/version": "^1.0.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "time": "2016-08-09 15:02:57" } ], "aliases": [], @@ -1037,6 +1386,8 @@ "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, - "platform": [], + "platform": { + "php": ">=7.0" + }, "platform-dev": [] } From 7e2702ba9374c4270cacedf84cbbfbb6822a7c97 Mon Sep 17 00:00:00 2001 From: Dominik Liebler Date: Wed, 21 Sep 2016 14:42:16 +0200 Subject: [PATCH 2/4] removed old PHP versions from travis build --- .travis.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9f379f8..cb88b17 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,17 +3,10 @@ language: php sudo: false php: - - 5.3 - - 5.4 - - 5.5 - - 5.6 - 7.0 - - hhvm + - 7.1 matrix: - allow_failures: - - php: hhvm - - php: 7.0 fast_finish: true cache: From 1ff4203bebab4b6fc4df0980dd180d4267317b8a Mon Sep 17 00:00:00 2001 From: Dominik Liebler Date: Wed, 21 Sep 2016 14:58:49 +0200 Subject: [PATCH 3/4] fixed translation --- locale/ca/LC_MESSAGES/Behavioral/Iterator/README.po | 6 ++---- locale/es/LC_MESSAGES/Behavioral/Iterator/README.po | 6 ++---- locale/pt_BR/LC_MESSAGES/Behavioral/Iterator/README.po | 6 ++---- locale/ru/LC_MESSAGES/Behavioral/Iterator/README.po | 4 +--- locale/zh_CN/LC_MESSAGES/Behavioral/Iterator/README.po | 6 ++---- 5 files changed, 9 insertions(+), 19 deletions(-) diff --git a/locale/ca/LC_MESSAGES/Behavioral/Iterator/README.po b/locale/ca/LC_MESSAGES/Behavioral/Iterator/README.po index 3000658..34ecd7d 100644 --- a/locale/ca/LC_MESSAGES/Behavioral/Iterator/README.po +++ b/locale/ca/LC_MESSAGES/Behavioral/Iterator/README.po @@ -1,4 +1,4 @@ -# +# msgid "" msgstr "" "Project-Id-Version: DesignPatternsPHP 1.0\n" @@ -20,9 +20,7 @@ msgid "Purpose" msgstr "" #: ../../Behavioral/Iterator/README.rst:7 -msgid "" -"To make an object iterable and to make it appear like a collection of " -"objects." +msgid "To make an object iterable and to make it appear like a collection of objects." msgstr "" #: ../../Behavioral/Iterator/README.rst:11 diff --git a/locale/es/LC_MESSAGES/Behavioral/Iterator/README.po b/locale/es/LC_MESSAGES/Behavioral/Iterator/README.po index 3000658..34ecd7d 100644 --- a/locale/es/LC_MESSAGES/Behavioral/Iterator/README.po +++ b/locale/es/LC_MESSAGES/Behavioral/Iterator/README.po @@ -1,4 +1,4 @@ -# +# msgid "" msgstr "" "Project-Id-Version: DesignPatternsPHP 1.0\n" @@ -20,9 +20,7 @@ msgid "Purpose" msgstr "" #: ../../Behavioral/Iterator/README.rst:7 -msgid "" -"To make an object iterable and to make it appear like a collection of " -"objects." +msgid "To make an object iterable and to make it appear like a collection of objects." msgstr "" #: ../../Behavioral/Iterator/README.rst:11 diff --git a/locale/pt_BR/LC_MESSAGES/Behavioral/Iterator/README.po b/locale/pt_BR/LC_MESSAGES/Behavioral/Iterator/README.po index 3000658..1212041 100644 --- a/locale/pt_BR/LC_MESSAGES/Behavioral/Iterator/README.po +++ b/locale/pt_BR/LC_MESSAGES/Behavioral/Iterator/README.po @@ -1,4 +1,4 @@ -# +# msgid "" msgstr "" "Project-Id-Version: DesignPatternsPHP 1.0\n" @@ -20,9 +20,7 @@ msgid "Purpose" msgstr "" #: ../../Behavioral/Iterator/README.rst:7 -msgid "" -"To make an object iterable and to make it appear like a collection of " -"objects." +msgid To make an object iterable and to make it appear like a collection of objects." msgstr "" #: ../../Behavioral/Iterator/README.rst:11 diff --git a/locale/ru/LC_MESSAGES/Behavioral/Iterator/README.po b/locale/ru/LC_MESSAGES/Behavioral/Iterator/README.po index 1d5061d..37fa467 100644 --- a/locale/ru/LC_MESSAGES/Behavioral/Iterator/README.po +++ b/locale/ru/LC_MESSAGES/Behavioral/Iterator/README.po @@ -20,9 +20,7 @@ msgid "Purpose" msgstr "Назначение" #: ../../Behavioral/Iterator/README.rst:7 -msgid "" -"To make an object iterable and to make it appear like a collection of " -"objects." +msgid "To make an object iterable and to make it appear like a collection of objects." msgstr "" "Добавить коллекции объектов функционал последовательного доступа к " "содержащимся в ней экземплярам объектов без реализации этого функционала в " diff --git a/locale/zh_CN/LC_MESSAGES/Behavioral/Iterator/README.po b/locale/zh_CN/LC_MESSAGES/Behavioral/Iterator/README.po index 3000658..1212041 100644 --- a/locale/zh_CN/LC_MESSAGES/Behavioral/Iterator/README.po +++ b/locale/zh_CN/LC_MESSAGES/Behavioral/Iterator/README.po @@ -1,4 +1,4 @@ -# +# msgid "" msgstr "" "Project-Id-Version: DesignPatternsPHP 1.0\n" @@ -20,9 +20,7 @@ msgid "Purpose" msgstr "" #: ../../Behavioral/Iterator/README.rst:7 -msgid "" -"To make an object iterable and to make it appear like a collection of " -"objects." +msgid To make an object iterable and to make it appear like a collection of objects." msgstr "" #: ../../Behavioral/Iterator/README.rst:11 From 57c2e4f025b2ed35911c4a9fbb277b226e19cbae Mon Sep 17 00:00:00 2001 From: Dominik Liebler Date: Thu, 22 Sep 2016 08:47:57 +0200 Subject: [PATCH 4/4] #232 simplified things a bit --- Behavioral/Iterator/BookList.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Behavioral/Iterator/BookList.php b/Behavioral/Iterator/BookList.php index e69825f..f8d0c87 100644 --- a/Behavioral/Iterator/BookList.php +++ b/Behavioral/Iterator/BookList.php @@ -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]); } }