euromark 12 years ago
parent
commit
93e6556a54

+ 3 - 3
Console/Command/CopyShell.php

@@ -158,7 +158,8 @@ class CopyShell extends AppShell {
 
 		if (empty($connection) || $connection === 'q') {
 			return $this->error('Aborted!');
-		} elseif ($connection === 'h') {
+		}
+		if ($connection === 'h') {
 			$this->help();
 			return;
 		}
@@ -181,9 +182,8 @@ class CopyShell extends AppShell {
 
 		if (empty($configuration)) {
 			return $this->error('Error...');
-		} else {
-			$this->out('... Config \''.$this->types[$this->type].'_'.$this->configName.'\' selected ...');
 		}
+		$this->out('... Config \''.$this->types[$this->type].'_'.$this->configName.'\' selected ...');
 
 		$hasLocalPath = false;
 		$this->out('');

+ 2 - 1
Console/Command/FolderSyncShell.php

@@ -140,7 +140,8 @@ class FolderSyncShell extends AppShell {
 			$this->removedFiles++;
 			$this->out('   (source missing, deleting)', 1, Shell::VERBOSE);
 			return;
-		} elseif (!$sourceExists) {
+		}
+		if (!$sourceExists) {
 			$this->missing[] = $name;
 			$this->out('   (target missing, skipping)', 1, Shell::VERBOSE);
 			return;

+ 2 - 1
Console/Command/PhpTagShell.php

@@ -86,7 +86,8 @@ class PhpTagShell extends AppShell {
 
 				if ($action === 'q') {
 					return $this->error('Abort... Done');
-				} elseif ($action === 'y') {
+				}
+				if ($action === 'y') {
 					$res = $c;
 					if (in_array('leading', $error)) {
 						$res = preg_replace('/^[\n\r|\n\r|\n|\r|\s]+\<\?php/', '<?php', $res);

+ 5 - 2
Console/Command/WhitespaceShell.php

@@ -82,7 +82,8 @@ class WhitespaceShell extends AppShell {
 			if ($action === 'q') {
 				return $this->error('Abort... Done');
 
-			} elseif ($action === 'y') {
+			}
+			if ($action === 'y') {
 				if ($error === 'leading') {
 					$res = preg_replace('/^[\n\r|\n\r|\n|\r|\s]+\<\?php/', '<?php', $c);
 				} else { //trailing
@@ -95,7 +96,7 @@ class WhitespaceShell extends AppShell {
 			}
 		}
 
-		# report
+		// Report.
 		$this->out('--------');
 		$this->out('found '.$this->report['leading'][0].' leading, '.$this->report['trailing'][0].' trailing ws');
 		$this->out('fixed '.$this->report['leading'][1].' leading, '.$this->report['trailing'][1].' trailing ws');
@@ -103,6 +104,8 @@ class WhitespaceShell extends AppShell {
 
 	/**
 	 * Whitespaces at the end of the file
+	 *
+	 * @return void
 	 */
 	public function eof() {
 		if (!empty($this->args[0])) {

+ 6 - 3
Controller/Component/CommonComponent.php

@@ -1199,7 +1199,8 @@ class CommonComponent extends Component {
 
 		if ($type === 'username') {
 			return $nameParts[0];
-		} elseif ($type === 'hostname') {
+		}
+		if ($type === 'hostname') {
 			return $nameParts[1];
 		}
 
@@ -1447,7 +1448,8 @@ class CommonComponent extends Component {
 	protected function _sortUp($x, $y) {
 		if ($x[1] == $y[1]) {
 			return 0;
-		} elseif ($x[1] < $y[1]) {
+		}
+		if ($x[1] < $y[1]) {
 			return 1;
 		}
 		return - 1;
@@ -1456,7 +1458,8 @@ class CommonComponent extends Component {
 	protected function _sortDown($x, $y) {
 		if ($x[1] == $y[1]) {
 			return 0;
-		} elseif ($x[1] < $y[1]) {
+		}
+		if ($x[1] < $y[1]) {
 			return - 1;
 		}
 		return 1;

+ 2 - 4
Lib/GeocodeLib.php

@@ -231,9 +231,8 @@ class GeocodeLib {
 			}
 			if ($this->options['output'] === 'json') {
 				return $this->_transformJson($this->result);
-			} else {
-				return $this->_transformXml($this->result);
 			}
+			return $this->_transformXml($this->result);
 		}
 		return false;
 	}
@@ -399,9 +398,8 @@ class GeocodeLib {
 					$this->setError('JSON parsing failed');
 					CakeLog::write('geocode', __('Failed with JSON parsing of \'%s\'', $address));
 					return false;
-				} else {
-					$xmlArray['result'] = $xmlArray['results'];
 				}
+				$xmlArray['result'] = $xmlArray['results'];
 				unset($xmlArray['results']);
 
 			} else {

+ 5 - 8
Lib/HttpSocketLib.php

@@ -136,8 +136,8 @@ class HttpSocketLib {
 			}
 			$response = $this->_assertEncoding($response);
 			return $response;
-
-		} elseif ($options['use']['cake']) {
+		}
+		if ($options['use']['cake']) {
 			$this->debug = 'cake';
 
 			$HttpSocket = new HttpSocket(array('timeout' => $options['timeout']));
@@ -147,8 +147,8 @@ class HttpSocketLib {
 			}
 			$response = $this->_assertEncoding($response);
 			return $response;
-
-		} elseif ($options['use']['php']) {
+		}
+		if ($options['use']['php']) {
 			$this->debug = 'php';
 
 			$opts = array(
@@ -176,11 +176,8 @@ class HttpSocketLib {
 			}
 			$response = $this->_assertEncoding($response);
 			return $response;
-
-		} else {
-			throw new CakeException('no protocol given');
 		}
-		return null;
+		throw new CakeException('no protocol given');
 	}
 
 	/**

+ 28 - 37
Lib/ImapLib.php

@@ -179,9 +179,8 @@ class ImapLib {
 	public function close($expunge = false) {
 		if ($expunge) {
 			return @imap_close($this->stream, CL_EXPUNGE);
-		} else {
-			return @imap_close($this->stream);
 		}
+		return @imap_close($this->stream);
 	}
 
 	public function __destruct() {
@@ -379,9 +378,8 @@ class ImapLib {
 				// Perform the search
 				#echo "'$search_string'";
 				return imap_search($this->stream, $search_string);
-			} else {
-				return imap_last_error();
 			}
+			return imap_last_error();
 		}
 
 		return imap_last_error();
@@ -439,11 +437,10 @@ class ImapLib {
 
 				if (count($email_error) === count($emails)) {
 					return imap_last_error();
-				} else {
-					$return['status'] = false;
-					$return['not_deleted'] = $email_error;
-					return $return;
 				}
+				$return['status'] = false;
+				$return['not_deleted'] = $email_error;
+				return $return;
 			}
 		}
 		// Not connected
@@ -482,10 +479,9 @@ class ImapLib {
 			$info = imap_mailboxmsginfo($this->stream);
 			if ($info) {
 				return $info->Mailbox;
-			} else {
-				// There was an error
-				return imap_last_error();
 			}
+			// There was an error
+			return imap_last_error();
 		}
 
 		// Not connected
@@ -499,13 +495,11 @@ class ImapLib {
 				if ($type === 'array') {
 					$info_array = get_object_vars($info);
 					return $info_array;
-				} else {
-					return $info;
 				}
-			} else {
-				// There was an error
-				return imap_last_error();
+				return $info;
 			}
+			// There was an error
+			return imap_last_error();
 		}
 
 		// Not connected
@@ -583,9 +577,8 @@ class ImapMessageInfoLib {
 	public function messageObject() {
 		if (!isset($this->ImapMessage)) {
 			return $this->ImapMessage = new ImapMessageLib($this->ImapFolder, $this->uid, $this);
-		} else {
-			return $this->ImapMessage;
 		}
+		return $this->ImapMessage;
 	}
 
 	public function flag($flag) {
@@ -599,51 +592,51 @@ class ImapMessageInfoLib {
 	public function seen($set = null) {
 		if ($set === null) {
 			return $this->seen;
-		} elseif ($set) {
+		}
+		if ($set) {
 			return $this->flag(self::BS . 'Seen');
-		} else {
-			return $this->unFlag(self::BS . 'Seen');
 		}
+		return $this->unFlag(self::BS . 'Seen');
 	}
 
 	public function answered($set = null) {
 		if ($set === null) {
 			return $this->answered;
-		} elseif ($set) {
+		}
+		if ($set) {
 			return $this->flag(self::BS . 'Answered');
-		} else {
-			return $this->unFlag(self::BS . 'Answered');
 		}
+		return $this->unFlag(self::BS . 'Answered');
 	}
 
 	public function flagged($set = null) {
 		if ($set === null) {
 			return $this->flagged;
-		} elseif ($set) {
+		}
+		if ($set) {
 			return $this->flag(self::BS . 'Flagged');
-		} else {
-			return $this->unFlag(self::BS . 'Flagged');
 		}
+		return $this->unFlag(self::BS . 'Flagged');
 	}
 
 	public function deleted($set = null) {
 		if ($set === null) {
 			return $this->deleted;
-		} elseif ($set) {
+		}
+		if ($set) {
 			return $this->flag(self::BS . 'Deleted');
-		} else {
-			return $this->unFlag(self::BS . 'Deleted');
 		}
+		return $this->unFlag(self::BS . 'Deleted');
 	}
 
 	public function draft($set = null) {
 		if ($set === null) {
 			return $this->draft;
-		} elseif ($set) {
+		}
+		if ($set) {
 			return $this->flag(self::BS . 'Draft');
-		} else {
-			return $this->unFlag(self::BS . 'Draft');
 		}
+		return $this->unFlag(self::BS . 'Draft');
 	}
 
 }
@@ -702,9 +695,8 @@ class ImapMessagesListLib {
 		if (isset($this->messageUIDs[$id])) {
 			if (is_object($this->messageUIDs[$id])) {
 				return $this->messageUIDs[$id];
-			} else {
-				return $this->messageUIDs[$id] = new ImapMessageLib($this->ImapFolder, $this->messageUIDs[$id]);
 			}
+			return $this->messageUIDs[$id] = new ImapMessageLib($this->ImapFolder, $this->messageUIDs[$id]);
 		}
 		return false;
 	}
@@ -722,9 +714,8 @@ class ImapMessagesListLib {
 				$msgObjs[] = new ImapMessageInfoLib($this->ImapFolder, $info);
 			}
 			return $msgObjs;
-		} else {
-			return $overview;
 		}
+		return $overview;
 	}
 
 }

+ 22 - 24
Lib/MimeLib.php

@@ -765,34 +765,32 @@ class MimeLib extends CakeResponse {
 	* @return String $MIMEType - The type of the file passed in the argument
 	*/
 	public function extractMimeType($file = NULL) {
-		if (is_file($file)) {
-			/**
-			* Attempts to retrieve file info from FINFO
-			* If FINFO functions are not available then try to retrieve MIME type from pre-defined MIMEs
-			* If MIME type doesn't exist, then try (as a last resort) to use the (deprecated) mime_content_type function
-			* If all else fails, just return application/octet-stream
-			*/
-			if (!function_exists("finfo_open")) {
-				if (function_exists("mime_content_type")) {
-					$type = mime_content_type($file);
-					if (!empty($type)) {
-						return $type;
-					}
-				}
-				$extension = $this->_getExtension($file);
-				if ($mimeType = $this->getMimeType($extension)) {
-					return $mimeType;
-				} else {
-					return "application/octet-stream";
+		if (!is_file($file)) {
+			return false;
+		}
+		/**
+		* Attempts to retrieve file info from FINFO
+		* If FINFO functions are not available then try to retrieve MIME type from pre-defined MIMEs
+		* If MIME type doesn't exist, then try (as a last resort) to use the (deprecated) mime_content_type function
+		* If all else fails, just return application/octet-stream
+		*/
+		if (!function_exists("finfo_open")) {
+			if (function_exists("mime_content_type")) {
+				$type = mime_content_type($file);
+				if (!empty($type)) {
+					return $type;
 				}
-			} else {
-				$finfo = finfo_open(FILEINFO_MIME_TYPE);
-				$mimeType = finfo_file($finfo, $file);
-				finfo_close($finfo);
+			}
+			$extension = $this->_getExtension($file);
+			if ($mimeType = $this->getMimeType($extension)) {
 				return $mimeType;
 			}
+			return "application/octet-stream";
 		}
-		return false;
+		$finfo = finfo_open(FILEINFO_MIME_TYPE);
+		$mimeType = finfo_file($finfo, $file);
+		finfo_close($finfo);
+		return $mimeType;
 	}
 
 	/**

+ 14 - 16
Lib/Utility/TextAnalysisLib.php

@@ -150,22 +150,20 @@ class TextAnalysisLib extends TextLib {
 				}
 			}
 			return $occ;
-
-		} else {
-
-			$occ = 0;
-			$pos = 0;
-			do {
-				$pos = strpos($str, $char, $pos);
-				if ($pos !== false) {
-					$occ++;
-					$pos++;
-				} else {
-					break;
-				}
-			} while (true);
-			return $occ;
 		}
+
+		$occ = 0;
+		$pos = 0;
+		do {
+			$pos = strpos($str, $char, $pos);
+			if ($pos !== false) {
+				$occ++;
+				$pos++;
+			} else {
+				break;
+			}
+		} while (true);
+		return $occ;
 	}
 
 
@@ -187,7 +185,7 @@ class TextAnalysisLib extends TextLib {
 				$occ = array($key => $value);
 			}
 		}
-		echo returns($occ);
+		//echo returns($occ);
 		return $occ;
 	}
 

+ 27 - 25
Lib/Utility/TimeLib.php

@@ -173,26 +173,27 @@ class TimeLib extends CakeTime {
 
 	/**
 	 * 2011-11-22 lb
+	 * @return mixed
 	 */
 	public static function ageByHoroscope($year, $sign) {
 		App::uses('ZodiacLib', 'Tools.Misc');
 		$Zodiac = new ZodiacLib();
 		$range = $Zodiac->getRange($sign);
 
-		// undefined
+
 		if ($sign == ZodiacLib::SIGN_CAPRICORN) {
+			// undefined
 			return array(date('Y') - $year - 1, date('Y') - $year);
 		}
-		// not over
-		elseif($range[0][0] > date('m') || ($range[0][0] == date('m') && $range[0][1] > date('d'))) {
+		if($range[0][0] > date('m') || ($range[0][0] == date('m') && $range[0][1] > date('d'))) {
+			// not over
 			return date('Y') - $year - 1;
 		}
-		// over
-		elseif ($range[1][0] < date('m') || ($range[1][0] == date('m') && $range[1][1] <= date('d'))) {
+		if ($range[1][0] < date('m') || ($range[1][0] == date('m') && $range[1][1] <= date('d'))) {
+			// over
 			return date('Y') - $year;
-		} else {
-			return array(date('Y') - $year - 1, date('Y') - $year);
 		}
+		return array(date('Y') - $year - 1, date('Y') - $year);
 	}
 
 	/**
@@ -222,10 +223,10 @@ class TimeLib extends CakeTime {
 			$lowerRange = $age - ($age % $steps) + 1;
 			$upperRange = $age - ($age % $steps) + $steps;
 		}
-		if ($lowerRange == $upperRange)
+		if ($lowerRange == $upperRange) {
 			return $upperRange;
-		else
-			return array($lowerRange, $upperRange);
+		}
+		return array($lowerRange, $upperRange);
 	}
 
 	/**
@@ -828,10 +829,12 @@ class TimeLib extends CakeTime {
 		if ($past === true) {
 			// This is in the past
 			return __('%s ago', __($span));
-		} elseif ($past === false) {
+		}
+		if ($past === false) {
 			// This in the future
 			return __('in %s', __($span));
-		} elseif ($past !== null) {
+		}
+		if ($past !== null) {
 			// Custom translation
 			return __($past, __($span));
 		}
@@ -918,7 +921,7 @@ class TimeLib extends CakeTime {
 				$str = floor($seconds % 60);
 				break;
 			default:
-				return "";
+				return '';
 				break;
 			}
 
@@ -981,16 +984,15 @@ class TimeLib extends CakeTime {
 				return sprintf($options['future'], $ret);
 			}
 			return array('future'=>$ret);
-		} elseif ($type == -1) {
+		}
+		if ($type == -1) {
 			if ($options['past'] !== false) {
 				return sprintf($options['past'], $ret);
 			}
 			return array('past'=>$ret);
-		} else {
-			if ($options['verbose'] !== false) {
-				return $options['verbose'];
-			}
-			//return array('now'=>true);
+		}
+		if ($options['verbose'] !== false) {
+			return $options['verbose'];
 		}
 		return $options['default'];
 	}
@@ -1084,7 +1086,7 @@ class TimeLib extends CakeTime {
 
 		if ($format) {
 			$res = DateTime::createFromFormat($format, $date);
-			$res = $res->format(FORMAT_DB_DATE).' '.($type=='end'?'23:59:59':'00:00:00');
+			$res = $res->format(FORMAT_DB_DATE).' '.($type === 'end'?'23:59:59':'00:00:00');
 			return $res;
 		}
 
@@ -1106,12 +1108,12 @@ class TimeLib extends CakeTime {
 			$explode[0] = str_pad($explode[0], 4, '20', STR_PAD_LEFT);
 
 			if (count($explode) === 3) {
-				return implode('-', $explode).' '.($type=='end'?'23:59:59':'00:00:00');
-			} elseif (count($explode) === 2) {
-				return implode('-', $explode).'-'.($type=='end'?self::daysInMonth($explode[0], $explode[1]):'01').' '.($type=='end'?'23:59:59':'00:00:00');
-			} else {
-				return $explode[0].'-'.($type=='end'?'12':'01').'-'.($type=='end'?'31':'01').' '.($type=='end'?'23:59:59':'00:00:00');
+				return implode('-', $explode).' '.($type === 'end'?'23:59:59':'00:00:00');
+			}
+			if (count($explode) === 2) {
+				return implode('-', $explode).'-'.($type === 'end'?self::daysInMonth($explode[0], $explode[1]):'01').' '.($type === 'end' ? '23:59:59':'00:00:00');
 			}
+			return $explode[0].'-'.($type === 'end'?'12':'01').'-'.($type === 'end'?'31':'01').' '.($type === 'end' ? '23:59:59':'00:00:00');
 		}
 
 		return false;