| Conditions | 31 | 
| Paths | 1030 | 
| Total Lines | 131 | 
| 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:
| 1 | <?php  | 
            ||
| 88 | public static function getMatchingCallableFromCallMapOptions(  | 
            ||
| 89 | Codebase $codebase,  | 
            ||
| 90 | array $callables,  | 
            ||
| 91 | array $args,  | 
            ||
| 92 | ?\Psalm\NodeTypeProvider $nodes  | 
            ||
| 93 |     ) { | 
            ||
| 94 |         if (count($callables) === 1) { | 
            ||
| 95 | return $callables[0];  | 
            ||
| 96 | }  | 
            ||
| 97 | |||
| 98 | $matching_param_count_callable = null;  | 
            ||
| 99 | $matching_coerced_param_count_callable = null;  | 
            ||
| 100 | |||
| 101 |         foreach ($callables as $possible_callable) { | 
            ||
| 102 | $possible_function_params = $possible_callable->params;  | 
            ||
| 103 | |||
| 104 | assert($possible_function_params !== null);  | 
            ||
| 105 | |||
| 106 | $all_args_match = true;  | 
            ||
| 107 | $type_coerced = false;  | 
            ||
| 108 | |||
| 109 | $last_param = count($possible_function_params)  | 
            ||
| 110 | ? $possible_function_params[count($possible_function_params) - 1]  | 
            ||
| 111 | : null;  | 
            ||
| 112 | |||
| 113 | $mandatory_param_count = count($possible_function_params);  | 
            ||
| 114 | |||
| 115 |             foreach ($possible_function_params as $i => $possible_function_param) { | 
            ||
| 116 |                 if ($possible_function_param->is_optional) { | 
            ||
| 117 | $mandatory_param_count = $i;  | 
            ||
| 118 | break;  | 
            ||
| 119 | }  | 
            ||
| 120 | }  | 
            ||
| 121 | |||
| 122 |             if ($mandatory_param_count > count($args) && !($last_param && $last_param->is_variadic)) { | 
            ||
| 123 | continue;  | 
            ||
| 124 | }  | 
            ||
| 125 | |||
| 126 |             foreach ($args as $argument_offset => $arg) { | 
            ||
| 127 |                 if ($argument_offset >= count($possible_function_params)) { | 
            ||
| 128 |                     if (!$last_param || !$last_param->is_variadic) { | 
            ||
| 129 | $all_args_match = false;  | 
            ||
| 130 | break;  | 
            ||
| 131 | }  | 
            ||
| 132 | |||
| 133 | $function_param = $last_param;  | 
            ||
| 134 |                 } else { | 
            ||
| 135 | $function_param = $possible_function_params[$argument_offset];  | 
            ||
| 136 | }  | 
            ||
| 137 | |||
| 138 | $param_type = $function_param->type;  | 
            ||
| 139 | |||
| 140 |                 if (!$param_type) { | 
            ||
| 141 | continue;  | 
            ||
| 142 | }  | 
            ||
| 143 | |||
| 144 | $arg_type = null;  | 
            ||
| 145 | |||
| 146 | if (!$nodes  | 
            ||
| 147 | || !($arg_type = $nodes->getType($arg->value))  | 
            ||
| 148 |                 ) { | 
            ||
| 149 | continue;  | 
            ||
| 150 | }  | 
            ||
| 151 | |||
| 152 |                 if ($arg_type->hasMixed()) { | 
            ||
| 153 | continue;  | 
            ||
| 154 | }  | 
            ||
| 155 | |||
| 156 |                 if ($arg->unpack && !$function_param->is_variadic) { | 
            ||
| 157 |                     if ($arg_type->hasArray()) { | 
            ||
| 158 | /**  | 
            ||
| 159 | * @psalm-suppress PossiblyUndefinedStringArrayOffset  | 
            ||
| 160 | * @var Type\Atomic\TArray|Type\Atomic\ObjectLike|Type\Atomic\TList  | 
            ||
| 161 | */  | 
            ||
| 162 | $array_atomic_type = $arg_type->getAtomicTypes()['array'];  | 
            ||
| 163 | |||
| 164 |                         if ($array_atomic_type instanceof Type\Atomic\ObjectLike) { | 
            ||
| 165 | $arg_type = $array_atomic_type->getGenericValueType();  | 
            ||
| 166 |                         } elseif ($array_atomic_type instanceof Type\Atomic\TList) { | 
            ||
| 167 | $arg_type = $array_atomic_type->type_param;  | 
            ||
| 168 |                         } else { | 
            ||
| 169 | $arg_type = $array_atomic_type->type_params[1];  | 
            ||
| 170 | }  | 
            ||
| 171 | }  | 
            ||
| 172 | }  | 
            ||
| 173 | |||
| 174 | $arg_result = new \Psalm\Internal\Analyzer\TypeComparisonResult();  | 
            ||
| 175 | |||
| 176 | if (TypeAnalyzer::isContainedBy(  | 
            ||
| 177 | $codebase,  | 
            ||
| 178 | $arg_type,  | 
            ||
| 179 | $param_type,  | 
            ||
| 180 | true,  | 
            ||
| 181 | true,  | 
            ||
| 182 | $arg_result  | 
            ||
| 183 |                 ) || $arg_result->type_coerced) { | 
            ||
| 184 |                     if ($arg_result->type_coerced) { | 
            ||
| 185 | $type_coerced = true;  | 
            ||
| 186 | }  | 
            ||
| 187 | |||
| 188 | continue;  | 
            ||
| 189 | }  | 
            ||
| 190 | |||
| 191 | $all_args_match = false;  | 
            ||
| 192 | break;  | 
            ||
| 193 | }  | 
            ||
| 194 | |||
| 195 |             if (count($args) === count($possible_function_params)) { | 
            ||
| 196 | $matching_param_count_callable = $possible_callable;  | 
            ||
| 197 | }  | 
            ||
| 198 | |||
| 199 |             if ($all_args_match && !$type_coerced) { | 
            ||
| 200 | return $possible_callable;  | 
            ||
| 201 | }  | 
            ||
| 202 | |||
| 203 |             if ($all_args_match) { | 
            ||
| 204 | $matching_coerced_param_count_callable = $possible_callable;  | 
            ||
| 205 | }  | 
            ||
| 206 | }  | 
            ||
| 207 | |||
| 208 |         if ($matching_coerced_param_count_callable) { | 
            ||
| 209 | return $matching_coerced_param_count_callable;  | 
            ||
| 210 | }  | 
            ||
| 211 | |||
| 212 |         if ($matching_param_count_callable) { | 
            ||
| 213 | return $matching_param_count_callable;  | 
            ||
| 214 | }  | 
            ||
| 215 | |||
| 216 | // if we don't succeed in finding a match, set to the first possible and wait for issues below  | 
            ||
| 217 | return $callables[0];  | 
            ||
| 218 | }  | 
            ||
| 219 | |||
| 423 | 
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.