| Total Complexity | 7 |
| Total Lines | 58 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class TypeParanoia extends TypeCertainty |
||
| 12 | { |
||
| 13 | const INDEX_SECOND_ARG = 2; |
||
| 14 | |||
| 15 | const INT_ARG_OFFSET = 5; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @param string|object $object |
||
| 19 | * |
||
| 20 | * @psalm-param class-string|object $object |
||
| 21 | */ |
||
| 22 | 20 | public static function ThrowIfNotType( |
|
| 23 | $object, |
||
| 24 | int $argument, |
||
| 25 | string $class, |
||
| 26 | string $function, |
||
| 27 | string ...$types |
||
| 28 | ) : void { |
||
| 29 | 20 | foreach ($types as $i => $type) { |
|
| 30 | 20 | if ( ! interface_exists($type) && ! class_exists($type)) { |
|
| 31 | 2 | throw new InvalidArgumentException( |
|
| 32 | 'Argument ' . |
||
| 33 | 2 | (self::INT_ARG_OFFSET + $i) . |
|
| 34 | 2 | ' passed to ' . |
|
| 35 | 2 | __METHOD__ . |
|
| 36 | 2 | ' must be a class or interface!' |
|
| 37 | ); |
||
| 38 | 18 | } elseif ( ! is_a($object, $type, is_string($object))) { |
|
| 39 | 12 | throw new DaftObjectRepositoryTypeByClassMethodAndTypeException( |
|
| 40 | 12 | $argument, |
|
| 41 | 12 | $class, |
|
| 42 | 12 | $function, |
|
| 43 | 12 | $type, |
|
| 44 | 18 | is_string($object) ? $object : get_class($object) |
|
| 45 | ); |
||
| 46 | } |
||
| 47 | } |
||
| 48 | 12 | } |
|
| 49 | |||
| 50 | /** |
||
| 51 | * @param string|object $object |
||
| 52 | * |
||
| 53 | * @psalm-param class-string<DefinesOwnIdPropertiesInterface>|DefinesOwnIdPropertiesInterface $object |
||
| 54 | */ |
||
| 55 | 10 | public static function ThrowIfNotDaftObjectIdPropertiesType( |
|
| 69 | ); |
||
| 70 | 4 | } |
|
| 72 |