|
40 | 40 | use PHPStan\Type\Traits\NonRemoveableTypeTrait; |
41 | 41 | use PHPStan\Type\Traits\TruthyBooleanTypeTrait; |
42 | 42 | use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait; |
| 43 | +use function array_key_exists; |
43 | 44 | use function array_map; |
44 | 45 | use function array_merge; |
45 | 46 | use function count; |
@@ -218,7 +219,100 @@ public function equals(Type $type): bool |
218 | 219 | return false; |
219 | 220 | } |
220 | 221 |
|
221 | | - return $this->describe(VerbosityLevel::precise()) === $type->describe(VerbosityLevel::precise()); |
| 222 | + if ($this->isCommonCallable) { |
| 223 | + if (!$type->isCommonCallable) { |
| 224 | + return false; |
| 225 | + } |
| 226 | + } elseif ($type->isCommonCallable) { |
| 227 | + return false; |
| 228 | + } |
| 229 | + |
| 230 | + if ($this->variadic !== $type->variadic) { |
| 231 | + return false; |
| 232 | + } |
| 233 | + |
| 234 | + if ($this->isPure !== $type->isPure) { |
| 235 | + return false; |
| 236 | + } |
| 237 | + |
| 238 | + if (!$this->returnType->equals($type->returnType)) { |
| 239 | + return false; |
| 240 | + } |
| 241 | + |
| 242 | + if (count($this->parameters) !== count($type->parameters)) { |
| 243 | + return false; |
| 244 | + } |
| 245 | + |
| 246 | + foreach ($this->parameters as $i => $parameter) { |
| 247 | + $otherParameter = $type->parameters[$i]; |
| 248 | + if ($parameter->isOptional() !== $otherParameter->isOptional()) { |
| 249 | + return false; |
| 250 | + } |
| 251 | + if (!$parameter->passedByReference()->equals($otherParameter->passedByReference())) { |
| 252 | + return false; |
| 253 | + } |
| 254 | + if ($parameter->isVariadic() !== $otherParameter->isVariadic()) { |
| 255 | + return false; |
| 256 | + } |
| 257 | + if (!$parameter->getType()->equals($otherParameter->getType())) { |
| 258 | + return false; |
| 259 | + } |
| 260 | + if ($parameter->getDefaultValue() !== null) { |
| 261 | + if ($otherParameter->getDefaultValue() === null) { |
| 262 | + return false; |
| 263 | + } |
| 264 | + |
| 265 | + return $parameter->getDefaultValue()->equals($otherParameter->getDefaultValue()); |
| 266 | + } elseif ($otherParameter->getDefaultValue() !== null) { |
| 267 | + return false; |
| 268 | + } |
| 269 | + } |
| 270 | + |
| 271 | + foreach ([[$this->templateTypeMap, $type->templateTypeMap], [$this->resolvedTemplateTypeMap, $type->resolvedTemplateTypeMap]] as [$templateTypeMap, $otherTemplateTypeMap]) { |
| 272 | + if ($templateTypeMap->count() !== $otherTemplateTypeMap->count()) { |
| 273 | + return false; |
| 274 | + } |
| 275 | + |
| 276 | + foreach ($templateTypeMap->getTypes() as $typeName => $templateType) { |
| 277 | + $otherTemplateType = $otherTemplateTypeMap->getType($typeName); |
| 278 | + if ($otherTemplateType === null) { |
| 279 | + return false; |
| 280 | + } |
| 281 | + |
| 282 | + if (!$templateType->equals($otherTemplateType)) { |
| 283 | + return false; |
| 284 | + } |
| 285 | + } |
| 286 | + } |
| 287 | + |
| 288 | + foreach ($this->templateTags as $tagName => $tag) { |
| 289 | + if (!array_key_exists($tagName, $type->templateTags)) { |
| 290 | + return false; |
| 291 | + } |
| 292 | + |
| 293 | + $otherTag = $type->templateTags[$tagName]; |
| 294 | + if ($tag->getName() !== $otherTag->getName()) { |
| 295 | + return false; |
| 296 | + } |
| 297 | + |
| 298 | + if (!$tag->getBound()->equals($otherTag->getBound())) { |
| 299 | + return false; |
| 300 | + } |
| 301 | + if (!$tag->getVariance()->equals($otherTag->getVariance())) { |
| 302 | + return false; |
| 303 | + } |
| 304 | + if ($tag->getDefault() !== null) { |
| 305 | + if ($otherTag->getDefault() === null) { |
| 306 | + return false; |
| 307 | + } |
| 308 | + |
| 309 | + return $tag->getDefault()->equals($otherTag->getDefault()); |
| 310 | + } elseif ($otherTag->getDefault() !== null) { |
| 311 | + return false; |
| 312 | + } |
| 313 | + } |
| 314 | + |
| 315 | + return true; |
222 | 316 | } |
223 | 317 |
|
224 | 318 | public function describe(VerbosityLevel $level): string |
|
0 commit comments