I believe that DTO should be as dummy and easy as possible. However, after hint made by my friend, opportunity to validate data that is set in DTO sounds tempting.
Let's have following example:
//this class only holds bunch of objects from the future
class FooFuture{
/** @var ArrayObject */
$collection;
(other fields ommited for readability)
/**
* @param ArrayObject $collection
*/
public function __construct(ArrayObject $collection = null){
if(null === $collection){
$this->collection = new ArrayObject();
} else {
$this->collection = $collection;
}
}
/**
* @param ArrayObject $col
*/
public function setCollection(ArrayObject $col){
$now = new DateTime();
foreach($col as $element){
if($element->getDateTime() < $now){
throw new InvalidArgumentException('Collection should only contain objects from the future');
}
}
}
/**
* @return ArrayObject
*/
public function getCollection(){
return $this->collection;
}
}
What do you think?
$element->getDateTime()
will be?$now
.