Skip to content

Commit dde3c3e

Browse files
committed
Only check for vars if there are vars in the trigger event
1 parent 12ee08e commit dde3c3e

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/Events/php_exporter.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,13 @@ public function crawl_php_file($file)
119119
$event_line = $i;
120120
$this->set_current_event($this->get_event_name($event_line, false), $event_line);
121121

122-
// Find variables of the event
123-
$arguments = $this->get_vars_from_array();
124-
$doc_vars = $this->get_vars_from_docblock();
125-
$this->validate_vars_docblock_array($arguments, $doc_vars);
122+
// Find variables of the event if it has them
123+
if (strpos($this->file_lines[$event_line], 'compact('))
124+
{
125+
$arguments = $this->get_vars_from_array();
126+
$doc_vars = $this->get_vars_from_docblock();
127+
$this->validate_vars_docblock_array($arguments, $doc_vars);
128+
}
126129
}
127130
else
128131
{

tests/php_exporter_test.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,16 @@ public function extension_data()
5252
/**
5353
* @dataProvider extension_data
5454
*/
55-
public function test_event_name($line, $content, $is_dispatch, $expected_name, $expected_vars, $expected_errors = [])
55+
public function test_event_name($line, $file, $is_dispatch, $expected_name, $expected_vars, $expected_errors = [])
5656
{
57+
$content = file_get_contents($file);
5758
$output = new Output();
5859
$exporter = new php_exporter($output, '');
59-
$exporter->set_content(explode("\n", file_get_contents($content)));
60+
$exporter->set_content(explode("\n", $content));
6061

6162
$name = $exporter->get_event_name($line, $is_dispatch);
6263
$exporter->set_current_event($name, $line);
63-
$vars = $expected_vars ? $exporter->get_vars_from_array(false) : [];
64+
$vars = strpos($content, 'compact(') ? $exporter->get_vars_from_array(false) : [];
6465

6566
self::assertEquals($expected_name, $name);
6667
self::assertEquals($expected_vars, $vars);

0 commit comments

Comments
 (0)