Exemple #1
0
 /**
  * @param string|object|array $type
  * @param bool $onlyOr
  * @return string
  */
 public static function getFor($type, $onlyOr = false)
 {
     if (is_array($type)) {
         $messagesFor = f\partial(a\map, ['\\nspl\\args\\_p\\ErrorMessage', 'getFor']);
         if ($onlyOr) {
             return implode(' or ', $messagesFor($type));
         } else {
             $isOr = function ($t) {
                 return isset(Checker::$isOr[$t]) || class_exists($t) || interface_exists($t);
             };
             list($orTypes, $andTypes) = a\partition($isOr, $type);
             return implode(' and ', array_filter([implode(' or ', $messagesFor($orTypes)), implode(' and ', $messagesFor($andTypes))]));
         }
     }
     if ($type instanceof Constraint) {
         return $type->__toString();
     }
     $default = class_exists($type) || interface_exists($type) ? $type : implode(' ', array_map('strtolower', preg_split('/(?=[A-Z])/', a\last(explode('\\', $type)))));
     return a\value(self::$messages, $type, 'be ' . $default);
 }
Exemple #2
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testLastForEmptyList()
 {
     last([]);
 }