/** * @param mixed:\DateInterval|\DateInterval[] $vars * @param \DateInterval $vars,... * @return \DateInterval */ public static function sum() { $intervals = array(); foreach (func_get_args() as $e) { if (is_array($e)) { $intervals = array_merge($intervals, array_values($e)); } else { $intervals[] = $e; } } $base = $intervals[0]; unset($intervals[0]); try { /* @var $intervals \DateInterval[] */ $intervals = ParameterConverter::toArray($intervals, '\\DateInterval'); } catch (\DomainException $e) { throw new \InvalidArgumentException('This method only accepts \\DateInterval objects.'); } $s = self::toSeconds($base); foreach ($intervals as $interval) { /* @var $interval \DateInterval */ if (!$interval->invert) { $s += self::toSeconds($interval); } else { $s -= self::toSeconds($interval); } } $result = new \DateInterval(sprintf('PT%dS', abs($s))); $result = new \DateInterval(self::shortenString($result)); if ($s < 0) { $result->invert = true; } return $result; }
/** * @return VectorInterface */ public function add() { $vectors = func_get_args(); try { $vectors = ParameterConverter::toArray($vectors, 'Alameda\\Component\\Math\\VectorInterface'); } catch (\DomainException $e) { throw $e; } foreach ($vectors as $v) { /* @var $v VectorInterface */ if ($this->getSize() !== $v->getSize()) { throw new \InvalidArgumentException('The vectors need to have the same amount of dimensions.'); } foreach ($v->getCoordinates() as $d => $c) { $this->coordinates[$d] += $c; } } return $this; }
/** * @expectedException \DomainException */ public function testInvalidScalarTypes() { $string = 'string'; ParameterConverter::toArray($string, 'string'); }