コード例 #1
0
 /**
  * Returns the array type contained in the given type, or null if no array
  * type is available.
  *
  * @param PhpType|null $type
  *
  * @return ArrayType|null
  */
 private function getContainedArrayType(PhpType $type = null)
 {
     if (null === $type) {
         return null;
     }
     if ($type->isArrayType()) {
         return $type;
     }
     if (!$type->isUnionType()) {
         return null;
     }
     foreach ($type->getAlternates() as $alt) {
         if ($alt->isArrayType()) {
             return $alt;
         }
     }
     return null;
 }
コード例 #2
0
 /**
  * Emulates a loose comparison between two types, and returns the result.
  *
  * The result can be true, false, or unknown:
  *
  *     - true: loose comparison of these types is always true
  *     - false: loose comparison of these types is always false
  *     - unknown: outcome depends on the actual values of these types
  *
  * @see http://php.net/manual/en/types.comparisons.php (table with loose comparison ==)
  *
  * @param PhpType $thisType
  * @param PhpType $thatType
  */
 public function testForEquality(PhpType $that)
 {
     if ($that->isAllType() || $that->isUnknownType() || $that->isNoResolvedType() || $this->isAllType() || $this->isUnknownType() || $this->isNoResolvedType()) {
         return TernaryValue::get('unknown');
     }
     if ($this->isNoType() || $that->isNoType()) {
         if ($this->isNoType() && $that->isNoType()) {
             return TernaryValue::get('true');
         }
         return TernaryValue::get('unknown');
     }
     $isThisNumeric = $this->isIntegerType() || $this->isDoubleType();
     $isThatNumeric = $that->isIntegerType() || $that->isDoubleType();
     if (($isThisNumeric || $this->isStringType()) && $that->isArrayType() || ($isThatNumeric || $that->isStringType()) && $this->isArrayType()) {
         return TernaryValue::get('false');
     }
     if ($this->isObjectType() ^ $that->isObjectType()) {
         return TernaryValue::get('false');
     }
     if ($that->isUnionType()) {
         return $that->testForEquality($this);
     }
     if ($this->isArrayType() && $that->isArrayType()) {
         // TODO: Maybe make this more sophisticated by looking at the key,
         //       and element types.
         return TernaryValue::get('unknown');
     }
     // If this is reached, then this base type does not have enough information to
     // make an informed decision, but the method should be overridden by a subtype
     // as this method eventually is never allowed to return null.
     return null;
 }