PhpStorm 2016.3 Help

Analyzing Data Flow

On this page:

Introduction

PhpStorm provides Dataflow Analysis features to help you with code archeology - better understand the inherited project code, interpret complicated parts of the code, find bottlenecks in the source, and more.

Specifically, Dataflow to/from here features allow you to:

  • See where values assigned to a variable come from.
  • Find out all the possible values that a variable can have.
  • Find out the places an expression\variable\method parameter can flow into.

If you want to trace back the value passed to a parameter at caret, you can create a slice view of the source code using the Analyze | Dataflow to Here command. Moreover, using Analyze | Dataflow from Here command you can find the places an expression can flow into. The results of each dataflow analysis are displayed in the dedicated tabs of the Analyze Dataflow tool window.

Analyzing data flow

To analyze dataflow to/from a symbol:

  1. Open the desired file for editing, see Opening and Reopening Files in the Editor.
  2. Place the caret at the symbol to be analyzed (expression\variable\method parameter).
  3. On the main menu, or on the context menu, choose Code | Analyze Dataflow to Here or Code | Analyze Dataflow from Here depending on your purposes.
  4. Specify the analysis scope and choose whether you want to ignore all values coming from the test code.
  5. Click OK. Review the analysis results in the dedicated Analyze Dataflow tool window.

Examining the results of Dataflow analysis

The following sections briefly describe how to "read" the dataflow analysis results.

    Dataflow to Here

    • Expand the tree to dig in the chain of assignments and method calls that lead to the symbol in question. Nodes with gray background denote duplicates (the usages that are already present in the tree in another location). The image below shows an example of the Dataflow to Here analysis results:
      ps_dataflow_tree.png
      The values in this view flow in the following direction: the value for the field $result in dataflow.php comes from the $result = Calculate($p,$s) assignment statement where the Calculate($m,$n) method called with the $p and $s parameters returns $f. The value of $f comes from the Division($a,$b) method called with the $d and $e parameters and so on.
    • To view the code of assignments and method calls, press the icon_showDiff.png toggle button. PhpStorm adds a Preview pane which shows the code of the assignment or call that is currently selected in the tree, the code is highlighted:
      ps_dataflow_preview.png
    • To navigate to the source code of an assignment or call, double click the relevant line in the tree.

    Dataflow from Here

    The hierarchical view is similar to the results of Dataflow to Here analysis, but the values flow in the opposite direction.

    See Also

    Last modified: 1 December 2016