diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2014-04-20 14:58:24 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2014-04-20 14:58:24 +0200 |
commit | 08cce5fba548374c8c067ee8bed8aa6d388367e5 (patch) | |
tree | ab906395fab16554be9229cf709aa0af11ecb2d2 | |
parent | 6849e8b36f5d097a413c87a1321a09b9209a9d71 (diff) | |
download | forums-08cce5fba548374c8c067ee8bed8aa6d388367e5.tar forums-08cce5fba548374c8c067ee8bed8aa6d388367e5.tar.gz forums-08cce5fba548374c8c067ee8bed8aa6d388367e5.tar.bz2 forums-08cce5fba548374c8c067ee8bed8aa6d388367e5.tar.xz forums-08cce5fba548374c8c067ee8bed8aa6d388367e5.zip |
[ticket/12273] Remove duplicated code
PHPBB3-12273
-rw-r--r-- | phpBB/phpbb/event/php_exporter.php | 49 | ||||
-rw-r--r-- | tests/event/php_exporter_test.php | 12 |
2 files changed, 24 insertions, 37 deletions
diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index 88301f86f6..c076d7567d 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -185,7 +185,7 @@ class php_exporter if ($found_trigger_event !== false) { $event_line = $i; - $this->set_current_event($this->get_trigger_event_name($event_line), $event_line); + $this->set_current_event($this->get_event_name($event_line, false), $event_line); // Find variables of the event $arguments = $this->get_vars_from_array(); @@ -198,7 +198,7 @@ class php_exporter if ($found_dispatch !== false) { $event_line = $i; - $this->set_current_event($this->get_dispatch_name($event_line), $event_line); + $this->set_current_event($this->get_event_name($event_line, true), $event_line); } } @@ -241,46 +241,29 @@ class php_exporter * Find the name of the event inside the dispatch() line * * @param int $event_line + * @param bool $is_dispatch Do we look for dispatch() or trigger_event() ? * @return int Absolute line number * @throws \LogicException */ - public function get_dispatch_name($event_line) + public function get_event_name($event_line, $is_dispatch) { $event_text_line = $this->file_lines[$event_line]; $event_text_line = ltrim($event_text_line, "\t"); - $regex = '#\$([a-z](?:[a-z0-9_]|->)*)'; - $regex .= '->dispatch\('; - $regex .= '\'' . $this->preg_match_event_name() . '\''; - $regex .= '\);#'; - - $match = array(); - preg_match($regex, $event_text_line, $match); - if (!isset($match[2])) + if ($is_dispatch) { - throw new \LogicException("Can not find event name in line '{$event_text_line}' " - . "in file '{$this->current_file}:{$event_line}'", 1); + $regex = '#\$([a-z](?:[a-z0-9_]|->)*)'; + $regex .= '->dispatch\('; + $regex .= '\'' . $this->preg_match_event_name() . '\''; + $regex .= '\);#'; + } + else + { + $regex = '#extract\(\$([a-z](?:[a-z0-9_]|->)*)'; + $regex .= '->trigger_event\('; + $regex .= '\'' . $this->preg_match_event_name() . '\''; + $regex .= ', compact\(\$vars\)\)\);#'; } - - return $match[2]; - } - - /** - * Find the name of the event inside the trigger_event() line - * - * @param int $event_line - * @return int Absolute line number - * @throws \LogicException - */ - public function get_trigger_event_name($event_line) - { - $event_text_line = $this->file_lines[$event_line]; - $event_text_line = ltrim($event_text_line, "\t"); - - $regex = '#extract\(\$([a-z](?:[a-z0-9_]|->)*)'; - $regex .= '->trigger_event\('; - $regex .= '\'' . $this->preg_match_event_name() . '\''; - $regex .= ', compact\(\$vars\)\)\);#'; $match = array(); preg_match($regex, $event_text_line, $match); diff --git a/tests/event/php_exporter_test.php b/tests/event/php_exporter_test.php index a289f5f6e4..5df7713bdf 100644 --- a/tests/event/php_exporter_test.php +++ b/tests/event/php_exporter_test.php @@ -233,7 +233,8 @@ class phpbb_event_php_exporter_test extends phpbb_test_case */ public function test_get_dispatch_name($event_line, $expected) { - $this->assertEquals($expected, $this->exporter->get_dispatch_name($event_line)); + $this->exporter->set_content(array($event_line)); + $this->assertEquals($expected, $this->exporter->get_event_name(0, true)); } static public function get_dispatch_name_throws_data() @@ -252,7 +253,8 @@ class phpbb_event_php_exporter_test extends phpbb_test_case */ public function test_get_dispatch_name_throws($event_line) { - $this->exporter->get_dispatch_name($event_line); + $this->exporter->set_content(array($event_line)); + $this->exporter->get_event_name(0, true); } static public function get_trigger_event_name_data() @@ -270,7 +272,8 @@ class phpbb_event_php_exporter_test extends phpbb_test_case */ public function test_get_trigger_event_name($event_line, $expected) { - $this->assertEquals($expected, $this->exporter->get_trigger_event_name($event_line)); + $this->exporter->set_content(array($event_line)); + $this->assertEquals($expected, $this->exporter->get_event_name(0, false)); } static public function get_trigger_event_name_throws_data() @@ -293,7 +296,8 @@ class phpbb_event_php_exporter_test extends phpbb_test_case */ public function test_get_trigger_event_name_throws($event_line) { - $this->exporter->get_trigger_event_name($event_line); + $this->exporter->set_content(array($event_line)); + $this->exporter->get_event_name(0, false); } static public function get_vars_from_array_data() |