.. _functions-toomanylocalvariables: .. _too-many-local-variables: Too Many Local Variables ++++++++++++++++++++++++ Too many local variables were found in the methods. When over 15 variables are found in such a method, a violation is reported. Local variables exclude globals (imported with global) and arguments. Local variable include `static `_ variables. When too many variables are used in a function, it is a code smells. The function is trying to do too much and needs extra space for juggling. Beyond 15 variables, it becomes difficult to keep track of their name and usage, leading to confusion, overwriting or hijacking. .. code-block:: php +-------------------------------+---------+---------+------------------------------------------------------------------+ | Name | Default | Type | Description | +-------------------------------+---------+---------+------------------------------------------------------------------+ | tooManyLocalVariableThreshold | 15 | integer | Minimal number of variables in one function or method to report. | +-------------------------------+---------+---------+------------------------------------------------------------------+ Connex PHP features ------------------- + `variable `_ + `local-variable `_ + `scope `_ + `local-scope `_ Suggestions ___________ * Remove some of the variables, and inline them * Break the big function into smaller ones * Find repeated code and make it a separate function Specs _____ +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Short name | Functions/TooManyLocalVariables | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Rulesets | :ref:`All `, :ref:`Analyze ` | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Exakat since | 0.9.2 | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | PHP Version | All | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Severity | Minor | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Time To Fix | Slow (1 hour) | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Precision | Very high | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Examples | :ref:`case-humo-gen-functions-toomanylocalvariables` | +--------------+-------------------------------------------------------------------------------------------------------------------------+ | Available in | `Entreprise Edition `_, `Exakat Cloud `_ | +--------------+-------------------------------------------------------------------------------------------------------------------------+