aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2013-11-13 18:27:40 +0100
committerMarc Alexander <admin@m-a-styles.de>2013-11-13 18:27:40 +0100
commit13a4ceedb18ba938d3cd18e2f68707385bc9283a (patch)
treef787d2b82cd103171f72f7430e14b8bec150c258
parent0ec644532d437e2d915185a5a63424d231d49433 (diff)
downloadforums-13a4ceedb18ba938d3cd18e2f68707385bc9283a.tar
forums-13a4ceedb18ba938d3cd18e2f68707385bc9283a.tar.gz
forums-13a4ceedb18ba938d3cd18e2f68707385bc9283a.tar.bz2
forums-13a4ceedb18ba938d3cd18e2f68707385bc9283a.tar.xz
forums-13a4ceedb18ba938d3cd18e2f68707385bc9283a.zip
[ticket/11525] Use foreach instead of array_walk in method clean_row()
This approach is cleaner and probably even faster the previous ways that included using array_walk() or array_map() and other helper functions and methods. PHPBB3-11525
-rw-r--r--phpBB/phpbb/avatar/manager.php32
-rw-r--r--tests/avatar/manager_test.php50
2 files changed, 22 insertions, 60 deletions
diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php
index 9f6a5fb089..12d7861cdf 100644
--- a/phpBB/phpbb/avatar/manager.php
+++ b/phpBB/phpbb/avatar/manager.php
@@ -195,33 +195,19 @@ class manager
return self::$default_row;
}
- $keys = array_keys($row);
- $values = array_values($row);
-
- array_walk($keys, array('\phpbb\avatar\manager', 'strip_prefix'), $prefix);
- $row = array_combine($keys, $values);
-
- if ($prefix == 'group')
+ $output = array();
+ foreach ($row as $key => $value)
{
- $row['id'] = 'g' . $row['id'];
+ $key = preg_replace("#^(?:{$prefix}_)#", '', $key);
+ $output[$key] = $value;
}
- return $row;
- }
+ if ($prefix === 'group' && isset($output['id']))
+ {
+ $output['id'] = 'g' . $output['id'];
+ }
- /**
- * Strip prepending user_ or group_ prefix from key
- *
- * @param string $key Array key
- * @param string $null Parameter is ignored by the function, just required by the array_walk
- * @param string $prefix Prefix that should be stripped off from the keys (e.g. user)
- * Should not include the trailing underscore
- * @return null
- */
- static protected function strip_prefix(&$key, $null, $prefix)
- {
- $regex = ($prefix !== '') ? "#^(?:{$prefix}_)#" : '#^(?:user_|group_)#';
- $key = preg_replace($regex, '', $key);
+ return $output;
}
/**
diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php
index e9f622bfde..f29f7aee95 100644
--- a/tests/avatar/manager_test.php
+++ b/tests/avatar/manager_test.php
@@ -152,31 +152,20 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase
return array(
array(
array(
- 'user_avatar' => '',
- 'user_avatar_type' => '',
- 'user_avatar_width' => '',
+ 'user_avatar' => '',
+ 'user_avatar_type' => '',
+ 'user_avatar_width' => '',
'user_avatar_height' => '',
+ 'group_avatar' => '',
),
array(
- 'avatar' => '',
- 'avatar_type' => '',
- 'avatar_width' => '',
- 'avatar_height' => '',
- ),
- ),
- array(
- array(
- 'group_avatar' => '',
- 'group_avatar_type' => '',
- 'group_avatar_width' => '',
- 'group_avatar_height' => '',
- ),
- array(
- 'avatar' => '',
- 'avatar_type' => '',
- 'avatar_width' => '',
- 'avatar_height' => '',
+ 'user_avatar' => '',
+ 'user_avatar_type' => '',
+ 'user_avatar_width' => '',
+ 'user_avatar_height' => '',
+ 'group_avatar' => '',
),
+ 'foobar',
),
array(
array(),
@@ -189,27 +178,14 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase
),
array(
array(
- 'foobar_avatar' => '',
- 'foobar_avatar_type' => '',
- 'foobar_avatar_width' => '',
- 'foobar_avatar_height' => '',
- ),
- array(
- 'foobar_avatar' => '',
- 'foobar_avatar_type' => '',
- 'foobar_avatar_width' => '',
- 'foobar_avatar_height' => '',
- ),
- ),
- array(
- array(
'user_avatar' => '',
'user_id' => 5,
'group_id' => 4,
),
array(
- 'avatar' => '',
- 'id' => 4,
+ 'user_avatar' => '',
+ 'user_id' => 5,
+ 'group_id' => 4,
),
),
array(