| Conditions | 147 | 
| Paths | > 20000 | 
| Total Lines | 609 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
| 1 | <?php | ||
| 435 | public static function verifyType( | ||
| 436 | StatementsAnalyzer $statements_analyzer, | ||
| 437 | Type\Union $input_type, | ||
| 438 | Type\Union $param_type, | ||
| 439 | ?Type\Union $signature_param_type, | ||
| 440 | ?string $cased_method_id, | ||
| 441 | int $argument_offset, | ||
| 442 | CodeLocation $arg_location, | ||
| 443 | PhpParser\Node\Expr $input_expr, | ||
| 444 | Context $context, | ||
| 445 | FunctionLikeParameter $function_param, | ||
| 446 | bool $unpack, | ||
| 447 | ?Type\Atomic $unpacked_atomic_array, | ||
| 448 | bool $specialize_taint, | ||
| 449 | bool $in_call_map, | ||
| 450 | CodeLocation $function_call_location | ||
| 451 |     ) { | ||
| 452 | $codebase = $statements_analyzer->getCodebase(); | ||
| 453 | |||
| 454 |         if ($param_type->hasMixed()) { | ||
| 455 | if ($codebase->infer_types_from_usage | ||
| 456 | && !$input_type->hasMixed() | ||
| 457 | && !$param_type->from_docblock | ||
| 458 | && !$param_type->had_template | ||
| 459 | && $cased_method_id | ||
| 460 | && strpos($cased_method_id, '::') | ||
| 461 | && !strpos($cased_method_id, '__') | ||
| 462 |             ) { | ||
| 463 |                 $method_parts = explode('::', $cased_method_id); | ||
| 464 | |||
| 465 | $method_id = new \Psalm\Internal\MethodIdentifier($method_parts[0], strtolower($method_parts[1])); | ||
| 466 | $declaring_method_id = $codebase->methods->getDeclaringMethodId($method_id); | ||
| 467 | |||
| 468 |                 if ($declaring_method_id) { | ||
| 469 | $id_lc = strtolower((string) $declaring_method_id); | ||
| 470 |                     if (!isset($codebase->analyzer->possible_method_param_types[$id_lc][$argument_offset])) { | ||
| 471 | $codebase->analyzer->possible_method_param_types[$id_lc][$argument_offset] | ||
| 472 | = clone $input_type; | ||
| 473 |                     } else { | ||
| 474 | $codebase->analyzer->possible_method_param_types[$id_lc][$argument_offset] | ||
| 475 | = Type::combineUnionTypes( | ||
| 476 | $codebase->analyzer->possible_method_param_types[$id_lc][$argument_offset], | ||
| 477 | clone $input_type, | ||
| 478 | $codebase | ||
| 479 | ); | ||
| 480 | } | ||
| 481 | } | ||
| 482 | } | ||
| 483 | |||
| 484 |             if ($cased_method_id) { | ||
| 485 | self::processTaintedness( | ||
| 486 | $statements_analyzer, | ||
| 487 | $cased_method_id, | ||
| 488 | $argument_offset, | ||
| 489 | $arg_location, | ||
| 490 | $function_call_location, | ||
| 491 | $function_param, | ||
| 492 | $input_type, | ||
| 493 | $input_expr, | ||
| 494 | $context, | ||
| 495 | $specialize_taint | ||
| 496 | ); | ||
| 497 | } | ||
| 498 | |||
| 499 | return null; | ||
| 500 | } | ||
| 501 | |||
| 502 | $method_identifier = $cased_method_id ? ' of ' . $cased_method_id : ''; | ||
| 503 | |||
| 504 |         if ($input_type->hasMixed()) { | ||
| 505 | if (!$context->collect_initializations | ||
| 506 | && !$context->collect_mutations | ||
| 507 | && $statements_analyzer->getFilePath() === $statements_analyzer->getRootFilePath() | ||
| 508 | && (!(($parent_source = $statements_analyzer->getSource()) | ||
| 509 | instanceof \Psalm\Internal\Analyzer\FunctionLikeAnalyzer) | ||
| 510 | || !$parent_source->getSource() instanceof \Psalm\Internal\Analyzer\TraitAnalyzer) | ||
| 511 |             ) { | ||
| 512 | $codebase->analyzer->incrementMixedCount($statements_analyzer->getFilePath()); | ||
| 513 | } | ||
| 514 | |||
| 515 | if (IssueBuffer::accepts( | ||
| 516 | new MixedArgument( | ||
| 517 | 'Argument ' . ($argument_offset + 1) . $method_identifier | ||
| 518 | . ' cannot be ' . $input_type->getId() . ', expecting ' . | ||
| 519 | $param_type, | ||
| 520 | $arg_location, | ||
| 521 | $cased_method_id | ||
| 522 | ), | ||
| 523 | $statements_analyzer->getSuppressedIssues() | ||
| 524 |             )) { | ||
| 525 | // fall through | ||
| 526 | } | ||
| 527 | |||
| 528 |             if ($input_type->isMixed()) { | ||
| 529 | if (!$function_param->by_ref | ||
| 530 | && !($function_param->is_variadic xor $unpack) | ||
| 531 | && $cased_method_id !== 'echo' | ||
| 532 | && $cased_method_id !== 'print' | ||
| 533 | && (!$in_call_map || $context->strict_types) | ||
| 534 |                 ) { | ||
| 535 | self::coerceValueAfterGatekeeperArgument( | ||
| 536 | $statements_analyzer, | ||
| 537 | $input_type, | ||
| 538 | false, | ||
| 539 | $input_expr, | ||
| 540 | $param_type, | ||
| 541 | $signature_param_type, | ||
| 542 | $context, | ||
| 543 | $unpack, | ||
| 544 | $unpacked_atomic_array | ||
| 545 | ); | ||
| 546 | } | ||
| 547 | } | ||
| 548 | |||
| 549 |             if ($cased_method_id) { | ||
| 550 | $input_type = self::processTaintedness( | ||
| 551 | $statements_analyzer, | ||
| 552 | $cased_method_id, | ||
| 553 | $argument_offset, | ||
| 554 | $arg_location, | ||
| 555 | $function_call_location, | ||
| 556 | $function_param, | ||
| 557 | $input_type, | ||
| 558 | $input_expr, | ||
| 559 | $context, | ||
| 560 | $specialize_taint | ||
| 561 | ); | ||
| 562 | } | ||
| 563 | |||
| 564 |             if ($input_type->isMixed()) { | ||
| 565 | return null; | ||
| 566 | } | ||
| 567 | } | ||
| 568 | |||
| 569 |         if ($input_type->isNever()) { | ||
| 570 | if (IssueBuffer::accepts( | ||
| 571 | new NoValue( | ||
| 572 | 'This function or method call never returns output', | ||
| 573 | $arg_location | ||
| 574 | ), | ||
| 575 | $statements_analyzer->getSuppressedIssues() | ||
| 576 |             )) { | ||
| 577 | // fall through | ||
| 578 | } | ||
| 579 | |||
| 580 | return null; | ||
| 581 | } | ||
| 582 | |||
| 583 | if (!$context->collect_initializations | ||
| 584 | && !$context->collect_mutations | ||
| 585 | && $statements_analyzer->getFilePath() === $statements_analyzer->getRootFilePath() | ||
| 586 | && (!(($parent_source = $statements_analyzer->getSource()) | ||
| 587 | instanceof \Psalm\Internal\Analyzer\FunctionLikeAnalyzer) | ||
| 588 | || !$parent_source->getSource() instanceof \Psalm\Internal\Analyzer\TraitAnalyzer) | ||
| 589 |         ) { | ||
| 590 | $codebase->analyzer->incrementNonMixedCount($statements_analyzer->getFilePath()); | ||
| 591 | } | ||
| 592 | |||
| 593 |         if ($function_param->by_ref) { | ||
| 594 | $param_type->possibly_undefined = true; | ||
| 595 | } | ||
| 596 | |||
| 597 | if ($param_type->hasCallableType() | ||
| 598 | && $param_type->isSingle() | ||
| 599 | && $input_type->isSingleStringLiteral() | ||
| 600 | && !\Psalm\Internal\Codebase\InternalCallMapHandler::inCallMap($input_type->getSingleStringLiteral()->value) | ||
| 601 |         ) { | ||
| 602 |             foreach ($input_type->getAtomicTypes() as $key => $atomic_type) { | ||
| 603 | $candidate_callable = TypeAnalyzer::getCallableFromAtomic( | ||
| 604 | $codebase, | ||
| 605 | $atomic_type, | ||
| 606 | null, | ||
| 607 | $statements_analyzer | ||
| 608 | ); | ||
| 609 | |||
| 610 |                 if ($candidate_callable) { | ||
| 611 | $input_type->removeType($key); | ||
| 612 | $input_type->addType($candidate_callable); | ||
| 613 | } | ||
| 614 | } | ||
| 615 | } | ||
| 616 | |||
| 617 | $union_comparison_results = new \Psalm\Internal\Analyzer\TypeComparisonResult(); | ||
| 618 | |||
| 619 | $type_match_found = TypeAnalyzer::isContainedBy( | ||
| 620 | $codebase, | ||
| 621 | $input_type, | ||
| 622 | $param_type, | ||
| 623 | true, | ||
| 624 | true, | ||
| 625 | $union_comparison_results | ||
| 626 | ); | ||
| 627 | |||
| 628 | $replace_input_type = false; | ||
| 629 | |||
| 630 |         if ($union_comparison_results->replacement_union_type) { | ||
| 631 | $replace_input_type = true; | ||
| 632 | $input_type = $union_comparison_results->replacement_union_type; | ||
| 633 | } | ||
| 634 | |||
| 635 |         if ($cased_method_id) { | ||
| 636 | $old_input_type = $input_type; | ||
| 637 | |||
| 638 | $input_type = self::processTaintedness( | ||
| 639 | $statements_analyzer, | ||
| 640 | $cased_method_id, | ||
| 641 | $argument_offset, | ||
| 642 | $arg_location, | ||
| 643 | $function_call_location, | ||
| 644 | $function_param, | ||
| 645 | $input_type, | ||
| 646 | $input_expr, | ||
| 647 | $context, | ||
| 648 | $specialize_taint | ||
| 649 | ); | ||
| 650 | |||
| 651 |             if ($old_input_type !== $input_type) { | ||
| 652 | $replace_input_type = true; | ||
| 653 | } | ||
| 654 | } | ||
| 655 | |||
| 656 | if ($type_match_found | ||
| 657 | && $param_type->hasCallableType() | ||
| 658 |         ) { | ||
| 659 | $potential_method_ids = []; | ||
| 660 | |||
| 661 |             foreach ($input_type->getAtomicTypes() as $input_type_part) { | ||
| 662 |                 if ($input_type_part instanceof Type\Atomic\ObjectLike) { | ||
| 663 | $potential_method_id = TypeAnalyzer::getCallableMethodIdFromObjectLike( | ||
| 664 | $input_type_part, | ||
| 665 | $codebase, | ||
| 666 | $context->calling_method_id, | ||
| 667 | $statements_analyzer->getFilePath() | ||
| 668 | ); | ||
| 669 | |||
| 670 |                     if ($potential_method_id && $potential_method_id !== 'not-callable') { | ||
| 671 | $potential_method_ids[] = $potential_method_id; | ||
| 672 | } | ||
| 673 | } elseif ($input_type_part instanceof Type\Atomic\TLiteralString | ||
| 674 | && strpos($input_type_part->value, '::') | ||
| 675 |                 ) { | ||
| 676 |                     $parts = explode('::', $input_type_part->value); | ||
| 677 | $potential_method_ids[] = new \Psalm\Internal\MethodIdentifier( | ||
| 678 | $parts[0], | ||
| 679 | strtolower($parts[1]) | ||
| 680 | ); | ||
| 681 | } | ||
| 682 | } | ||
| 683 | |||
| 684 |             foreach ($potential_method_ids as $potential_method_id) { | ||
| 685 | $codebase->methods->methodExists( | ||
| 686 | $potential_method_id, | ||
| 687 | $context->calling_method_id, | ||
| 688 | null, | ||
| 689 | $statements_analyzer, | ||
| 690 | $statements_analyzer->getFilePath() | ||
| 691 | ); | ||
| 692 | } | ||
| 693 | } | ||
| 694 | |||
| 695 | if ($context->strict_types | ||
| 696 | && !$input_type->hasArray() | ||
| 697 | && !$param_type->from_docblock | ||
| 698 | && $cased_method_id !== 'echo' | ||
| 699 | && $cased_method_id !== 'print' | ||
| 700 | && $cased_method_id !== 'sprintf' | ||
| 701 |         ) { | ||
| 702 | $union_comparison_results->scalar_type_match_found = false; | ||
| 703 | |||
| 704 |             if ($union_comparison_results->to_string_cast) { | ||
| 705 | $union_comparison_results->to_string_cast = false; | ||
| 706 | $type_match_found = false; | ||
| 707 | } | ||
| 708 | } | ||
| 709 | |||
| 710 |         if ($union_comparison_results->type_coerced && !$input_type->hasMixed()) { | ||
| 711 |             if ($union_comparison_results->type_coerced_from_mixed) { | ||
| 712 | if (IssueBuffer::accepts( | ||
| 713 | new MixedArgumentTypeCoercion( | ||
| 714 | 'Argument ' . ($argument_offset + 1) . $method_identifier . ' expects ' . $param_type->getId() . | ||
| 715 | ', parent type ' . $input_type->getId() . ' provided', | ||
| 716 | $arg_location, | ||
| 717 | $cased_method_id | ||
| 718 | ), | ||
| 719 | $statements_analyzer->getSuppressedIssues() | ||
| 720 |                 )) { | ||
| 721 | // keep soldiering on | ||
| 722 | } | ||
| 723 |             } else { | ||
| 724 | if (IssueBuffer::accepts( | ||
| 725 | new ArgumentTypeCoercion( | ||
| 726 | 'Argument ' . ($argument_offset + 1) . $method_identifier . ' expects ' . $param_type->getId() . | ||
| 727 | ', parent type ' . $input_type->getId() . ' provided', | ||
| 728 | $arg_location, | ||
| 729 | $cased_method_id | ||
| 730 | ), | ||
| 731 | $statements_analyzer->getSuppressedIssues() | ||
| 732 |                 )) { | ||
| 733 | // keep soldiering on | ||
| 734 | } | ||
| 735 | } | ||
| 736 | } | ||
| 737 | |||
| 738 |         if ($union_comparison_results->to_string_cast && $cased_method_id !== 'echo' && $cased_method_id !== 'print') { | ||
| 739 | if (IssueBuffer::accepts( | ||
| 740 | new ImplicitToStringCast( | ||
| 741 | 'Argument ' . ($argument_offset + 1) . $method_identifier . ' expects ' . | ||
| 742 | $param_type->getId() . ', ' . $input_type->getId() . ' provided with a __toString method', | ||
| 743 | $arg_location | ||
| 744 | ), | ||
| 745 | $statements_analyzer->getSuppressedIssues() | ||
| 746 |             )) { | ||
| 747 | // fall through | ||
| 748 | } | ||
| 749 | } | ||
| 750 | |||
| 751 |         if (!$type_match_found && !$union_comparison_results->type_coerced) { | ||
| 752 | $types_can_be_identical = TypeAnalyzer::canBeContainedBy( | ||
| 753 | $codebase, | ||
| 754 | $input_type, | ||
| 755 | $param_type, | ||
| 756 | true, | ||
| 757 | true | ||
| 758 | ); | ||
| 759 | |||
| 760 |             if ($union_comparison_results->scalar_type_match_found) { | ||
| 761 |                 if ($cased_method_id !== 'echo' && $cased_method_id !== 'print') { | ||
| 762 | if (IssueBuffer::accepts( | ||
| 763 | new InvalidScalarArgument( | ||
| 764 | 'Argument ' . ($argument_offset + 1) . $method_identifier . ' expects ' . | ||
| 765 | $param_type->getId() . ', ' . $input_type->getId() . ' provided', | ||
| 766 | $arg_location, | ||
| 767 | $cased_method_id | ||
| 768 | ), | ||
| 769 | $statements_analyzer->getSuppressedIssues() | ||
| 770 |                     )) { | ||
| 771 | // fall through | ||
| 772 | } | ||
| 773 | } | ||
| 774 |             } elseif ($types_can_be_identical) { | ||
| 775 | if (IssueBuffer::accepts( | ||
| 776 | new PossiblyInvalidArgument( | ||
| 777 | 'Argument ' . ($argument_offset + 1) . $method_identifier . ' expects ' . $param_type->getId() . | ||
| 778 | ', possibly different type ' . $input_type->getId() . ' provided', | ||
| 779 | $arg_location, | ||
| 780 | $cased_method_id | ||
| 781 | ), | ||
| 782 | $statements_analyzer->getSuppressedIssues() | ||
| 783 |                 )) { | ||
| 784 | // fall through | ||
| 785 | } | ||
| 786 |             } else { | ||
| 787 | if (IssueBuffer::accepts( | ||
| 788 | new InvalidArgument( | ||
| 789 | 'Argument ' . ($argument_offset + 1) . $method_identifier . ' expects ' . $param_type->getId() . | ||
| 790 | ', ' . $input_type->getId() . ' provided', | ||
| 791 | $arg_location, | ||
| 792 | $cased_method_id | ||
| 793 | ), | ||
| 794 | $statements_analyzer->getSuppressedIssues() | ||
| 795 |                 )) { | ||
| 796 | // fall through | ||
| 797 | } | ||
| 798 | } | ||
| 799 | |||
| 800 | return; | ||
| 801 | } | ||
| 802 | |||
| 803 | if ($input_expr instanceof PhpParser\Node\Scalar\String_ | ||
| 804 | || $input_expr instanceof PhpParser\Node\Expr\Array_ | ||
| 805 | || $input_expr instanceof PhpParser\Node\Expr\BinaryOp\Concat | ||
| 806 |         ) { | ||
| 807 |             foreach ($param_type->getAtomicTypes() as $param_type_part) { | ||
| 808 | if ($param_type_part instanceof TClassString | ||
| 809 | && $input_expr instanceof PhpParser\Node\Scalar\String_ | ||
| 810 | && !$param_type->getLiteralStrings() | ||
| 811 |                 ) { | ||
| 812 | if (ClassLikeAnalyzer::checkFullyQualifiedClassLikeName( | ||
| 813 | $statements_analyzer, | ||
| 814 | $input_expr->value, | ||
| 815 | $arg_location, | ||
| 816 | $context->self, | ||
| 817 | $context->calling_method_id, | ||
| 818 | $statements_analyzer->getSuppressedIssues() | ||
| 819 | ) === false | ||
| 820 |                     ) { | ||
| 821 | return; | ||
| 822 | } | ||
| 823 | } elseif ($param_type_part instanceof TArray | ||
| 824 | && $input_expr instanceof PhpParser\Node\Expr\Array_ | ||
| 825 |                 ) { | ||
| 826 |                     foreach ($param_type_part->type_params[1]->getAtomicTypes() as $param_array_type_part) { | ||
| 827 |                         if ($param_array_type_part instanceof TClassString) { | ||
| 828 |                             foreach ($input_expr->items as $item) { | ||
| 829 |                                 if ($item && $item->value instanceof PhpParser\Node\Scalar\String_) { | ||
| 830 | if (ClassLikeAnalyzer::checkFullyQualifiedClassLikeName( | ||
| 831 | $statements_analyzer, | ||
| 832 | $item->value->value, | ||
| 833 | $arg_location, | ||
| 834 | $context->self, | ||
| 835 | $context->calling_method_id, | ||
| 836 | $statements_analyzer->getSuppressedIssues() | ||
| 837 | ) === false | ||
| 838 |                                     ) { | ||
| 839 | return; | ||
| 840 | } | ||
| 841 | } | ||
| 842 | } | ||
| 843 | } | ||
| 844 | } | ||
| 845 |                 } elseif ($param_type_part instanceof TCallable) { | ||
| 846 | $can_be_callable_like_array = false; | ||
| 847 |                     if ($param_type->hasArray()) { | ||
| 848 | /** | ||
| 849 | * @psalm-suppress PossiblyUndefinedStringArrayOffset | ||
| 850 | */ | ||
| 851 | $param_array_type = $param_type->getAtomicTypes()['array']; | ||
| 852 | |||
| 853 | $row_type = null; | ||
| 854 |                         if ($param_array_type instanceof TList) { | ||
| 855 | $row_type = $param_array_type->type_param; | ||
| 856 |                         } elseif ($param_array_type instanceof TArray) { | ||
| 857 | $row_type = $param_array_type->type_params[1]; | ||
| 858 |                         } elseif ($param_array_type instanceof Type\Atomic\ObjectLike) { | ||
| 859 | $row_type = $param_array_type->getGenericArrayType()->type_params[1]; | ||
| 860 | } | ||
| 861 | |||
| 862 | if ($row_type && | ||
| 863 | ($row_type->hasMixed() || $row_type->hasString()) | ||
| 864 |                         ) { | ||
| 865 | $can_be_callable_like_array = true; | ||
| 866 | } | ||
| 867 | } | ||
| 868 | |||
| 869 |                     if (!$can_be_callable_like_array) { | ||
| 870 | $function_ids = CallAnalyzer::getFunctionIdsFromCallableArg( | ||
| 871 | $statements_analyzer, | ||
| 872 | $input_expr | ||
| 873 | ); | ||
| 874 | |||
| 875 |                         foreach ($function_ids as $function_id) { | ||
| 876 |                             if (strpos($function_id, '::') !== false) { | ||
| 877 |                                 if ($function_id[0] === '$') { | ||
| 878 | $function_id = \substr($function_id, 1); | ||
| 879 | } | ||
| 880 | |||
| 881 |                                 $function_id_parts = explode('&', $function_id); | ||
| 882 | |||
| 883 | $non_existent_method_ids = []; | ||
| 884 | $has_valid_method = false; | ||
| 885 | |||
| 886 |                                 foreach ($function_id_parts as $function_id_part) { | ||
| 887 |                                     list($callable_fq_class_name, $method_name) = explode('::', $function_id_part); | ||
| 888 | |||
| 889 |                                     switch ($callable_fq_class_name) { | ||
| 890 | case 'self': | ||
| 891 | case 'static': | ||
| 892 | case 'parent': | ||
| 893 | $container_class = $statements_analyzer->getFQCLN(); | ||
| 894 | |||
| 895 |                                             if ($callable_fq_class_name === 'parent') { | ||
| 896 | $container_class = $statements_analyzer->getParentFQCLN(); | ||
| 897 | } | ||
| 898 | |||
| 899 |                                             if (!$container_class) { | ||
| 900 | continue 2; | ||
| 901 | } | ||
| 902 | |||
| 903 | $callable_fq_class_name = $container_class; | ||
| 904 | } | ||
| 905 | |||
| 906 | if (ClassLikeAnalyzer::checkFullyQualifiedClassLikeName( | ||
| 907 | $statements_analyzer, | ||
| 908 | $callable_fq_class_name, | ||
| 909 | $arg_location, | ||
| 910 | $context->self, | ||
| 911 | $context->calling_method_id, | ||
| 912 | $statements_analyzer->getSuppressedIssues() | ||
| 913 | ) === false | ||
| 914 |                                     ) { | ||
| 915 | return; | ||
| 916 | } | ||
| 917 | |||
| 918 | $function_id_part = new \Psalm\Internal\MethodIdentifier( | ||
| 919 | $callable_fq_class_name, | ||
| 920 | strtolower($method_name) | ||
| 921 | ); | ||
| 922 | |||
| 923 | $call_method_id = new \Psalm\Internal\MethodIdentifier( | ||
| 924 | $callable_fq_class_name, | ||
| 925 | '__call' | ||
| 926 | ); | ||
| 927 | |||
| 928 |                                     if (!$codebase->classOrInterfaceExists($callable_fq_class_name)) { | ||
| 929 | return; | ||
| 930 | } | ||
| 931 | |||
| 932 | if (!$codebase->methods->methodExists($function_id_part) | ||
| 933 | && !$codebase->methods->methodExists($call_method_id) | ||
| 934 |                                     ) { | ||
| 935 | $non_existent_method_ids[] = $function_id_part; | ||
| 936 |                                     } else { | ||
| 937 | $has_valid_method = true; | ||
| 938 | } | ||
| 939 | } | ||
| 940 | |||
| 941 |                                 if (!$has_valid_method && !$param_type->hasString() && !$param_type->hasArray()) { | ||
| 942 | if (MethodAnalyzer::checkMethodExists( | ||
| 943 | $codebase, | ||
| 944 | $non_existent_method_ids[0], | ||
| 945 | $arg_location, | ||
| 946 | $statements_analyzer->getSuppressedIssues() | ||
| 947 | ) === false | ||
| 948 |                                     ) { | ||
| 949 | return; | ||
| 950 | } | ||
| 951 | } | ||
| 952 |                             } else { | ||
| 953 | if (!$param_type->hasString() | ||
| 954 | && !$param_type->hasArray() | ||
| 955 | && CallAnalyzer::checkFunctionExists( | ||
| 956 | $statements_analyzer, | ||
| 957 | $function_id, | ||
| 958 | $arg_location, | ||
| 959 | false | ||
| 960 | ) === false | ||
| 961 |                                 ) { | ||
| 962 | return; | ||
| 963 | } | ||
| 964 | } | ||
| 965 | } | ||
| 966 | } | ||
| 967 | } | ||
| 968 | } | ||
| 969 | } | ||
| 970 | |||
| 971 |         if (!$param_type->isNullable() && $cased_method_id !== 'echo' && $cased_method_id !== 'print') { | ||
| 972 |             if ($input_type->isNull()) { | ||
| 973 | if (IssueBuffer::accepts( | ||
| 974 | new NullArgument( | ||
| 975 | 'Argument ' . ($argument_offset + 1) . $method_identifier . ' cannot be null, ' . | ||
| 976 | 'null value provided to parameter with type ' . $param_type->getId(), | ||
| 977 | $arg_location, | ||
| 978 | $cased_method_id | ||
| 979 | ), | ||
| 980 | $statements_analyzer->getSuppressedIssues() | ||
| 981 |                 )) { | ||
| 982 | // fall through | ||
| 983 | } | ||
| 984 | |||
| 985 | return null; | ||
| 986 | } | ||
| 987 | |||
| 988 |             if ($input_type->isNullable() && !$input_type->ignore_nullable_issues) { | ||
| 989 | if (IssueBuffer::accepts( | ||
| 990 | new PossiblyNullArgument( | ||
| 991 | 'Argument ' . ($argument_offset + 1) . $method_identifier . ' cannot be null, possibly ' . | ||
| 992 | 'null value provided', | ||
| 993 | $arg_location, | ||
| 994 | $cased_method_id | ||
| 995 | ), | ||
| 996 | $statements_analyzer->getSuppressedIssues() | ||
| 997 |                 )) { | ||
| 998 | // fall through | ||
| 999 | } | ||
| 1000 | } | ||
| 1001 | } | ||
| 1002 | |||
| 1003 | if ($input_type->isFalsable() | ||
| 1004 | && !$param_type->hasBool() | ||
| 1005 | && !$param_type->hasScalar() | ||
| 1006 | && !$input_type->ignore_falsable_issues | ||
| 1007 | && $cased_method_id !== 'echo' | ||
| 1008 |         ) { | ||
| 1009 | if (IssueBuffer::accepts( | ||
| 1010 | new PossiblyFalseArgument( | ||
| 1011 | 'Argument ' . ($argument_offset + 1) . $method_identifier . ' cannot be false, possibly ' . | ||
| 1012 | 'false value provided', | ||
| 1013 | $arg_location, | ||
| 1014 | $cased_method_id | ||
| 1015 | ), | ||
| 1016 | $statements_analyzer->getSuppressedIssues() | ||
| 1017 |             )) { | ||
| 1018 | // fall through | ||
| 1019 | } | ||
| 1020 | } | ||
| 1021 | |||
| 1022 | if (($type_match_found || $input_type->hasMixed()) | ||
| 1023 | && !$function_param->by_ref | ||
| 1024 | && !($function_param->is_variadic xor $unpack) | ||
| 1025 | && $cased_method_id !== 'echo' | ||
| 1026 | && $cased_method_id !== 'print' | ||
| 1027 | && (!$in_call_map || $context->strict_types) | ||
| 1028 |         ) { | ||
| 1029 | self::coerceValueAfterGatekeeperArgument( | ||
| 1030 | $statements_analyzer, | ||
| 1031 | $input_type, | ||
| 1032 | $replace_input_type, | ||
| 1033 | $input_expr, | ||
| 1034 | $param_type, | ||
| 1035 | $signature_param_type, | ||
| 1036 | $context, | ||
| 1037 | $unpack, | ||
| 1038 | $unpacked_atomic_array | ||
| 1039 | ); | ||
| 1040 | } | ||
| 1041 | |||
| 1042 | return null; | ||
| 1043 | } | ||
| 1044 | |||
| 1300 | 
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.