From f229dbc8cc1df2fbe90bdcd5a9e7762abc5fc8ae Mon Sep 17 00:00:00 2001 From: Fabian Becker <fabian.becker@uni-tuebingen.de> Date: Wed, 4 Sep 2013 01:33:25 +0200 Subject: [PATCH] Replace create_function calls with lambda functions. This allows the IDE to pick up all code! refs #4113 --- core/DataTable/Renderer/Json.php | 6 +++++- core/Piwik.php | 10 ++++++---- core/Unzip/PclZip.php | 7 +++---- core/View.php | 4 +++- plugins/API/API.php | 2 +- plugins/Actions/API.php | 4 ++-- .../CoreVisualizations/JqplotDataGenerator/Chart.php | 2 +- plugins/CustomVariables/API.php | 9 +++++---- plugins/DevicesDetection/DevicesDetection.php | 2 +- plugins/MultiSites/API.php | 2 +- plugins/Referers/API.php | 2 +- plugins/SitesManager/API.php | 4 ++-- plugins/UserCountry/API.php | 2 +- 13 files changed, 32 insertions(+), 24 deletions(-) diff --git a/core/DataTable/Renderer/Json.php b/core/DataTable/Renderer/Json.php index f5f6fc12bb..89dd73ab37 100644 --- a/core/DataTable/Renderer/Json.php +++ b/core/DataTable/Renderer/Json.php @@ -79,7 +79,11 @@ class Json extends Renderer } // decode all entities - $callback = create_function('&$value,$key', 'if(is_string($value)){$value = html_entity_decode($value, ENT_QUOTES, "UTF-8");}'); + $callback = function(&$value,$key) { + if(is_string($value)) { + $value = html_entity_decode($value, ENT_QUOTES, "UTF-8"); + }; + }; array_walk_recursive($array, $callback); $str = Common::json_encode($array); diff --git a/core/Piwik.php b/core/Piwik.php index 97b6d47b58..96d5b6a15c 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -686,7 +686,9 @@ class Piwik $outputHandler = ini_get('output_handler'); // output handlers can be stacked - $obHandlers = array_filter(ob_list_handlers(), create_function('$var', 'return $var !== "default output handler";')); + $obHandlers = array_filter(ob_list_handlers(), function($var) { + return $var !== "default output handler"; + }); // user defined handler via wrapper $autoPrependFile = ini_get('auto_prepend_file'); @@ -2258,13 +2260,13 @@ class Piwik if (Zend_Registry::get('db')->hasBulkLoader()) { try { -// throw new Exception(''); - $fileSpec = array( 'delim' => "\t", 'quote' => '"', // chr(34) 'escape' => '\\\\', // chr(92) - 'escapespecial_cb' => create_function('$str', 'return str_replace(array(chr(92), chr(34)), array(chr(92).chr(92), chr(92).chr(34)), $str);'), + 'escapespecial_cb' => function($str) { + return str_replace(array(chr(92), chr(34)), array(chr(92).chr(92), chr(92).chr(34)), $str); + }, 'eol' => "\r\n", 'null' => 'NULL', ); diff --git a/core/Unzip/PclZip.php b/core/Unzip/PclZip.php index ad92555ab2..6b2873766e 100644 --- a/core/Unzip/PclZip.php +++ b/core/Unzip/PclZip.php @@ -76,10 +76,9 @@ class PclZip implements UncompressInterface PCLZIP_OPT_PATH, $pathExtracted, PCLZIP_OPT_STOP_ON_ERROR, PCLZIP_OPT_REPLACE_NEWER, - PCLZIP_CB_PRE_EXTRACT, create_function( - '$p_event, &$p_header', - "return strncmp(\$p_header['filename'], '$pathExtracted', strlen('$pathExtracted')) ? 0 : 1;" - ) + PCLZIP_CB_PRE_EXTRACT, function($p_event, &$p_header) { + return strncmp($p_header['filename'], '$pathExtracted', strlen('$pathExtracted')) ? 0 : 1; + } ); } diff --git a/core/View.php b/core/View.php index 9d221c9d9c..d137457506 100644 --- a/core/View.php +++ b/core/View.php @@ -111,7 +111,9 @@ class View implements ViewInterface $count = Piwik::getWebsitesCountToDisplay(); $sites = SitesManagerAPI::getInstance()->getSitesWithAtLeastViewAccess($count); - usort($sites, create_function('$site1, $site2', 'return strcasecmp($site1["name"], $site2["name"]);')); + usort($sites, function($site1, $site2) { + return strcasecmp($site1["name"], $site2["name"]); + }); $this->sites = $sites; $this->url = Common::sanitizeInputValue(Url::getCurrentUrl()); $this->token_auth = Piwik::getCurrentUserTokenAuth(); diff --git a/plugins/API/API.php b/plugins/API/API.php index 977e4accd8..4181881132 100644 --- a/plugins/API/API.php +++ b/plugins/API/API.php @@ -146,7 +146,7 @@ class API 'segment' => 'visitorType', 'acceptedValues' => 'new, returning, returningCustomer' . ". " . Piwik_Translate('General_VisitTypeExample', '"&segment=visitorType==returning,visitorType==returningCustomer"'), 'sqlSegment' => 'log_visit.visitor_returning', - 'sqlFilter' => create_function('$type', 'return $type == "new" ? 0 : ($type == "returning" ? 1 : 2);'), + 'sqlFilter' => function($type) { return $type == "new" ? 0 : ($type == "returning" ? 1 : 2); } ); $segments[] = array( 'type' => 'metric', diff --git a/plugins/Actions/API.php b/plugins/Actions/API.php index 1a7a551fa8..9b05536227 100644 --- a/plugins/Actions/API.php +++ b/plugins/Actions/API.php @@ -182,7 +182,7 @@ class API // Keep only pages which are following site search $dataTable->filter('ColumnCallbackDeleteRow', array( 'nb_hits_following_search', - create_function('$value', 'return $value > 0;') + function($value) { return $value > 0; } )); } @@ -322,7 +322,7 @@ class API $dataTable->filter('ColumnCallbackDeleteRow', array( Metrics::INDEX_SITE_SEARCH_HAS_NO_RESULT, - create_function('$value', 'return $value >= 1;') + function($value) { return $value >= 1; } )); $dataTable->deleteRow(DataTable::ID_SUMMARY_ROW); $dataTable->deleteColumn(Metrics::INDEX_SITE_SEARCH_HAS_NO_RESULT); diff --git a/plugins/CoreVisualizations/JqplotDataGenerator/Chart.php b/plugins/CoreVisualizations/JqplotDataGenerator/Chart.php index 128935c884..0f0cccb22c 100644 --- a/plugins/CoreVisualizations/JqplotDataGenerator/Chart.php +++ b/plugins/CoreVisualizations/JqplotDataGenerator/Chart.php @@ -63,7 +63,7 @@ class Chart 'internalLabel' => $label ); - array_walk($data, create_function('&$v', '$v = (float)$v;')); + array_walk($data, function(&$v) { $v = (float)$v; }); $this->data[] = & $data; } } diff --git a/plugins/CustomVariables/API.php b/plugins/CustomVariables/API.php index 21bdca1f55..7e42e6de49 100644 --- a/plugins/CustomVariables/API.php +++ b/plugins/CustomVariables/API.php @@ -113,10 +113,11 @@ class API // Hack Ecommerce product price tracking to display correctly $dataTable->renameColumn('price_viewed', 'price'); } - $dataTable->queueFilter('ColumnCallbackReplace', array('label', create_function('$label', ' - return $label == \\Piwik\\Plugins\\CustomVariables\\Archiver::LABEL_CUSTOM_VALUE_NOT_DEFINED - ? "' . Piwik_Translate('General_NotDefined', Piwik_Translate('CustomVariables_ColumnCustomVariableValue')) . '" - : $label;'))); + $dataTable->queueFilter('ColumnCallbackReplace', array('label', function($label) { + return $label == \Piwik\Plugins\CustomVariables\Archiver::LABEL_CUSTOM_VALUE_NOT_DEFINED + ? Piwik_Translate('General_NotDefined', Piwik_Translate('CustomVariables_ColumnCustomVariableValue')) + : $label; + })); return $dataTable; } } diff --git a/plugins/DevicesDetection/DevicesDetection.php b/plugins/DevicesDetection/DevicesDetection.php index 00bfa35aac..6f298348e9 100644 --- a/plugins/DevicesDetection/DevicesDetection.php +++ b/plugins/DevicesDetection/DevicesDetection.php @@ -94,7 +94,7 @@ class DevicesDetection extends \Piwik\Plugin 'deviceType', 'log_visit.config_device_type', implode(", ", UserAgentParserEnhanced::$deviceTypes), // comma separated examples - create_function('$type', 'return array_search( strtolower(trim(urldecode($type))), UserAgentParserEnhanced::$deviceTypes);') + function($type) { return array_search( strtolower(trim(urldecode($type))), UserAgentParserEnhanced::$deviceTypes); } ), // device brands report array( diff --git a/plugins/MultiSites/API.php b/plugins/MultiSites/API.php index 6b2381c0d5..d3554ff6f6 100755 --- a/plugins/MultiSites/API.php +++ b/plugins/MultiSites/API.php @@ -314,7 +314,7 @@ class API 'ColumnCallbackDeleteRow', array( self::NB_VISITS_METRIC, - create_function('$value', 'return $value != 0;') + function($value) { return $value != 0; } ) ); } diff --git a/plugins/Referers/API.php b/plugins/Referers/API.php index 8e65899d1e..1c3e5b3793 100644 --- a/plugins/Referers/API.php +++ b/plugins/Referers/API.php @@ -306,7 +306,7 @@ class API $dataTable = $this->getDataTable(Archiver::WEBSITES_RECORD_NAME, $idSite, $period, $date, $segment, $expanded = false, $idSubtable); // the htmlspecialchars_decode call is for BC for before 1.1 // as the Referrer URL was previously encoded in the log tables, but is now recorded raw - $dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'url', create_function('$label', 'return htmlspecialchars_decode($label);'))); + $dataTable->queueFilter('ColumnCallbackAddMetadata', array('label', 'url', function($label) { return htmlspecialchars_decode($label); })); $dataTable->queueFilter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\getPathFromUrl')); return $dataTable; } diff --git a/plugins/SitesManager/API.php b/plugins/SitesManager/API.php index db68b112cc..5904097dd6 100644 --- a/plugins/SitesManager/API.php +++ b/plugins/SitesManager/API.php @@ -1079,7 +1079,7 @@ class API public function getCurrencyList() { $currencies = Piwik::getCurrencyList(); - return array_map(create_function('$a', 'return $a[1]." (".$a[0].")";'), $currencies); + return array_map(function($a) { return $a[1]." (".$a[0].")"; }, $currencies); } /** @@ -1090,7 +1090,7 @@ class API public function getCurrencySymbols() { $currencies = Piwik::getCurrencyList(); - return array_map(create_function('$a', 'return $a[0];'), $currencies); + return array_map(function($a) { return $a[0]; }, $currencies); } /** diff --git a/plugins/UserCountry/API.php b/plugins/UserCountry/API.php index a621b9344c..b62076385c 100644 --- a/plugins/UserCountry/API.php +++ b/plugins/UserCountry/API.php @@ -132,7 +132,7 @@ class API array('label', 'city_name', __NAMESPACE__ . '\getElementFromStringArray', array($separator, 0, $strUnknown))); $dataTable->filter('MetadataCallbackAddMetadata', - array('city_name', 'city', create_function('$city', ' if ($city == "' . $strUnknown . '") { return "xx"; } else { return false; } '))); + array('city_name', 'city', function($city) use ($strUnknown) { if ($city == $strUnknown) { return "xx"; } else { return false; } })); $dataTable->filter('ColumnCallbackAddMetadata', array('label', 'region', __NAMESPACE__ . '\getElementFromStringArray', array($separator, 1, $unk))); $dataTable->filter('ColumnCallbackAddMetadata', -- GitLab