/** * @param string $traversableType * @param string $orderedTraversableType * @param string $joiningOnTraversableType * @param string $joiningToTraversableType * @param bool $mutable * * @return array */ protected function generatePinqTypeData($traversableType, $orderedTraversableType, $joiningOnTraversableType, $joiningToTraversableType, $mutable = false) { $pinqTypes = []; $traversableTypeId = TypeId::getObject($traversableType); $orderedTraversableTypeId = TypeId::getObject($orderedTraversableType); $joiningOnTraversableTypeId = TypeId::getObject($joiningOnTraversableType); $joiningToTraversableTypeId = TypeId::getObject($joiningToTraversableType); $commonMethods = ['asArray' => INativeType::TYPE_ARRAY, 'asTraversable' => TypeId::getObject(Pinq\ITraversable::ITRAVERSABLE_TYPE), 'asCollection' => TypeId::getObject(Pinq\ICollection::ICOLLECTION_TYPE), 'isSource' => INativeType::TYPE_BOOL, 'getSource' => $traversableTypeId, 'iterate' => INativeType::TYPE_NULL, 'getIterator' => TypeId::getObject('Traversable'), 'getTrueIterator' => TypeId::getObject('Traversable'), 'getIteratorScheme' => TypeId::getObject(IIteratorScheme::IITERATOR_SCHEME_TYPE), 'first' => INativeType::TYPE_MIXED, 'last' => INativeType::TYPE_MIXED, 'count' => INativeType::TYPE_INT, 'isEmpty' => INativeType::TYPE_BOOL, 'aggregate' => INativeType::TYPE_MIXED, 'maximum' => INativeType::TYPE_MIXED, 'minimum' => INativeType::TYPE_MIXED, 'sum' => INativeType::TYPE_MIXED, 'average' => INativeType::TYPE_MIXED, 'all' => INativeType::TYPE_BOOL, 'any' => INativeType::TYPE_BOOL, 'implode' => INativeType::TYPE_STRING, 'contains' => INativeType::TYPE_BOOL, 'where' => $traversableTypeId, 'orderBy' => $orderedTraversableTypeId, 'orderByAscending' => $orderedTraversableTypeId, 'orderByDescending' => $orderedTraversableTypeId, 'skip' => $traversableTypeId, 'take' => $traversableTypeId, 'slice' => $traversableTypeId, 'indexBy' => $traversableTypeId, 'keys' => $traversableTypeId, 'reindex' => $traversableTypeId, 'groupBy' => $traversableTypeId, 'join' => $joiningOnTraversableTypeId, 'groupJoin' => $joiningOnTraversableTypeId, 'select' => $traversableTypeId, 'selectMany' => $traversableTypeId, 'unique' => $traversableTypeId, 'append' => $traversableTypeId, 'whereIn' => $traversableTypeId, 'except' => $traversableTypeId, 'union' => $traversableTypeId, 'intersect' => $traversableTypeId, 'difference' => $traversableTypeId]; if ($mutable) { $commonMethods += ['apply' => INativeType::TYPE_NULL, 'addRange' => INativeType::TYPE_NULL, 'remove' => INativeType::TYPE_NULL, 'removeRange' => INativeType::TYPE_NULL, 'removeWhere' => INativeType::TYPE_NULL, 'clear' => INativeType::TYPE_NULL]; } $pinqTypes[$traversableType] = ['methods' => $commonMethods]; $pinqTypes[$orderedTraversableType] = ['methods' => ['thenBy' => $orderedTraversableTypeId, 'thenByAscending' => $orderedTraversableTypeId, 'thenByDescending' => $orderedTraversableTypeId] + $commonMethods]; $joiningMethods = ['withDefault' => $joiningToTraversableTypeId, 'to' => $traversableTypeId]; if ($mutable) { $joiningMethods += ['apply' => INativeType::TYPE_NULL]; } $pinqTypes[$joiningToTraversableType] = ['methods' => $joiningMethods]; $pinqTypes[$joiningOnTraversableType] = ['methods' => ['on' => $joiningToTraversableTypeId, 'onEquality' => $joiningToTraversableTypeId] + $joiningMethods]; return $pinqTypes; }
protected function getObjectTypeData($classType) { $classType = $this->normalizeClassName($classType); $data = isset($this->classTypeMap[$classType]) ? $this->classTypeMap[$classType] : []; foreach (['methods', 'fields', 'static-fields'] as $property) { if (!isset($data[$property])) { $data[$property] = []; } foreach ($data[$property] as &$returnType) { if ($returnType === self::TYPE_SELF) { $returnType = TypeId::getObject($classType); } } } return $data; }
public function types() { return ['DateTime' => ['methods' => ['add' => self::TYPE_SELF, 'createFromFormat' => self::TYPE_SELF, 'getLastErrors' => INativeType::TYPE_ARRAY, 'modify' => self::TYPE_SELF, 'setDate' => self::TYPE_SELF, 'setISODate' => self::TYPE_SELF, 'setTime' => self::TYPE_SELF, 'setTimestamp' => self::TYPE_SELF, 'setTimezone' => self::TYPE_SELF, 'sub' => self::TYPE_SELF, 'diff' => TypeId::getObject('DateInterval'), 'format' => INativeType::TYPE_STRING, 'getOffset' => INativeType::TYPE_INT, 'getTimestamp' => INativeType::TYPE_INT, 'getTimezone' => TypeId::getObject('DateTimeZone')]], 'DateInterval' => ['fields' => ['y' => INativeType::TYPE_INT, 'm' => INativeType::TYPE_INT, 'd' => INativeType::TYPE_INT, 'h' => INativeType::TYPE_INT, 'i' => INativeType::TYPE_INT, 's' => INativeType::TYPE_INT, 'invert' => INativeType::TYPE_INT, 'days' => INativeType::TYPE_MIXED], 'methods' => ['createFromDateString' => self::TYPE_SELF, 'format' => INativeType::TYPE_STRING]], 'DateTimeZone' => ['methods' => ['getLocation' => INativeType::TYPE_ARRAY, 'getName' => INativeType::TYPE_STRING, 'getOffset' => TypeId::getObject('DateTime'), 'getTransitions' => INativeType::TYPE_ARRAY, 'listAbbreviations' => INativeType::TYPE_ARRAY, 'listIdentifiers' => INativeType::TYPE_ARRAY]]]; }
public function getObjectType($classType) { $normalizedClassType = $this->normalizeClassName($classType); $typeId = TypeId::getObject($normalizedClassType); if (!isset($this->objectTypes[$typeId])) { $this->objectTypes[$typeId] = $this->buildObjectType($typeId, $normalizedClassType); } return $this->objectTypes[$typeId]; }
public function testCompositeType() { $compositeType = $this->typeSystem->getType(TypeId::getComposite([TypeId::getObject('ArrayAccess'), TypeId::getObject('Countable')])); $indexer = $compositeType->getIndex(O\Expression::index(O\Expression::value([]), O\Expression::value('s'))); $this->assertEqualTypes($this->typeSystem->getObjectType('ArrayAccess'), $indexer->getSourceType()); $this->assertEqualsNativeType(INativeType::TYPE_MIXED, $indexer->getReturnType()); $method = $compositeType->getMethod(O\Expression::methodCall(O\Expression::value([]), O\Expression::value('offsetExists'))); $this->assertEqualTypes($this->typeSystem->getObjectType('ArrayAccess'), $method->getSourceType()); $this->assertEqualsNativeType(INativeType::TYPE_BOOL, $method->getReturnType()); $method = $compositeType->getMethod(O\Expression::methodCall(O\Expression::value([]), O\Expression::value('count'))); $this->assertEqualTypes($this->typeSystem->getObjectType('Countable'), $method->getSourceType()); $this->assertEqualsNativeType(INativeType::TYPE_INT, $method->getReturnType()); }