Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
typedeclarationchecker.php
1<?php
2
3declare(strict_types=1);
4
6
8{
9 private \ReflectionNamedType $type;
10 private mixed $desiredValue;
11
12 public function __construct(\ReflectionNamedType $type, mixed $desiredValue)
13 {
14 $this->type = $type;
15 $this->desiredValue = $desiredValue;
16 }
17
18 public function isSatisfied(): bool
19 {
20 if (!$this->type->isBuiltin())
21 {
22 return false;
23 }
24
25 if ($this->type->getName() === \gettype($this->desiredValue))
26 {
27 return true;
28 }
29
30 //gettype returns 'double' when type is float :)
31 if (\is_float($this->desiredValue) && $this->type->getName() === 'float')
32 {
33 return true;
34 }
35
36 if ($this->desiredValue === null && $this->type->allowsNull())
37 {
38 return true;
39 }
40
41 return match ($this->type->getName())
42 {
43 'bool' => \is_scalar($this->desiredValue),
44 'float', 'int' => \is_numeric($this->desiredValue),
45 'string' => \is_string($this->desiredValue),
46 default => false,
47 };
48 }
49
50 public function isArray(): bool
51 {
52 return $this->type->getName() === 'array';
53 }
54}
__construct(\ReflectionNamedType $type, mixed $desiredValue)