mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/12273] Remove duplicated code
PHPBB3-12273
This commit is contained in:
parent
6849e8b36f
commit
08cce5fba5
2 changed files with 24 additions and 37 deletions
|
@ -185,7 +185,7 @@ class php_exporter
|
||||||
if ($found_trigger_event !== false)
|
if ($found_trigger_event !== false)
|
||||||
{
|
{
|
||||||
$event_line = $i;
|
$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
|
// Find variables of the event
|
||||||
$arguments = $this->get_vars_from_array();
|
$arguments = $this->get_vars_from_array();
|
||||||
|
@ -198,7 +198,7 @@ class php_exporter
|
||||||
if ($found_dispatch !== false)
|
if ($found_dispatch !== false)
|
||||||
{
|
{
|
||||||
$event_line = $i;
|
$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
|
* Find the name of the event inside the dispatch() line
|
||||||
*
|
*
|
||||||
* @param int $event_line
|
* @param int $event_line
|
||||||
|
* @param bool $is_dispatch Do we look for dispatch() or trigger_event() ?
|
||||||
* @return int Absolute line number
|
* @return int Absolute line number
|
||||||
* @throws \LogicException
|
* @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 = $this->file_lines[$event_line];
|
||||||
$event_text_line = ltrim($event_text_line, "\t");
|
$event_text_line = ltrim($event_text_line, "\t");
|
||||||
|
|
||||||
$regex = '#\$([a-z](?:[a-z0-9_]|->)*)';
|
if ($is_dispatch)
|
||||||
$regex .= '->dispatch\(';
|
|
||||||
$regex .= '\'' . $this->preg_match_event_name() . '\'';
|
|
||||||
$regex .= '\);#';
|
|
||||||
|
|
||||||
$match = array();
|
|
||||||
preg_match($regex, $event_text_line, $match);
|
|
||||||
if (!isset($match[2]))
|
|
||||||
{
|
{
|
||||||
throw new \LogicException("Can not find event name in line '{$event_text_line}' "
|
$regex = '#\$([a-z](?:[a-z0-9_]|->)*)';
|
||||||
. "in file '{$this->current_file}:{$event_line}'", 1);
|
$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();
|
$match = array();
|
||||||
preg_match($regex, $event_text_line, $match);
|
preg_match($regex, $event_text_line, $match);
|
||||||
|
|
|
@ -233,7 +233,8 @@ class phpbb_event_php_exporter_test extends phpbb_test_case
|
||||||
*/
|
*/
|
||||||
public function test_get_dispatch_name($event_line, $expected)
|
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()
|
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)
|
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()
|
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)
|
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()
|
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)
|
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()
|
static public function get_vars_from_array_data()
|
||||||
|
|
Loading…
Add table
Reference in a new issue