PocketMine-MP 5.35.1 git-09f4626fa630fccbe1d56a65a90ff8f3566e4db8
Loading...
Searching...
No Matches
ParameterInfo.php
1<?php declare(strict_types=1);
2
3namespace DaveRandom\CallbackValidator;
4
6
7final class ParameterInfo{
8 public function __construct(
9 public readonly string $name,
10 public readonly ?BaseType $type,
11 public readonly bool $byReference,
12 public readonly bool $isOptional,
13 public readonly bool $isVariadic
14 ){}
15
16 public function isSatisfiedBy(ParameterInfo $other) : bool{
17 //contravariance can be tested as covariance by swapping the types
18 return $this->byReference === $other->byReference && MatchTester::isCovariant($other->type, $this->type);
19 }
20
24 public function __toString() : string{
25 $string = '';
26
27 if($this->type !== null){
28 $string .= $this->type->stringify() . ' ';
29 }
30
31 if($this->byReference){
32 $string .= '&';
33 }
34
35 if($this->isVariadic){
36 $string .= '...';
37 }
38
39 $string .= '$' . $this->name;
40 return $string;
41 }
42}