Conditions | 184 |
Paths | > 20000 |
Total Lines | 671 |
Lines | 178 |
Ratio | 26.53 % |
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:
1 | <?php |
||
608 | private static function scrapeTypeProperties( |
||
609 | Atomic $type, |
||
610 | TypeCombination $combination, |
||
611 | $codebase, |
||
612 | bool $overwrite_empty_array, |
||
613 | bool $allow_mixed_union, |
||
614 | int $literal_limit |
||
615 | ) { |
||
616 | if ($type instanceof TMixed) { |
||
617 | $combination->has_mixed = true; |
||
618 | if ($type->from_loop_isset) { |
||
619 | if ($combination->mixed_from_loop_isset === null) { |
||
620 | $combination->mixed_from_loop_isset = true; |
||
621 | } else { |
||
622 | return null; |
||
623 | } |
||
624 | } else { |
||
625 | $combination->mixed_from_loop_isset = false; |
||
626 | } |
||
627 | |||
628 | if ($type instanceof TNonEmptyMixed) { |
||
629 | $combination->non_empty_mixed = true; |
||
630 | |||
631 | if ($combination->empty_mixed) { |
||
632 | return null; |
||
633 | } |
||
634 | } elseif ($type instanceof TEmptyMixed) { |
||
635 | $combination->empty_mixed = true; |
||
636 | |||
637 | if ($combination->non_empty_mixed) { |
||
638 | return null; |
||
639 | } |
||
640 | } else { |
||
641 | $combination->empty_mixed = true; |
||
642 | $combination->non_empty_mixed = true; |
||
643 | } |
||
644 | |||
645 | if (!$allow_mixed_union) { |
||
646 | return Type::getMixed((bool) $combination->mixed_from_loop_isset); |
||
647 | } |
||
648 | } |
||
649 | |||
650 | // deal with false|bool => bool |
||
651 | if (($type instanceof TFalse || $type instanceof TTrue) && isset($combination->value_types['bool'])) { |
||
652 | return null; |
||
653 | } |
||
654 | |||
655 | View Code Duplication | if (get_class($type) === TBool::class && isset($combination->value_types['false'])) { |
|
656 | unset($combination->value_types['false']); |
||
657 | } |
||
658 | |||
659 | View Code Duplication | if (get_class($type) === TBool::class && isset($combination->value_types['true'])) { |
|
660 | unset($combination->value_types['true']); |
||
661 | } |
||
662 | |||
663 | if ($type instanceof TArray && isset($combination->builtin_type_params['iterable'])) { |
||
664 | $type_key = 'iterable'; |
||
665 | } elseif ($type instanceof TArray |
||
666 | && $type->type_params[1]->isMixed() |
||
667 | && isset($combination->value_types['iterable']) |
||
668 | ) { |
||
669 | $type_key = 'iterable'; |
||
670 | $combination->builtin_type_params['iterable'] = [Type::getMixed(), Type::getMixed()]; |
||
671 | } elseif ($type instanceof TNamedObject |
||
672 | && $type->value === 'Traversable' |
||
673 | && (isset($combination->builtin_type_params['iterable']) || isset($combination->value_types['iterable'])) |
||
674 | ) { |
||
675 | $type_key = 'iterable'; |
||
676 | |||
677 | if (!isset($combination->builtin_type_params['iterable'])) { |
||
678 | $combination->builtin_type_params['iterable'] = [Type::getMixed(), Type::getMixed()]; |
||
679 | } |
||
680 | |||
681 | if (!$type instanceof TGenericObject) { |
||
682 | $type = new TGenericObject($type->value, [Type::getMixed(), Type::getMixed()]); |
||
683 | } |
||
684 | } elseif ($type instanceof TNamedObject && ($type->value === 'Traversable' || $type->value === 'Generator')) { |
||
685 | $type_key = $type->value; |
||
686 | } else { |
||
687 | $type_key = $type->getKey(); |
||
688 | } |
||
689 | |||
690 | if ($type instanceof TIterable |
||
691 | && $combination->array_type_params |
||
692 | && ($type->has_docblock_params || $combination->array_type_params[1]->isMixed()) |
||
693 | ) { |
||
694 | if (!isset($combination->builtin_type_params['iterable'])) { |
||
695 | $combination->builtin_type_params['iterable'] = $combination->array_type_params; |
||
696 | } else { |
||
697 | View Code Duplication | foreach ($combination->array_type_params as $i => $array_type_param) { |
|
698 | $iterable_type_param = $combination->builtin_type_params['iterable'][$i]; |
||
699 | $combination->builtin_type_params['iterable'][$i] = Type::combineUnionTypes( |
||
700 | $iterable_type_param, |
||
701 | $array_type_param |
||
702 | ); |
||
703 | } |
||
704 | } |
||
705 | |||
706 | $combination->array_type_params = []; |
||
707 | } |
||
708 | |||
709 | if ($type instanceof TIterable |
||
710 | && (isset($combination->named_object_types['Traversable']) |
||
711 | || isset($combination->builtin_type_params['Traversable'])) |
||
712 | ) { |
||
713 | if (!isset($combination->builtin_type_params['iterable'])) { |
||
714 | $combination->builtin_type_params['iterable'] |
||
715 | = $combination->builtin_type_params['Traversable'] ?? [Type::getMixed(), Type::getMixed()]; |
||
716 | } elseif (isset($combination->builtin_type_params['Traversable'])) { |
||
717 | View Code Duplication | foreach ($combination->builtin_type_params['Traversable'] as $i => $array_type_param) { |
|
718 | $iterable_type_param = $combination->builtin_type_params['iterable'][$i]; |
||
719 | $combination->builtin_type_params['iterable'][$i] = Type::combineUnionTypes( |
||
720 | $iterable_type_param, |
||
721 | $array_type_param |
||
722 | ); |
||
723 | } |
||
724 | } else { |
||
725 | $combination->builtin_type_params['iterable'] = [Type::getMixed(), Type::getMixed()]; |
||
726 | } |
||
727 | |||
728 | /** @psalm-suppress PossiblyNullArrayAccess */ |
||
729 | unset( |
||
730 | $combination->named_object_types['Traversable'], |
||
731 | $combination->builtin_type_params['Traversable'] |
||
732 | ); |
||
733 | } |
||
734 | |||
735 | if ($type instanceof TNamedObject |
||
736 | || $type instanceof TTemplateParam |
||
737 | || $type instanceof TIterable |
||
738 | || $type instanceof Type\Atomic\TObjectWithProperties |
||
739 | ) { |
||
740 | if ($type->extra_types) { |
||
741 | $combination->extra_types = array_merge( |
||
742 | $combination->extra_types ?: [], |
||
743 | $type->extra_types |
||
744 | ); |
||
745 | } |
||
746 | } |
||
747 | |||
748 | if ($type instanceof TArray && $type_key === 'array') { |
||
749 | if ($type instanceof TCallableArray && isset($combination->value_types['callable'])) { |
||
750 | return; |
||
751 | } |
||
752 | |||
753 | View Code Duplication | foreach ($type->type_params as $i => $type_param) { |
|
754 | if (isset($combination->array_type_params[$i])) { |
||
755 | $combination->array_type_params[$i] = Type::combineUnionTypes( |
||
756 | $combination->array_type_params[$i], |
||
757 | $type_param, |
||
758 | $codebase, |
||
759 | $overwrite_empty_array |
||
760 | ); |
||
761 | } else { |
||
762 | $combination->array_type_params[$i] = $type_param; |
||
763 | } |
||
764 | } |
||
765 | |||
766 | View Code Duplication | if ($type instanceof TNonEmptyArray) { |
|
767 | if ($combination->array_counts !== null) { |
||
768 | if ($type->count === null) { |
||
769 | $combination->array_counts = null; |
||
770 | } else { |
||
771 | $combination->array_counts[$type->count] = true; |
||
772 | } |
||
773 | } |
||
774 | |||
775 | $combination->array_sometimes_filled = true; |
||
776 | } else { |
||
777 | $combination->array_always_filled = false; |
||
778 | } |
||
779 | |||
780 | if (!$type->type_params[1]->isEmpty()) { |
||
781 | $combination->all_arrays_lists = false; |
||
782 | $combination->all_arrays_class_string_maps = false; |
||
783 | } |
||
784 | |||
785 | View Code Duplication | if ($type instanceof TCallableArray) { |
|
786 | if ($combination->all_arrays_callable !== false) { |
||
787 | $combination->all_arrays_callable = true; |
||
788 | } |
||
789 | } else { |
||
790 | $combination->all_arrays_callable = false; |
||
791 | } |
||
792 | |||
793 | return null; |
||
794 | } |
||
795 | |||
796 | if ($type instanceof TList) { |
||
797 | View Code Duplication | foreach ([Type::getInt(), $type->type_param] as $i => $type_param) { |
|
798 | if (isset($combination->array_type_params[$i])) { |
||
799 | $combination->array_type_params[$i] = Type::combineUnionTypes( |
||
800 | $combination->array_type_params[$i], |
||
801 | $type_param, |
||
802 | $codebase, |
||
803 | $overwrite_empty_array |
||
804 | ); |
||
805 | } else { |
||
806 | $combination->array_type_params[$i] = $type_param; |
||
807 | } |
||
808 | } |
||
809 | |||
810 | View Code Duplication | if ($type instanceof TNonEmptyList) { |
|
811 | if ($combination->array_counts !== null) { |
||
812 | if ($type->count === null) { |
||
813 | $combination->array_counts = null; |
||
814 | } else { |
||
815 | $combination->array_counts[$type->count] = true; |
||
816 | } |
||
817 | } |
||
818 | |||
819 | $combination->array_sometimes_filled = true; |
||
820 | } else { |
||
821 | $combination->array_always_filled = false; |
||
822 | } |
||
823 | |||
824 | if ($combination->all_arrays_lists !== false) { |
||
825 | $combination->all_arrays_lists = true; |
||
826 | } |
||
827 | |||
828 | $combination->all_arrays_callable = false; |
||
829 | $combination->all_arrays_class_string_maps = false; |
||
830 | |||
831 | return null; |
||
832 | } |
||
833 | |||
834 | if ($type instanceof Atomic\TClassStringMap) { |
||
835 | View Code Duplication | foreach ([$type->getStandinKeyParam(), $type->value_param] as $i => $type_param) { |
|
836 | if (isset($combination->array_type_params[$i])) { |
||
837 | $combination->array_type_params[$i] = Type::combineUnionTypes( |
||
838 | $combination->array_type_params[$i], |
||
839 | $type_param, |
||
840 | $codebase, |
||
841 | $overwrite_empty_array |
||
842 | ); |
||
843 | } else { |
||
844 | $combination->array_type_params[$i] = $type_param; |
||
845 | } |
||
846 | } |
||
847 | |||
848 | $combination->array_always_filled = false; |
||
849 | |||
850 | if ($combination->all_arrays_class_string_maps !== false) { |
||
851 | $combination->all_arrays_class_string_maps = true; |
||
852 | $combination->class_string_map_names[$type->param_name] = true; |
||
853 | $combination->class_string_map_as_types[(string) $type->as_type] = $type->as_type; |
||
854 | } |
||
855 | |||
856 | return null; |
||
857 | } |
||
858 | |||
859 | if (($type instanceof TGenericObject && ($type->value === 'Traversable' || $type->value === 'Generator')) |
||
860 | || ($type instanceof TIterable && $type->has_docblock_params) |
||
861 | || ($type instanceof TArray && $type_key === 'iterable') |
||
862 | ) { |
||
863 | View Code Duplication | foreach ($type->type_params as $i => $type_param) { |
|
864 | if (isset($combination->builtin_type_params[$type_key][$i])) { |
||
865 | $combination->builtin_type_params[$type_key][$i] = Type::combineUnionTypes( |
||
866 | $combination->builtin_type_params[$type_key][$i], |
||
867 | $type_param, |
||
868 | $codebase, |
||
869 | $overwrite_empty_array |
||
870 | ); |
||
871 | } else { |
||
872 | $combination->builtin_type_params[$type_key][$i] = $type_param; |
||
873 | } |
||
874 | } |
||
875 | |||
876 | return null; |
||
877 | } |
||
878 | |||
879 | if ($type instanceof TGenericObject) { |
||
880 | View Code Duplication | foreach ($type->type_params as $i => $type_param) { |
|
881 | if (isset($combination->object_type_params[$type_key][$i])) { |
||
882 | $combination->object_type_params[$type_key][$i] = Type::combineUnionTypes( |
||
883 | $combination->object_type_params[$type_key][$i], |
||
884 | $type_param, |
||
885 | $codebase, |
||
886 | $overwrite_empty_array |
||
887 | ); |
||
888 | } else { |
||
889 | $combination->object_type_params[$type_key][$i] = $type_param; |
||
890 | } |
||
891 | } |
||
892 | |||
893 | return null; |
||
894 | } |
||
895 | |||
896 | if ($type instanceof ObjectLike) { |
||
897 | if ($type instanceof TCallableObjectLikeArray && isset($combination->value_types['callable'])) { |
||
898 | return; |
||
899 | } |
||
900 | |||
901 | $existing_objectlike_entries = (bool) $combination->objectlike_entries; |
||
902 | $possibly_undefined_entries = $combination->objectlike_entries; |
||
903 | $combination->objectlike_sealed = $combination->objectlike_sealed && $type->sealed; |
||
904 | |||
905 | View Code Duplication | if ($type->previous_value_type) { |
|
906 | if (!$combination->objectlike_value_type) { |
||
907 | $combination->objectlike_value_type = $type->previous_value_type; |
||
908 | } else { |
||
909 | $combination->objectlike_value_type = Type::combineUnionTypes( |
||
910 | $type->previous_value_type, |
||
911 | $combination->objectlike_value_type, |
||
912 | $codebase, |
||
913 | $overwrite_empty_array |
||
914 | ); |
||
915 | } |
||
916 | } |
||
917 | |||
918 | View Code Duplication | if ($type->previous_key_type) { |
|
919 | if (!$combination->objectlike_key_type) { |
||
920 | $combination->objectlike_key_type = $type->previous_key_type; |
||
921 | } else { |
||
922 | $combination->objectlike_key_type = Type::combineUnionTypes( |
||
923 | $type->previous_key_type, |
||
924 | $combination->objectlike_key_type, |
||
925 | $codebase, |
||
926 | $overwrite_empty_array |
||
927 | ); |
||
928 | } |
||
929 | } |
||
930 | |||
931 | foreach ($type->properties as $candidate_property_name => $candidate_property_type) { |
||
932 | $value_type = isset($combination->objectlike_entries[$candidate_property_name]) |
||
933 | ? $combination->objectlike_entries[$candidate_property_name] |
||
934 | : null; |
||
935 | |||
936 | if (!$value_type) { |
||
937 | $combination->objectlike_entries[$candidate_property_name] = clone $candidate_property_type; |
||
938 | // it's possibly undefined if there are existing objectlike entries and |
||
939 | $combination->objectlike_entries[$candidate_property_name]->possibly_undefined |
||
940 | = $existing_objectlike_entries || $candidate_property_type->possibly_undefined; |
||
941 | } else { |
||
942 | $combination->objectlike_entries[$candidate_property_name] = Type::combineUnionTypes( |
||
943 | $value_type, |
||
944 | $candidate_property_type, |
||
945 | $codebase, |
||
946 | $overwrite_empty_array |
||
947 | ); |
||
948 | } |
||
949 | |||
950 | if (!$type->previous_value_type) { |
||
951 | unset($possibly_undefined_entries[$candidate_property_name]); |
||
952 | } |
||
953 | } |
||
954 | |||
955 | if ($combination->array_counts !== null) { |
||
956 | $combination->array_counts[count($type->properties)] = true; |
||
957 | } |
||
958 | |||
959 | foreach ($possibly_undefined_entries as $possibly_undefined_type) { |
||
960 | $possibly_undefined_type->possibly_undefined = true; |
||
961 | } |
||
962 | |||
963 | if (!$type->is_list) { |
||
964 | $combination->all_arrays_lists = false; |
||
965 | } elseif ($combination->all_arrays_lists !== false) { |
||
966 | $combination->all_arrays_lists = true; |
||
967 | } |
||
968 | |||
969 | View Code Duplication | if ($type instanceof TCallableObjectLikeArray) { |
|
970 | if ($combination->all_arrays_callable !== false) { |
||
971 | $combination->all_arrays_callable = true; |
||
972 | } |
||
973 | } else { |
||
974 | $combination->all_arrays_callable = false; |
||
975 | } |
||
976 | |||
977 | $combination->all_arrays_class_string_maps = false; |
||
978 | |||
979 | return null; |
||
980 | } |
||
981 | |||
982 | if ($type instanceof TObject) { |
||
983 | if ($type instanceof TCallableObject && isset($combination->value_types['callable'])) { |
||
984 | return; |
||
985 | } |
||
986 | |||
987 | $combination->named_object_types = null; |
||
988 | $combination->value_types[$type_key] = $type; |
||
989 | |||
990 | return null; |
||
991 | } |
||
992 | |||
993 | if ($type instanceof TIterable) { |
||
994 | $combination->value_types[$type_key] = $type; |
||
995 | |||
996 | return null; |
||
997 | } |
||
998 | |||
999 | if ($type instanceof TNamedObject) { |
||
1000 | if ($combination->named_object_types === null) { |
||
1001 | return null; |
||
1002 | } |
||
1003 | |||
1004 | if (isset($combination->named_object_types[$type_key])) { |
||
1005 | return null; |
||
1006 | } |
||
1007 | |||
1008 | if (!$codebase) { |
||
1009 | $combination->named_object_types[$type_key] = $type; |
||
1010 | |||
1011 | return null; |
||
1012 | } |
||
1013 | |||
1014 | if (!$codebase->classlikes->classOrInterfaceExists($type_key)) { |
||
1015 | // write this to the main list |
||
1016 | $combination->value_types[$type_key] = $type; |
||
1017 | |||
1018 | return null; |
||
1019 | } |
||
1020 | |||
1021 | $is_class = $codebase->classExists($type_key); |
||
1022 | |||
1023 | foreach ($combination->named_object_types as $key => $_) { |
||
1024 | if ($codebase->classExists($key)) { |
||
1025 | if ($codebase->classExtendsOrImplements($key, $type_key)) { |
||
1026 | unset($combination->named_object_types[$key]); |
||
1027 | continue; |
||
1028 | } |
||
1029 | |||
1030 | if ($is_class) { |
||
1031 | if ($codebase->classExtends($type_key, $key)) { |
||
1032 | return null; |
||
1033 | } |
||
1034 | } |
||
1035 | } else { |
||
1036 | if ($codebase->interfaceExtends($key, $type_key)) { |
||
1037 | unset($combination->named_object_types[$key]); |
||
1038 | continue; |
||
1039 | } |
||
1040 | |||
1041 | if ($is_class) { |
||
1042 | if ($codebase->classImplements($type_key, $key)) { |
||
1043 | return null; |
||
1044 | } |
||
1045 | } else { |
||
1046 | if ($codebase->interfaceExtends($type_key, $key)) { |
||
1047 | return null; |
||
1048 | } |
||
1049 | } |
||
1050 | } |
||
1051 | } |
||
1052 | |||
1053 | $combination->named_object_types[$type_key] = $type; |
||
1054 | |||
1055 | return null; |
||
1056 | } |
||
1057 | |||
1058 | if ($type instanceof TScalar) { |
||
1059 | $combination->strings = null; |
||
1060 | $combination->ints = null; |
||
1061 | $combination->floats = null; |
||
1062 | unset( |
||
1063 | $combination->value_types['string'], |
||
1064 | $combination->value_types['int'], |
||
1065 | $combination->value_types['bool'], |
||
1066 | $combination->value_types['true'], |
||
1067 | $combination->value_types['false'], |
||
1068 | $combination->value_types['float'] |
||
1069 | ); |
||
1070 | $combination->value_types[$type_key] = $type; |
||
1071 | |||
1072 | return null; |
||
1073 | } |
||
1074 | |||
1075 | if ($type instanceof Scalar && isset($combination->value_types['scalar'])) { |
||
1076 | return null; |
||
1077 | } |
||
1078 | |||
1079 | if ($type instanceof TArrayKey) { |
||
1080 | $combination->strings = null; |
||
1081 | $combination->ints = null; |
||
1082 | unset( |
||
1083 | $combination->value_types['string'], |
||
1084 | $combination->value_types['int'] |
||
1085 | ); |
||
1086 | $combination->value_types[$type_key] = $type; |
||
1087 | |||
1088 | return null; |
||
1089 | } |
||
1090 | |||
1091 | if ($type instanceof TString) { |
||
1092 | if ($type instanceof TCallableString && isset($combination->value_types['callable'])) { |
||
1093 | return; |
||
1094 | } |
||
1095 | |||
1096 | if (isset($combination->value_types['array-key'])) { |
||
1097 | return null; |
||
1098 | } |
||
1099 | |||
1100 | if ($type instanceof Type\Atomic\TTemplateParamClass) { |
||
1101 | $combination->value_types[$type_key] = $type; |
||
1102 | View Code Duplication | } elseif ($type instanceof Type\Atomic\TClassString) { |
|
1103 | if (!$type->as_type) { |
||
1104 | $combination->class_string_types['object'] = new TObject(); |
||
1105 | } else { |
||
1106 | $combination->class_string_types[$type->as] = $type->as_type; |
||
1107 | } |
||
1108 | } elseif ($type instanceof TLiteralString) { |
||
1109 | if ($combination->strings !== null && count($combination->strings) < $literal_limit) { |
||
1110 | $combination->strings[$type_key] = $type; |
||
1111 | } else { |
||
1112 | $shared_classlikes = $codebase ? $combination->getSharedTypes($codebase) : []; |
||
1113 | |||
1114 | $combination->strings = null; |
||
1115 | |||
1116 | if (isset($combination->value_types['string']) |
||
1117 | && $combination->value_types['string'] instanceof Type\Atomic\TNumericString |
||
1118 | && \is_numeric($type->value) |
||
1119 | ) { |
||
1120 | // do nothing |
||
1121 | } elseif (isset($combination->value_types['class-string']) |
||
1122 | && $type instanceof TLiteralClassString |
||
1123 | ) { |
||
1124 | // do nothing |
||
1125 | } elseif ($type instanceof TLiteralClassString) { |
||
1126 | $type_classlikes = $codebase |
||
1127 | ? self::getClassLikes($codebase, $type->value) |
||
1128 | : []; |
||
1129 | |||
1130 | $mutual = array_intersect_key($type_classlikes, $shared_classlikes); |
||
1131 | |||
1132 | if ($mutual) { |
||
1133 | $first_class = array_keys($mutual)[0]; |
||
1134 | |||
1135 | $combination->class_string_types[$first_class] = new TNamedObject($first_class); |
||
1136 | } else { |
||
1137 | $combination->class_string_types['object'] = new TObject(); |
||
1138 | } |
||
1139 | } else { |
||
1140 | $combination->value_types['string'] = new TString(); |
||
1141 | } |
||
1142 | } |
||
1143 | } else { |
||
1144 | $type_key = 'string'; |
||
1145 | |||
1146 | if (!isset($combination->value_types['string'])) { |
||
1147 | if ($combination->strings) { |
||
1148 | if ($type instanceof Type\Atomic\TNumericString) { |
||
1149 | $has_non_numeric_string = false; |
||
1150 | |||
1151 | foreach ($combination->strings as $string_type) { |
||
1152 | if (!\is_numeric($string_type->value)) { |
||
1153 | $has_non_numeric_string = true; |
||
1154 | break; |
||
1155 | } |
||
1156 | } |
||
1157 | |||
1158 | if ($has_non_numeric_string) { |
||
1159 | $combination->value_types['string'] = new TString(); |
||
1160 | } else { |
||
1161 | $combination->value_types['string'] = $type; |
||
1162 | } |
||
1163 | |||
1164 | $combination->strings = null; |
||
1165 | } else { |
||
1166 | $has_non_literal_class_string = false; |
||
1167 | |||
1168 | $shared_classlikes = $codebase ? $combination->getSharedTypes($codebase) : []; |
||
1169 | |||
1170 | foreach ($combination->strings as $string_type) { |
||
1171 | if (!$string_type instanceof TLiteralClassString) { |
||
1172 | $has_non_literal_class_string = true; |
||
1173 | break; |
||
1174 | } |
||
1175 | } |
||
1176 | |||
1177 | if ($has_non_literal_class_string || |
||
1178 | !$type instanceof TClassString |
||
1179 | ) { |
||
1180 | $combination->value_types[$type_key] = new TString(); |
||
1181 | } else { |
||
1182 | View Code Duplication | if (isset($shared_classlikes[$type->as]) && $type->as_type) { |
|
1183 | $combination->class_string_types[$type->as] = $type->as_type; |
||
1184 | } else { |
||
1185 | $combination->class_string_types['object'] = new TObject(); |
||
1186 | } |
||
1187 | } |
||
1188 | } |
||
1189 | } else { |
||
1190 | $combination->value_types[$type_key] = $type; |
||
1191 | } |
||
1192 | } elseif (get_class($combination->value_types['string']) !== TString::class) { |
||
1193 | if (get_class($type) === TString::class) { |
||
1194 | $combination->value_types['string'] = $type; |
||
1195 | } elseif ($combination->value_types['string'] instanceof TTraitString |
||
1196 | && $type instanceof TClassString |
||
1197 | ) { |
||
1198 | $combination->value_types['trait-string'] = $combination->value_types['string']; |
||
1199 | $combination->value_types['class-string'] = $type; |
||
1200 | |||
1201 | unset($combination->value_types['string']); |
||
1202 | } elseif (get_class($combination->value_types['string']) !== get_class($type)) { |
||
1203 | if (get_class($type) === TNonEmptyString::class |
||
1204 | && get_class($combination->value_types['string']) === TNonEmptyLowercaseString::class |
||
1205 | ) { |
||
1206 | $combination->value_types['string'] = $type; |
||
1207 | View Code Duplication | } elseif (get_class($combination->value_types['string']) === TNonEmptyString::class |
|
1208 | && get_class($type) === TNonEmptyLowercaseString::class |
||
1209 | ) { |
||
1210 | $combination->value_types['string'] = $combination->value_types['string']; |
||
1211 | } elseif (get_class($type) === TLowercaseString::class |
||
1212 | && get_class($combination->value_types['string']) === TNonEmptyLowercaseString::class |
||
1213 | ) { |
||
1214 | $combination->value_types['string'] = $type; |
||
1215 | View Code Duplication | } elseif (get_class($combination->value_types['string']) === TLowercaseString::class |
|
1216 | && get_class($type) === TNonEmptyLowercaseString::class |
||
1217 | ) { |
||
1218 | $combination->value_types['string'] = $combination->value_types['string']; |
||
1219 | } else { |
||
1220 | $combination->value_types['string'] = new TString(); |
||
1221 | } |
||
1222 | } |
||
1223 | } |
||
1224 | |||
1225 | $combination->strings = null; |
||
1226 | } |
||
1227 | |||
1228 | return null; |
||
1229 | } |
||
1230 | |||
1231 | if ($type instanceof TInt) { |
||
1232 | if (isset($combination->value_types['array-key'])) { |
||
1233 | return null; |
||
1234 | } |
||
1235 | |||
1236 | if ($type instanceof TLiteralInt) { |
||
1237 | View Code Duplication | if ($combination->ints !== null && count($combination->ints) < $literal_limit) { |
|
1238 | $combination->ints[$type_key] = $type; |
||
1239 | } else { |
||
1240 | $combination->ints = null; |
||
1241 | $combination->value_types['int'] = new TInt(); |
||
1242 | } |
||
1243 | } else { |
||
1244 | $combination->ints = null; |
||
1245 | $combination->value_types['int'] = $type; |
||
1246 | } |
||
1247 | |||
1248 | return null; |
||
1249 | } |
||
1250 | |||
1251 | if ($type instanceof TFloat) { |
||
1252 | if ($type instanceof TLiteralFloat) { |
||
1253 | View Code Duplication | if ($combination->floats !== null && count($combination->floats) < $literal_limit) { |
|
1254 | $combination->floats[$type_key] = $type; |
||
1255 | } else { |
||
1256 | $combination->floats = null; |
||
1257 | $combination->value_types['float'] = new TFloat(); |
||
1258 | } |
||
1259 | } else { |
||
1260 | $combination->floats = null; |
||
1261 | $combination->value_types['float'] = $type; |
||
1262 | } |
||
1263 | |||
1264 | return null; |
||
1265 | } |
||
1266 | |||
1267 | if ($type instanceof TCallable && $type_key === 'callable') { |
||
1268 | if (($combination->value_types['string'] ?? null) instanceof TCallableString) { |
||
1269 | unset($combination->value_types['string']); |
||
1270 | } elseif (!empty($combination->array_type_params) && $combination->all_arrays_callable) { |
||
1271 | $combination->array_type_params = []; |
||
1272 | } elseif (isset($combination->value_types['callable-object'])) { |
||
1273 | unset($combination->value_types['callable-object']); |
||
1274 | } |
||
1275 | } |
||
1276 | |||
1277 | $combination->value_types[$type_key] = $type; |
||
1278 | } |
||
1279 | |||
1347 |
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.