| Conditions | 3 |
| Paths | 4 |
| Total Lines | 13 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 3 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 18 | 4 | public function __construct(SimpleXMLElement $xml) |
|
| 19 | { |
||
| 20 | 4 | $this->ofx = $xml; |
|
| 21 | |||
| 22 | 4 | if (isset($this->ofx->BANKMSGSRSV1->STMTTRNRS->STMTRS->BANKTRANLIST->STMTTRN)) { |
|
| 23 | 3 | $movements = $this->ofx->BANKMSGSRSV1->STMTTRNRS->STMTRS->BANKTRANLIST->STMTTRN; |
|
| 24 | 3 | } |
|
| 25 | 4 | if (isset($this->ofx->CREDITCARDMSGSRSV1->CCSTMTTRNRS->CCSTMTRS->BANKTRANLIST)) { |
|
| 26 | 1 | $movements = $this->ofx->CREDITCARDMSGSRSV1->CCSTMTTRNRS->CCSTMTRS->BANKTRANLIST; |
|
| 27 | 1 | } |
|
| 28 | |||
| 29 | 4 | $this->exportMovements($movements); |
|
|
|
|||
| 30 | 4 | } |
|
| 31 | |||
| 49 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: