|
| 1 | +<?php declare(strict_types = 0); |
| 2 | + |
| 3 | +namespace Bug12393b; |
| 4 | + |
| 5 | +use function PHPStan\Testing\assertNativeType; |
| 6 | +use function PHPStan\Testing\assertType; |
| 7 | + |
| 8 | +class HelloWorld |
| 9 | +{ |
| 10 | + private string $name; |
| 11 | + |
| 12 | + /** @var string */ |
| 13 | + private $untypedName; |
| 14 | + |
| 15 | + private float $float; |
| 16 | + |
| 17 | + /** @var float */ |
| 18 | + private $untypedFloat; |
| 19 | + |
| 20 | + private array $a; |
| 21 | + |
| 22 | + /** |
| 23 | + * @param mixed[] $plugin |
| 24 | + */ |
| 25 | + public function __construct(array $plugin){ |
| 26 | + $this->name = $plugin["name"]; |
| 27 | + assertType('string', $this->name); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * @param mixed[] $plugin |
| 32 | + */ |
| 33 | + public function doFoo(array $plugin){ |
| 34 | + $this->untypedName = $plugin["name"]; |
| 35 | + assertType('mixed', $this->untypedName); |
| 36 | + } |
| 37 | + |
| 38 | + public function doBar(int $i){ |
| 39 | + $this->float = $i; |
| 40 | + assertType('float', $this->float); |
| 41 | + } |
| 42 | + |
| 43 | + public function doBaz(int $i){ |
| 44 | + $this->untypedFloat = $i; |
| 45 | + assertType('int', $this->untypedFloat); |
| 46 | + } |
| 47 | + |
| 48 | + public function doLorem(): void |
| 49 | + { |
| 50 | + $this->a = ['a' => 1]; |
| 51 | + assertType('array{a: 1}', $this->a); |
| 52 | + } |
| 53 | + |
| 54 | + public function doFloatTricky(){ |
| 55 | + $this->float = 1; |
| 56 | + assertType('1.0', $this->float); |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +class HelloWorldStatic |
| 61 | +{ |
| 62 | + private static string $name; |
| 63 | + |
| 64 | + /** @var string */ |
| 65 | + private static $untypedName; |
| 66 | + |
| 67 | + private static float $float; |
| 68 | + |
| 69 | + /** @var float */ |
| 70 | + private static $untypedFloat; |
| 71 | + |
| 72 | + private static array $a; |
| 73 | + |
| 74 | + /** |
| 75 | + * @param mixed[] $plugin |
| 76 | + */ |
| 77 | + public function __construct(array $plugin){ |
| 78 | + self::$name = $plugin["name"]; |
| 79 | + assertType('string', self::$name); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * @param mixed[] $plugin |
| 84 | + */ |
| 85 | + public function doFoo(array $plugin){ |
| 86 | + self::$untypedName = $plugin["name"]; |
| 87 | + assertType('mixed', self::$untypedName); |
| 88 | + } |
| 89 | + |
| 90 | + public function doBar(int $i){ |
| 91 | + self::$float = $i; |
| 92 | + assertType('float', self::$float); |
| 93 | + } |
| 94 | + |
| 95 | + public function doBaz(int $i){ |
| 96 | + self::$untypedFloat = $i; |
| 97 | + assertType('int', self::$untypedFloat); |
| 98 | + } |
| 99 | + |
| 100 | + public function doLorem(): void |
| 101 | + { |
| 102 | + self::$a = ['a' => 1]; |
| 103 | + assertType('array{a: 1}', self::$a); |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +class EntryPointLookup |
| 108 | +{ |
| 109 | + |
| 110 | + /** @var array<string, mixed>|null */ |
| 111 | + private ?array $entriesData = null; |
| 112 | + |
| 113 | + /** |
| 114 | + * @return array<string, mixed> |
| 115 | + */ |
| 116 | + public function doFoo(): void |
| 117 | + { |
| 118 | + if ($this->entriesData !== null) { |
| 119 | + return; |
| 120 | + } |
| 121 | + |
| 122 | + assertType('null', $this->entriesData); |
| 123 | + assertNativeType('null', $this->entriesData); |
| 124 | + |
| 125 | + $data = $this->getMixed(); |
| 126 | + if ($data !== null) { |
| 127 | + $this->entriesData = $data; |
| 128 | + assertType('array', $this->entriesData); |
| 129 | + assertNativeType('array', $this->entriesData); |
| 130 | + return; |
| 131 | + } |
| 132 | + |
| 133 | + assertType('null', $this->entriesData); |
| 134 | + assertNativeType('null', $this->entriesData); |
| 135 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * @return mixed |
| 139 | + */ |
| 140 | + public function getMixed() |
| 141 | + { |
| 142 | + |
| 143 | + } |
| 144 | + |
| 145 | +} |
0 commit comments