Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.00% |
9 / 10 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| HashmapUtils | |
90.00% |
9 / 10 |
|
75.00% |
3 / 4 |
12.14 | |
0.00% |
0 / 1 |
| __construct | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| isHashmap | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
3 | |||
| getArrayType | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| isList | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
3 | |||
| isSet | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | namespace Apie\Core\Utils; |
| 3 | |
| 4 | use Apie\Core\Lists\ItemHashmap; |
| 5 | use Apie\Core\Lists\ItemList; |
| 6 | use Apie\Core\Lists\ItemSet; |
| 7 | use Apie\TypeConverter\ReflectionTypeFactory; |
| 8 | use ReflectionClass; |
| 9 | use ReflectionMethod; |
| 10 | use ReflectionProperty; |
| 11 | use ReflectionType; |
| 12 | |
| 13 | final class HashmapUtils |
| 14 | { |
| 15 | /** |
| 16 | * @codeCoverageIgnore |
| 17 | */ |
| 18 | private function __construct() |
| 19 | { |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * @param string|ReflectionClass<object>|ReflectionProperty|ReflectionType|ReflectionMethod $input |
| 24 | */ |
| 25 | public static function isHashmap(string|ReflectionClass|ReflectionProperty|ReflectionType|ReflectionMethod $input): bool |
| 26 | { |
| 27 | $class = ConverterUtils::toReflectionClass($input); |
| 28 | return $class !== null && ($class->name === ItemHashmap::class || $class->isSubclassOf(ItemHashmap::class)); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * @param string|ReflectionClass<object>|ReflectionProperty|ReflectionType|ReflectionMethod $input |
| 33 | */ |
| 34 | public static function getArrayType(string|ReflectionClass|ReflectionProperty|ReflectionType|ReflectionMethod $input): ReflectionType |
| 35 | { |
| 36 | $class = ConverterUtils::toReflectionClass($input); |
| 37 | if ($class === null) { |
| 38 | return ReflectionTypeFactory::createReflectionType('mixed'); |
| 39 | } |
| 40 | return $class->getMethod('offsetGet')->getReturnType() ?? ReflectionTypeFactory::createReflectionType('mixed'); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @param string|ReflectionClass<object>|ReflectionProperty|ReflectionType|ReflectionMethod $input |
| 45 | */ |
| 46 | public static function isList(string|ReflectionClass|ReflectionProperty|ReflectionType|ReflectionMethod $input): bool |
| 47 | { |
| 48 | $class = ConverterUtils::toReflectionClass($input); |
| 49 | return $class !== null && ($class->name === ItemList::class || $class->isSubclassOf(ItemList::class)); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @param string|ReflectionClass<object>|ReflectionProperty|ReflectionType|ReflectionMethod $input |
| 54 | */ |
| 55 | public static function isSet(string|ReflectionClass|ReflectionProperty|ReflectionType|ReflectionMethod $input): bool |
| 56 | { |
| 57 | $class = ConverterUtils::toReflectionClass($input); |
| 58 | return $class !== null && ($class->name === ItemSet::class || $class->isSubclassOf(ItemSet::class)); |
| 59 | } |
| 60 | } |