コード例 #1
0
ファイル: UnionType.php プロジェクト: sekjun9878/juggler
 public function juggle(Type $type)
 {
     if (array_filter($this->types, function (Type $element) use($type) {
         return array_filter($type->getTypes(), function (Type $element) use($type) {
             return $element->juggle($type);
         });
     })) {
         return $type;
     }
     return null;
 }
コード例 #2
0
ファイル: ScalarTypeBase.php プロジェクト: sekjun9878/juggler
 public function juggle(Type $type)
 {
     /*
      * This is a predicate to determine whether the CURRENT type (the child class)
      * can be juggled into the Type $type.
      */
     $predicate = function (Type $element) {
         return array_any($this->getAllowedJuggleTypes(), function (Type $value, $index, $collection) use($element) {
             return (bool) Type::intersect($element, $value);
         });
     };
     $x = array_filter($type->getTypes(), $predicate);
     if (!$x) {
         return null;
     }
     if (count($x) === 1) {
         return first($x);
     }
     return UnionType::createIfNotDuplicate(array_shift($x), ...$x);
 }