k0a1a / hotglue2

HOTGLUE is a Content Manipulation System which allows to construct websites directly in a web-browser.
http://hotglue.me/demo
GNU General Public License v3.0
275 stars 38 forks source link

Get rid of array_shift #10

Closed dereckson closed 7 years ago

dereckson commented 7 years ago

The array_shift PHP function expects an array to manipulate, stored in a variable. As such, it's a poor candidate to get the first element of an array, as it will raise a strict exception if we pass it a reference to an array instead.

We supersede array_shift by an universal function to get the first element of any array or object which implements the Traversable interface, kicking the iterator to pick th first element.

Fixes #9.

dereckson commented 7 years ago

Tests under PHP 5.6.30

PHPUnit 5.7.5-47-g58613c7c by Sebastian Bergmann and contributors.

...                                                                 3 / 3 (100%)

Time: 186 ms, Memory: 3.50MB

OK (3 tests, 8 assertions)

Tests under PHP 7.1.0

PHPUnit 5.7.5-47-g58613c7c by Sebastian Bergmann and contributors.

S..                                                                 3 / 3 (100%)

Time: 216 ms, Memory: 4.00MB

OK, but incomplete, skipped, or risky tests!
Tests: 3, Assertions: 4, Skipped: 1.
k0a1a commented 7 years ago

Tests confirmed, thanks for your quick fix!