zendframework/zf2 — pull request #5233 by texdc (2013-10-05 23:31:57+00:00)
Title: [stdlib] Add guard traits

The check for `array` or `Traversable` code is littered throughout the framework. This is a prime opportunity for a trait. Included a couple extra traits for good measure.

For example, https://github.com/zendframework/zf2/blob/master/library/Zend/Form/Fieldset.php#L297 could be:

```php
class Fieldset extends Element implements FieldsetInterface
{
use \Zend\Stdlib\Guard\ArrayOrTraversableGuardTrait;

// ...

public function setMessages($messages)
{
$this->guardForArrayOrTraversable(
$messages, 'Messages', __NAMESPACE__ . '\Exception\InvalidArgumentException'
);

foreach ($messages as $elementName => $elementMessages) {
$this->get($elementName)->setMessages($elementMessages);
}

return $this;
}

// ...

}
```

Please see http://verraes.net/2013/09/extract-till-you-drop/