FIX Remove use of deprecated each method

This commit is contained in:
Daniel Hensby 2018-06-04 13:02:35 +01:00
parent 33d2df1bf5
commit a20b0a4aa6
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
10 changed files with 45 additions and 31 deletions

View File

@ -278,15 +278,17 @@ class _DiffEngine
if (empty($ymatches[$line])) if (empty($ymatches[$line]))
continue; continue;
$matches = $ymatches[$line]; $matches = $ymatches[$line];
reset($matches); $y = reset($matches);
while (list ($junk, $y) = each($matches)) do {
if (empty($this->in_seq[$y])) { if (empty($this->in_seq[$y])) {
$k = $this->_lcs_pos($y); $k = $this->_lcs_pos($y);
USE_ASSERTS && assert($k > 0); USE_ASSERTS && assert($k > 0);
$ymids[$k] = $ymids[$k-1]; $ymids[$k] = $ymids[$k - 1];
break; break;
} }
while (list ($junk, $y) = each($matches)) { } while (false !== ($y = next($matches)));
while (false !== ($y = next($matches))) {
if ($y > $this->seq[$k-1]) { if ($y > $this->seq[$k-1]) {
USE_ASSERTS && assert($y < $this->seq[$k]); USE_ASSERTS && assert($y < $this->seq[$k]);
// Optimization: this is a common case: // Optimization: this is a common case:
@ -797,18 +799,19 @@ class Diff
$content = str_replace(array("&nbsp;","<", ">"),array(" "," <", "> "),$content); $content = str_replace(array("&nbsp;","<", ">"),array(" "," <", "> "),$content);
$candidateChunks = preg_split("/[\t\r\n ]+/", $content); $candidateChunks = preg_split("/[\t\r\n ]+/", $content);
while(list($i,$item) = each($candidateChunks)) { $item = reset($candidateChunks);
do {
if(isset($item[0]) && $item[0] == "<") { if(isset($item[0]) && $item[0] == "<") {
$newChunk = $item; $newChunk = $item;
while($item[strlen($item)-1] != ">") { while($item[strlen($item)-1] != ">") {
list($i,$item) = each($candidateChunks); $item = next($candidateChunks);
$newChunk .= ' ' . $item; $newChunk .= ' ' . $item;
} }
$chunks[] = $newChunk; $chunks[] = $newChunk;
} else { } else {
$chunks[] = $item; $chunks[] = $item;
} }
} } while (false !== ($item = next($candidateChunks)));
return $chunks; return $chunks;
} }

View File

@ -161,7 +161,7 @@ class Profiler {
echo"============================================================================\n"; echo"============================================================================\n";
print( "Calls Time Routine\n"); print( "Calls Time Routine\n");
echo"-----------------------------------------------------------------------------\n"; echo"-----------------------------------------------------------------------------\n";
while (list ($key, $val) = each ($this->description)) { foreach ($this->description as $key => $val) {
$t = $this->elapsedTime($key); $t = $this->elapsedTime($key);
$total = $this->running[$key]; $total = $this->running[$key];
$count = $this->count[$key]; $count = $this->count[$key];

View File

@ -337,26 +337,34 @@ class GridField extends FormField {
'before' => true, 'before' => true,
'after' => true, 'after' => true,
); );
$fragmentDeferred = array();
reset($content); // TODO: Break the below into separate reducer methods
while(list($contentKey, $contentValue) = each($content)) { // Continue looping if any placeholders exist
if(preg_match_all('/\$DefineFragment\(([a-z0-9\-_]+)\)/i', $contentValue, $matches)) { while (array_filter($content, function ($value) {
foreach($matches[1] as $match) { return preg_match('/\$DefineFragment\(([a-z0-9\-_]+)\)/i', $value);
})) {
foreach ($content as $contentKey => $contentValue) {
// Skip if this specific content has no placeholders
if (!preg_match_all('/\$DefineFragment\(([a-z0-9\-_]+)\)/i', $contentValue, $matches)) {
continue;
}
foreach ($matches[1] as $match) {
$fragmentName = strtolower($match); $fragmentName = strtolower($match);
$fragmentDefined[$fragmentName] = true; $fragmentDefined[$fragmentName] = true;
$fragment = ''; $fragment = '';
if(isset($content[$fragmentName])) { if (isset($content[$fragmentName])) {
$fragment = $content[$fragmentName]; $fragment = $content[$fragmentName];
} }
// If the fragment still has a fragment definition in it, when we should defer // If the fragment still has a fragment definition in it, when we should defer
// this item until later. // this item until later.
if(preg_match('/\$DefineFragment\(([a-z0-9\-_]+)\)/i', $fragment, $matches)) { if (preg_match('/\$DefineFragment\(([a-z0-9\-_]+)\)/i', $fragment, $matches)) {
if(isset($fragmentDeferred[$contentKey]) && $fragmentDeferred[$contentKey] > 5) { if (isset($fragmentDeferred[$contentKey]) && $fragmentDeferred[$contentKey] > 5) {
throw new LogicException(sprintf( throw new LogicException(sprintf(
'GridField HTML fragment "%s" and "%s" appear to have a circular dependency.', 'GridField HTML fragment "%s" and "%s" appear to have a circular dependency.',
$fragmentName, $fragmentName,
@ -368,7 +376,7 @@ class GridField extends FormField {
$content[$contentKey] = $contentValue; $content[$contentKey] = $contentValue;
if(!isset($fragmentDeferred[$contentKey])) { if (!isset($fragmentDeferred[$contentKey])) {
$fragmentDeferred[$contentKey] = 0; $fragmentDeferred[$contentKey] = 0;
} }
@ -386,6 +394,7 @@ class GridField extends FormField {
} }
} }
// Check for any undefined fragments, and if so throw an exception. // Check for any undefined fragments, and if so throw an exception.
// While we're at it, trim whitespace off the elements. // While we're at it, trim whitespace off the elements.
@ -587,7 +596,7 @@ class GridField extends FormField {
} else { } else {
$classes[] = 'odd'; $classes[] = 'odd';
} }
$this->extend('updateNewRowClasses', $classes, $total, $index, $record); $this->extend('updateNewRowClasses', $classes, $total, $index, $record);
return $classes; return $classes;

View File

@ -247,8 +247,10 @@ class Hierarchy extends DataExtension {
$this->markedNodes = array($this->owner->ID => $this->owner); $this->markedNodes = array($this->owner->ID => $this->owner);
$this->owner->markUnexpanded(); $this->owner->markUnexpanded();
$node = reset($this->markedNodes);
// foreach can't handle an ever-growing $nodes list // foreach can't handle an ever-growing $nodes list
while(list($id, $node) = each($this->markedNodes)) { do {
// first determine the number of children, if it's too high the tree view can't be used // first determine the number of children, if it's too high the tree view can't be used
// so will will not even bother to display the subtree // so will will not even bother to display the subtree
// this covers two cases: // this covers two cases:
@ -267,7 +269,7 @@ class Hierarchy extends DataExtension {
if($children) foreach($children as $child) $child->markClosed(); if($children) foreach($children as $child) $child->markClosed();
break; break;
} }
} } while (false !== ($node = next($this->markedNodes)));
return sizeof($this->markedNodes); return sizeof($this->markedNodes);
} }

View File

@ -63,7 +63,7 @@ class Zend_Cache_Backend
*/ */
public function __construct(array $options = array()) public function __construct(array $options = array())
{ {
while (list($name, $value) = each($options)) { foreach ($options as $name => $value) {
$this->setOption($name, $value); $this->setOption($name, $value);
} }
} }
@ -78,7 +78,7 @@ class Zend_Cache_Backend
public function setDirectives($directives) public function setDirectives($directives)
{ {
if (!is_array($directives)) Zend_Cache::throwException('Directives parameter must be an array'); if (!is_array($directives)) Zend_Cache::throwException('Directives parameter must be an array');
while (list($name, $value) = each($directives)) { foreach ($directives as $name => $value) {
if (!is_string($name)) { if (!is_string($name)) {
Zend_Cache::throwException("Incorrect option name : $name"); Zend_Cache::throwException("Incorrect option name : $name");
} }

View File

@ -143,7 +143,7 @@ class Zend_Cache_Core
Zend_Cache::throwException("Options passed were not an array" Zend_Cache::throwException("Options passed were not an array"
. " or Zend_Config instance."); . " or Zend_Config instance.");
} }
while (list($name, $value) = each($options)) { foreach ($options as $name => $value) {
$this->setOption($name, $value); $this->setOption($name, $value);
} }
$this->_loggerSanity(); $this->_loggerSanity();
@ -158,7 +158,7 @@ class Zend_Cache_Core
public function setConfig(Zend_Config $config) public function setConfig(Zend_Config $config)
{ {
$options = $config->toArray(); $options = $config->toArray();
while (list($name, $value) = each($options)) { foreach ($options as $name => $value) {
$this->setOption($name, $value); $this->setOption($name, $value);
} }
return $this; return $this;

View File

@ -107,7 +107,7 @@ class Zend_Cache_Frontend_Class extends Zend_Cache_Core
*/ */
public function __construct(array $options = array()) public function __construct(array $options = array())
{ {
while (list($name, $value) = each($options)) { foreach ($options as $name => $value) {
$this->setOption($name, $value); $this->setOption($name, $value);
} }
if ($this->_specificOptions['cached_entity'] === null) { if ($this->_specificOptions['cached_entity'] === null) {

View File

@ -88,7 +88,7 @@ class Zend_Cache_Frontend_File extends Zend_Cache_Core
*/ */
public function __construct(array $options = array()) public function __construct(array $options = array())
{ {
while (list($name, $value) = each($options)) { foreach ($options as $name => $value) {
$this->setOption($name, $value); $this->setOption($name, $value);
} }
if (!isset($this->_specificOptions['master_files'])) { if (!isset($this->_specificOptions['master_files'])) {

View File

@ -63,7 +63,7 @@ class Zend_Cache_Frontend_Function extends Zend_Cache_Core
*/ */
public function __construct(array $options = array()) public function __construct(array $options = array())
{ {
while (list($name, $value) = each($options)) { foreach ($options as $name => $value) {
$this->setOption($name, $value); $this->setOption($name, $value);
} }
$this->setOption('automatic_serialization', true); $this->setOption('automatic_serialization', true);

View File

@ -129,7 +129,7 @@ class Zend_Cache_Frontend_Page extends Zend_Cache_Core
*/ */
public function __construct(array $options = array()) public function __construct(array $options = array())
{ {
while (list($name, $value) = each($options)) { foreach ($options as $name => $value) {
$name = strtolower($name); $name = strtolower($name);
switch ($name) { switch ($name) {
case 'regexps': case 'regexps':