Skip to content

Instantly share code, notes, and snippets.

@syphoxy
Last active January 3, 2016 12:29
Show Gist options
  • Save syphoxy/8463247 to your computer and use it in GitHub Desktop.
Save syphoxy/8463247 to your computer and use it in GitHub Desktop.
Refactoring Magento code by example
<?php
protected function _getMemoryLimit()
{
$memoryLimit = trim(strtoupper(ini_get('memory_limit')));
if (!isSet($memoryLimit[0])){
$memoryLimit = "128M";
}
if (substr($memoryLimit, -1) == 'K') {
return substr($memoryLimit, 0, -1) * 1024;
}
if (substr($memoryLimit, -1) == 'M') {
return substr($memoryLimit, 0, -1) * 1024 * 1024;
}
if (substr($memoryLimit, -1) == 'G') {
return substr($memoryLimit, 0, -1) * 1024 * 1024 * 1024;
}
return $memoryLimit;
}
<?php
const DEFAULT_MEMORY_LIMIT = 134217728;
protected function _getMemoryLimit()
{
$memoryLimit = trim(ini_get('memory_limit'));
if (empty($memoryLimit)) {
return self::DEFAULT_MEMORY_LIMIT;
}
$multiple = stripos("KMGTPEZY", substr($memoryLimit, -1));
if ($multiple !== false) {
return intval(substr($memoryLimit, 0, -1)) * pow(1024, $multiple + 1);
}
return $memoryLimit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment