Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Tests/VariableAnalysisSniff/IfConditionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function testIfConditionWarnings() {
87,
98,
101,
159,
166,
];
$this->assertEquals($expectedWarnings, $lines);
}
Expand Down Expand Up @@ -56,6 +58,8 @@ public function testInlineIfConditionWarnings() {
77,
86,
88,
130,
136,
];
$this->assertEquals($expectedWarnings, $lines);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,25 @@ function ifConditionWithPossibleUse($first) {
echo $name;
}
}

function ifConditionWithArrayAssignment($first) {
$things = [];
if ($first) {
$things[] = 'person';
}
return $things;
}

function ifConditionWithUndefinedArrayAssignment($first) {
if ($first) {
$things[] = 'person'; // undefined array variable
}
return $things;
}

function loopAndPushWithUndefinedArray($parts) {
while ($part = array_shift($parts)) {
$suggestions[] = $part; // undefined array variable
}
return $suggestions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,15 @@ function ifConditionWithPossibleUse($first) {
if ($first)
echo $name;
}

function ifConditionWithUndefinedArrayAssignment($first) {
if ($first)
$things[] = 'person'; // undefined array variable
return $things;
}

function loopAndPushWithUndefinedArray($parts) {
while ($part = array_shift($parts))
$suggestions[] = $part; // undefined array variable
return $suggestions;
}