Skip to content

Commit

Permalink
Fixing most coding standard issues in Utility/
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 3, 2012
1 parent acccdcd commit 9d325fe
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 65 deletions.
6 changes: 3 additions & 3 deletions lib/Cake/Utility/CakeNumber.php
Expand Up @@ -206,15 +206,15 @@ public static function currency($number, $currency = 'USD', $options = array())
}
}

$position = $options[$symbolKey.'Position'] != 'after' ? 'before' : 'after';
$options[$position] = $options[$symbolKey.'Symbol'];
$position = $options[$symbolKey . 'Position'] != 'after' ? 'before' : 'after';
$options[$position] = $options[$symbolKey . 'Symbol'];

$abs = abs($number);
$result = self::format($abs, $options);

if ($number < 0 ) {
if ($options['negative'] == '()') {
$result = '(' . $result .')';
$result = '(' . $result . ')';
} else {
$result = $options['negative'] . $result;
}
Expand Down
43 changes: 22 additions & 21 deletions lib/Cake/Utility/CakeTime.php
Expand Up @@ -52,11 +52,11 @@ class CakeTime {
*/
public function __set($name, $value) {
switch ($name) {
case 'niceFormat':
self::${$name} = $value;
break;
default:
break;
case 'niceFormat':
self::${$name} = $value;
break;
default:
break;
}
}

Expand All @@ -67,12 +67,12 @@ public function __set($name, $value) {
*/
public function __get($name) {
switch ($name) {
case 'niceFormat':
return self::${$name};
break;
default:
return null;
break;
case 'niceFormat':
return self::${$name};
break;
default:
return null;
break;
}
}

Expand Down Expand Up @@ -140,13 +140,13 @@ protected static function _translateSpecifier($specifier) {
case 'h':
$months = __dc('cake', 'abmon', 5);
if (is_array($months)) {
return $months[date('n', self::$_time) -1];
return $months[date('n', self::$_time) - 1];
}
return '%b';
case 'B':
$months = __dc('cake', 'mon', 5);
if (is_array($months)) {
return $months[date('n', self::$_time) -1];
return $months[date('n', self::$_time) - 1];
}
break;
case 'n':
Expand Down Expand Up @@ -202,7 +202,7 @@ protected static function _translateSpecifier($specifier) {
public static function convert($serverTime, $userOffset) {
$serverOffset = self::serverOffset();
$gmtTime = $serverTime - $serverOffset;
$userTime = $gmtTime + $userOffset * (60*60);
$userTime = $gmtTime + $userOffset * (60 * 60);
return $userTime;
}

Expand Down Expand Up @@ -378,7 +378,7 @@ public static function isThisMonth($dateString, $userOffset = null) {
*/
public static function isThisYear($dateString, $userOffset = null) {
$date = self::fromString($dateString, $userOffset);
return date('Y', $date) == date('Y', time());
return date('Y', $date) == date('Y', time());
}

/**
Expand Down Expand Up @@ -429,16 +429,16 @@ public static function toQuarter($dateString, $range = false) {

switch ($date) {
case 1:
$date = array($year.'-01-01', $year.'-03-31');
$date = array($year . '-01-01', $year . '-03-31');
break;
case 2:
$date = array($year.'-04-01', $year.'-06-30');
$date = array($year . '-04-01', $year . '-06-30');
break;
case 3:
$date = array($year.'-07-01', $year.'-09-30');
$date = array($year . '-07-01', $year . '-09-30');
break;
case 4:
$date = array($year.'-10-01', $year.'-12-31');
$date = array($year . '-10-01', $year . '-12-31');
break;
}
}
Expand Down Expand Up @@ -485,8 +485,8 @@ public static function toRSS($dateString, $userOffset = null) {
if ($userOffset == 0) {
$timezone = '+0000';
} else {
$hours = (int) floor(abs($userOffset));
$minutes = (int) (fmod(abs($userOffset), $hours) * 60);
$hours = (int)floor(abs($userOffset));
$minutes = (int)(fmod(abs($userOffset), $hours) * 60);
$timezone = ($userOffset < 0 ? '-' : '+') . str_pad($hours, 2, '0', STR_PAD_LEFT) . str_pad($minutes, 2, '0', STR_PAD_LEFT);
}
return date('D, d M Y H:i:s', $date) . ' ' . $timezone;
Expand Down Expand Up @@ -795,4 +795,5 @@ protected static function _strftime($format, $date) {
}
return $format;
}

}
7 changes: 1 addition & 6 deletions lib/Cake/Utility/ClassRegistry.php
@@ -1,11 +1,5 @@
<?php
/**
* Class collections.
*
* A repository for class objects, each registered with a key.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand Down Expand Up @@ -370,4 +364,5 @@ public static function flush() {
$_this->_objects = array();
$_this->_map = array();
}

}
27 changes: 14 additions & 13 deletions lib/Cake/Utility/Debugger.php
Expand Up @@ -203,7 +203,7 @@ public static function log($var, $level = LOG_DEBUG) {
* @deprecated This function is superseded by Debugger::outputError()
*/
public static function showError($code, $description, $file = null, $line = null, $context = null) {
$_this = Debugger::getInstance();
$self = Debugger::getInstance();

if (empty($file)) {
$file = '[internal]';
Expand All @@ -214,8 +214,8 @@ public static function showError($code, $description, $file = null, $line = null
$path = self::trimPath($file);

$info = compact('code', 'description', 'file', 'line');
if (!in_array($info, $_this->errors)) {
$_this->errors[] = $info;
if (!in_array($info, $self->errors)) {
$self->errors[] = $info;
} else {
return;
}
Expand Down Expand Up @@ -254,7 +254,7 @@ public static function showError($code, $description, $file = null, $line = null
$data = compact(
'level', 'error', 'code', 'description', 'file', 'path', 'line', 'context'
);
echo $_this->outputError($data);
echo $self->outputError($data);

if ($error == 'Fatal Error') {
exit();
Expand All @@ -279,10 +279,10 @@ public static function showError($code, $description, $file = null, $line = null
* @link http://book.cakephp.org/2.0/en/development/debugging.html#Debugger::trace
*/
public static function trace($options = array()) {
$_this = Debugger::getInstance();
$self = Debugger::getInstance();
$defaults = array(
'depth' => 999,
'format' => $_this->_outputFormat,
'format' => $self->_outputFormat,
'args' => false,
'start' => 0,
'scope' => null,
Expand Down Expand Up @@ -330,10 +330,10 @@ public static function trace($options = array()) {
} elseif ($options['format'] == 'array') {
$back[] = $trace;
} else {
if (isset($_this->_templates[$options['format']]['traceLine'])) {
$tpl = $_this->_templates[$options['format']]['traceLine'];
if (isset($self->_templates[$options['format']]['traceLine'])) {
$tpl = $self->_templates[$options['format']]['traceLine'];
} else {
$tpl = $_this->_templates['base']['traceLine'];
$tpl = $self->_templates['base']['traceLine'];
}
$trace['path'] = self::trimPath($trace['file']);
$trace['reference'] = $reference;
Expand Down Expand Up @@ -665,7 +665,7 @@ public static function addFormat($format, array $strings) {
* in 3.0
*/
public function output($format = null, $strings = array()) {
$_this = Debugger::getInstance();
$self = Debugger::getInstance();
$data = null;

if (is_null($format)) {
Expand All @@ -676,9 +676,9 @@ public function output($format = null, $strings = array()) {
return Debugger::addFormat($format, $strings);
}

if ($format === true && !empty($_this->_data)) {
$data = $_this->_data;
$_this->_data = array();
if ($format === true && !empty($self->_data)) {
$data = $self->_data;
$self->_data = array();
$format = false;
}
Debugger::outputAs($format);
Expand Down Expand Up @@ -810,4 +810,5 @@ public static function checkSecurityKeys() {
trigger_error(__d('cake_dev', 'Please change the value of \'Security.cipherSeed\' in app/Config/core.php to a numeric (digits only) seed value specific to your application'), E_USER_NOTICE);
}
}

}
4 changes: 2 additions & 2 deletions lib/Cake/Utility/File.php
Expand Up @@ -528,7 +528,7 @@ public function lastChange() {
* @return Folder Current folder
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::Folder
*/
public function &Folder() {
public function &folder() {
return $this->Folder;
}

Expand Down Expand Up @@ -566,5 +566,5 @@ public function mime() {
}
return false;
}

}
9 changes: 3 additions & 6 deletions lib/Cake/Utility/Folder.php
@@ -1,9 +1,5 @@
<?php
/**
* Convenience class for handling directories.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand Down Expand Up @@ -192,7 +188,7 @@ public function read($sort = true, $exceptions = false, $fullPath = false) {
*/
public function find($regexpPattern = '.*', $sort = false) {
list($dirs, $files) = $this->read($sort);
return array_values(preg_grep('/^' . $regexpPattern . '$/i', $files)); ;
return array_values(preg_grep('/^' . $regexpPattern . '$/i', $files));
}

/**
Expand Down Expand Up @@ -750,7 +746,7 @@ public function realpath($path) {
$newpath = DS;
}

while (($part = array_shift($parts)) !== NULL) {
while (($part = array_shift($parts)) !== null) {
if ($part === '.' || $part === '') {
continue;
}
Expand Down Expand Up @@ -780,4 +776,5 @@ public static function isSlashTerm($path) {
$lastChar = $path[strlen($path) - 1];
return $lastChar === '/' || $lastChar === '\\';
}

}
9 changes: 1 addition & 8 deletions lib/Cake/Utility/Inflector.php
@@ -1,11 +1,5 @@
<?php
/**
* Pluralize and singularize English words.
*
* Used by Cake's naming conventions throughout the framework.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand Down Expand Up @@ -350,7 +344,6 @@ public static function rules($type, $rules, $reset = false) {
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::pluralize
*/
public static function pluralize($word) {

if (isset(self::$_cache['pluralize'][$word])) {
return self::$_cache['pluralize'][$word];
}
Expand Down Expand Up @@ -394,7 +387,6 @@ public static function pluralize($word) {
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::singularize
*/
public static function singularize($word) {

if (isset(self::$_cache['singularize'][$word])) {
return self::$_cache['singularize'][$word];
}
Expand Down Expand Up @@ -552,6 +544,7 @@ public static function slug($string, $replacement = '_') {
$map = self::$_transliteration + $merge;
return preg_replace(array_keys($map), array_values($map), $string);
}

}

// Store the initial state
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/Utility/ObjectCollection.php
Expand Up @@ -322,4 +322,5 @@ public static function normalizeObjectArray($objects) {
}
return $normal;
}

}
1 change: 1 addition & 0 deletions lib/Cake/Utility/Sanitize.php
Expand Up @@ -260,4 +260,5 @@ public static function clean($data, $options = array()) {
return $data;
}
}

}
1 change: 1 addition & 0 deletions lib/Cake/Utility/Security.php
Expand Up @@ -154,4 +154,5 @@ public static function cipher($text, $key) {
srand();
return $out;
}

}
3 changes: 2 additions & 1 deletion lib/Cake/Utility/Set.php
Expand Up @@ -47,7 +47,7 @@ public static function merge($arr1, $arr2 = null) {

$r = (array)current($args);
while (($arg = next($args)) !== false) {
foreach ((array)$arg as $key => $val) {
foreach ((array)$arg as $key => $val) {
if (!empty($r[$key]) && is_array($r[$key]) && is_array($val)) {
$r[$key] = Set::merge($r[$key], $val);
} elseif (is_int($key)) {
Expand Down Expand Up @@ -1214,4 +1214,5 @@ public static function get($input, $path = null) {
}
return $return;
}

}
8 changes: 4 additions & 4 deletions lib/Cake/Utility/String.php
Expand Up @@ -40,13 +40,13 @@ public static function uuid() {
'::', str_repeat(':0000', 8 - substr_count($node, ':')) . ':', $node
);
}
$node = explode(':', $node) ;
$ipv6 = '' ;
$node = explode(':', $node);
$ipv6 = '';

foreach ($node as $id) {
$ipv6 .= str_pad(base_convert($id, 16, 2), 16, 0, STR_PAD_LEFT);
}
$node = base_convert($ipv6, 2, 10);
$node = base_convert($ipv6, 2, 10);

if (strlen($node) < 38) {
$node = null;
Expand Down Expand Up @@ -551,7 +551,7 @@ class_exists('Multibyte');
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::excerpt
*/
public static function excerpt($text, $phrase, $radius = 100, $ending = '...') {
if (empty($text) or empty($phrase)) {
if (empty($text) || empty($phrase)) {
return self::truncate($text, $radius * 2, array('ending' => $ending));
}

Expand Down
4 changes: 3 additions & 1 deletion lib/Cake/Utility/Validation.php
Expand Up @@ -580,7 +580,8 @@ public static function phone($check, $regex = null, $country = 'all') {
case 'us':
case 'all':
case 'can':
// includes all NANPA members. see http://en.wikipedia.org/wiki/North_American_Numbering_Plan#List_of_NANPA_countries_and_territories
// includes all NANPA members.
// see http://en.wikipedia.org/wiki/North_American_Numbering_Plan#List_of_NANPA_countries_and_territories
$regex = '/^(?:\+?1)?[-. ]?\\(?[2-9][0-8][0-9]\\)?[-. ]?[2-9][0-9]{2}[-. ]?[0-9]{4}$/';
break;
}
Expand Down Expand Up @@ -880,4 +881,5 @@ protected static function _populateIp() {
protected static function _reset() {
self::$errors = array();
}

}

0 comments on commit 9d325fe

Please sign in to comment.