2f7039c5aa6372b53935ef50d699c687b83f696a
[GitHub/WoltLab/WCF.git] /
1 <?php
2
3 declare(strict_types=1);
4
5 namespace CuyZ\Valinor\Type\Parser\Exception\Generic;
6
7 use CuyZ\Valinor\Type\Parser\Exception\InvalidType;
8 use CuyZ\Valinor\Type\Type;
9 use RuntimeException;
10
11 use function array_fill;
12 use function array_map;
13 use function count;
14 use function implode;
15
16 /** @internal */
17 final class MissingGenerics extends RuntimeException implements InvalidType
18 {
19 /**
20 * @param class-string $className
21 * @param Type[] $generics
22 * @param Type[] $templates
23 */
24 public function __construct(string $className, array $generics, array $templates)
25 {
26 /** @var positive-int $missing */
27 $missing = count($templates) - count($generics);
28 $generics = array_map(fn (Type $type) => $type->toString(), $generics);
29 $generics += array_fill(count($generics), $missing, '?');
30
31 $signature = $className . '<' . implode(', ', $generics) . '>';
32
33 parent::__construct(
34 "There are $missing missing generics for `$signature`.",
35 1618054357
36 );
37 }
38 }