| @@ -32,8 +32,9 @@ | ||
| 32 | 32 | 'id_usuario' => $this->getIdUser(), | 
| 33 | 33 | ); | 
| 34 | 34 | |
| 35 | - if (isset($id_cliente)) | |
| 36 | - $conditions['id'] = $id_cliente; | |
| 35 | +			if (isset($id_cliente)) { | |
| 36 | + $conditions['id'] = $id_cliente; | |
| 37 | + } | |
| 37 | 38 | |
| 38 | 39 | |
| 39 | 40 |  		    $cliente = $this->Cliente->find('all',  | 
| @@ -70,8 +70,7 @@ | ||
| 70 | 70 | } | 
| 71 | 71 | |
| 72 | 72 | return true; | 
| 73 | - } | |
| 74 | - catch (Exception $e) | |
| 73 | + } catch (Exception $e) | |
| 75 | 74 |  		{ | 
| 76 | 75 |  			throw new Exception("Error Processing Request", 1); | 
| 77 | 76 | } | 
| @@ -63,8 +63,9 @@ discard block | ||
| 63 | 63 |  		if (!empty($image['name'])) { | 
| 64 | 64 | $retorno = $this->uploadImage($image); | 
| 65 | 65 | |
| 66 | - if (!$retorno['status']) | |
| 67 | -				$this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); | |
| 66 | +			if (!$retorno['status']) { | |
| 67 | +							$this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); | |
| 68 | + } | |
| 68 | 69 | |
| 69 | 70 | $dados['imagem'] = $retorno['nome']; | 
| 70 | 71 | } | 
| @@ -91,8 +92,9 @@ discard block | ||
| 91 | 92 | |
| 92 | 93 | $retorno = $this->uploadImage($image); | 
| 93 | 94 | |
| 94 | - if (!$retorno['status']) | |
| 95 | -			$this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); | |
| 95 | +		if (!$retorno['status']) { | |
| 96 | +					$this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); | |
| 97 | + } | |
| 96 | 98 | |
| 97 | 99 | $dados['src'] = $retorno['nome']; | 
| 98 | 100 | $dados['usuario_id'] = $this->instancia; | 
| @@ -114,8 +116,9 @@ discard block | ||
| 114 | 116 | |
| 115 | 117 | $returnUpload = move_uploaded_file($image['tmp_name'], $dir . $nameImage); | 
| 116 | 118 | |
| 117 | - if (!$returnUpload) | |
| 118 | -			return array('nome' => null, 'status' => false); | |
| 119 | +		if (!$returnUpload) { | |
| 120 | +					return array('nome' => null, 'status' => false); | |
| 121 | + } | |
| 119 | 122 | |
| 120 | 123 |  		return array('nome' => $nameImage, 'status' => true); | 
| 121 | 124 | } | 
| @@ -60,8 +60,9 @@ discard block | ||
| 60 | 60 |  		if ($this->_currentCellIsDirty) { | 
| 61 | 61 | $this->_currentObject->detach(); | 
| 62 | 62 | |
| 63 | -			if (!$this->_DBHandle->queryExec("INSERT OR REPLACE INTO kvp_".$this->_TableName." VALUES('".$this->_currentObjectID."','".sqlite_escape_string(serialize($this->_currentObject))."')")) | |
| 64 | - throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); | |
| 63 | +			if (!$this->_DBHandle->queryExec("INSERT OR REPLACE INTO kvp_".$this->_TableName." VALUES('".$this->_currentObjectID."','".sqlite_escape_string(serialize($this->_currentObject))."')")) { | |
| 64 | + throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); | |
| 65 | + } | |
| 65 | 66 | $this->_currentCellIsDirty = false; | 
| 66 | 67 | } | 
| 67 | 68 | $this->_currentObjectID = $this->_currentObject = null; | 
| @@ -162,8 +163,9 @@ discard block | ||
| 162 | 163 | |
| 163 | 164 | // Check if the requested entry exists in the cache | 
| 164 | 165 | $query = "DELETE FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'"; | 
| 165 | - if (!$this->_DBHandle->queryExec($query)) | |
| 166 | - throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); | |
| 166 | +		if (!$this->_DBHandle->queryExec($query)) { | |
| 167 | + throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); | |
| 168 | + } | |
| 167 | 169 | |
| 168 | 170 | $this->_currentCellIsDirty = false; | 
| 169 | 171 | } // function deleteCacheData() | 
| @@ -177,8 +179,9 @@ discard block | ||
| 177 | 179 |  	public function getCellList() { | 
| 178 | 180 | $query = "SELECT id FROM kvp_".$this->_TableName; | 
| 179 | 181 | $cellIdsResult = $this->_DBHandle->unbufferedQuery($query,SQLITE_ASSOC); | 
| 180 | - if ($cellIdsResult === false) | |
| 181 | - throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); | |
| 182 | +		if ($cellIdsResult === false) { | |
| 183 | + throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); | |
| 184 | + } | |
| 182 | 185 | |
| 183 | 186 | $cellKeys = array(); | 
| 184 | 187 |  		foreach($cellIdsResult as $row) { | 
| @@ -199,8 +202,9 @@ discard block | ||
| 199 | 202 | // Get a new id for the new table name | 
| 200 | 203 |  		$tableName = str_replace('.','_',$this->_getUniqueID()); | 
| 201 | 204 |  		if (!$this->_DBHandle->queryExec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB) | 
| 202 | - AS SELECT * FROM kvp_'.$this->_TableName)) | |
| 203 | - throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); | |
| 205 | +													AS SELECT * FROM kvp_'.$this->_TableName)) { | |
| 206 | + throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); | |
| 207 | + } | |
| 204 | 208 | |
| 205 | 209 | // Copy the existing cell cache file | 
| 206 | 210 | $this->_TableName = $tableName; | 
| @@ -237,10 +241,12 @@ discard block | ||
| 237 | 241 | $_DBName = ':memory:'; | 
| 238 | 242 | |
| 239 | 243 | $this->_DBHandle = new SQLiteDatabase($_DBName); | 
| 240 | - if ($this->_DBHandle === false) | |
| 241 | - throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); | |
| 242 | -			if (!$this->_DBHandle->queryExec('CREATE TABLE kvp_'.$this->_TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)')) | |
| 243 | - throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); | |
| 244 | +			if ($this->_DBHandle === false) { | |
| 245 | + throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); | |
| 246 | + } | |
| 247 | +			if (!$this->_DBHandle->queryExec('CREATE TABLE kvp_'.$this->_TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)')) { | |
| 248 | + throw new Exception(sqlite_error_string($this->_DBHandle->lastError())); | |
| 249 | + } | |
| 244 | 250 | } | 
| 245 | 251 | } // function __construct() | 
| 246 | 252 | |
| @@ -64,8 +64,9 @@ discard block | ||
| 64 | 64 |  			$query->bindValue('id',$this->_currentObjectID,SQLITE3_TEXT); | 
| 65 | 65 |  			$query->bindValue('data',serialize($this->_currentObject),SQLITE3_BLOB); | 
| 66 | 66 | $result = $query->execute(); | 
| 67 | - if ($result === false) | |
| 68 | - throw new Exception($this->_DBHandle->lastErrorMsg()); | |
| 67 | +			if ($result === false) { | |
| 68 | + throw new Exception($this->_DBHandle->lastErrorMsg()); | |
| 69 | + } | |
| 69 | 70 | $this->_currentCellIsDirty = false; | 
| 70 | 71 | } | 
| 71 | 72 | $this->_currentObjectID = $this->_currentObject = null; | 
| @@ -166,8 +167,9 @@ discard block | ||
| 166 | 167 | // Check if the requested entry exists in the cache | 
| 167 | 168 | $query = "DELETE FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'"; | 
| 168 | 169 | $result = $this->_DBHandle->exec($query); | 
| 169 | - if ($result === false) | |
| 170 | - throw new Exception($this->_DBHandle->lastErrorMsg()); | |
| 170 | +		if ($result === false) { | |
| 171 | + throw new Exception($this->_DBHandle->lastErrorMsg()); | |
| 172 | + } | |
| 171 | 173 | |
| 172 | 174 | $this->_currentCellIsDirty = false; | 
| 173 | 175 | } // function deleteCacheData() | 
| @@ -181,8 +183,9 @@ discard block | ||
| 181 | 183 |  	public function getCellList() { | 
| 182 | 184 | $query = "SELECT id FROM kvp_".$this->_TableName; | 
| 183 | 185 | $cellIdsResult = $this->_DBHandle->query($query); | 
| 184 | - if ($cellIdsResult === false) | |
| 185 | - throw new Exception($this->_DBHandle->lastErrorMsg()); | |
| 186 | +		if ($cellIdsResult === false) { | |
| 187 | + throw new Exception($this->_DBHandle->lastErrorMsg()); | |
| 188 | + } | |
| 186 | 189 | |
| 187 | 190 | $cellKeys = array(); | 
| 188 | 191 |  		while ($row = $cellIdsResult->fetchArray(SQLITE3_ASSOC)) { | 
| @@ -203,8 +206,9 @@ discard block | ||
| 203 | 206 | // Get a new id for the new table name | 
| 204 | 207 |  		$tableName = str_replace('.','_',$this->_getUniqueID()); | 
| 205 | 208 |  		if (!$this->_DBHandle->exec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB) | 
| 206 | - AS SELECT * FROM kvp_'.$this->_TableName)) | |
| 207 | - throw new Exception($this->_DBHandle->lastErrorMsg()); | |
| 209 | +		                                       AS SELECT * FROM kvp_'.$this->_TableName)) { | |
| 210 | + throw new Exception($this->_DBHandle->lastErrorMsg()); | |
| 211 | + } | |
| 208 | 212 | |
| 209 | 213 | // Copy the existing cell cache file | 
| 210 | 214 | $this->_TableName = $tableName; | 
| @@ -241,10 +245,12 @@ discard block | ||
| 241 | 245 | $_DBName = ':memory:'; | 
| 242 | 246 | |
| 243 | 247 | $this->_DBHandle = new SQLite3($_DBName); | 
| 244 | - if ($this->_DBHandle === false) | |
| 245 | - throw new Exception($this->_DBHandle->lastErrorMsg()); | |
| 246 | -			if (!$this->_DBHandle->exec('CREATE TABLE kvp_'.$this->_TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)')) | |
| 247 | - throw new Exception($this->_DBHandle->lastErrorMsg()); | |
| 248 | +			if ($this->_DBHandle === false) { | |
| 249 | + throw new Exception($this->_DBHandle->lastErrorMsg()); | |
| 250 | + } | |
| 251 | +			if (!$this->_DBHandle->exec('CREATE TABLE kvp_'.$this->_TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)')) { | |
| 252 | + throw new Exception($this->_DBHandle->lastErrorMsg()); | |
| 253 | + } | |
| 248 | 254 | } | 
| 249 | 255 | } // function __construct() | 
| 250 | 256 | |
| @@ -2208,9 +2208,13 @@ discard block | ||
| 2208 | 2208 | // Basic validation that this is indeed a formula | 
| 2209 | 2209 | // We return an empty array if not | 
| 2210 | 2210 | $formula = trim($formula); | 
| 2211 | -		if ((!isset($formula{0})) || ($formula{0} != '=')) return array(); | |
| 2211 | +		if ((!isset($formula{0})) || ($formula{0} != '=')) { | |
| 2212 | + return array(); | |
| 2213 | + } | |
| 2212 | 2214 | $formula = ltrim(substr($formula,1)); | 
| 2213 | -		if (!isset($formula{0})) return array(); | |
| 2215 | +		if (!isset($formula{0})) { | |
| 2216 | + return array(); | |
| 2217 | + } | |
| 2214 | 2218 | |
| 2215 | 2219 | // Parse the formula and return the token stack | 
| 2216 | 2220 | return $this->_parseFormula($formula); | 
| @@ -2263,9 +2267,13 @@ discard block | ||
| 2263 | 2267 | // Basic validation that this is indeed a formula | 
| 2264 | 2268 | // We simply return the "cell value" (formula) if not | 
| 2265 | 2269 | $formula = trim($formula); | 
| 2266 | -		if ($formula{0} != '=') return self::_wrapResult($formula); | |
| 2270 | +		if ($formula{0} != '=') { | |
| 2271 | + return self::_wrapResult($formula); | |
| 2272 | + } | |
| 2267 | 2273 | $formula = ltrim(substr($formula,1)); | 
| 2268 | -		if (!isset($formula{0})) return self::_wrapResult($formula); | |
| 2274 | +		if (!isset($formula{0})) { | |
| 2275 | + return self::_wrapResult($formula); | |
| 2276 | + } | |
| 2269 | 2277 | |
| 2270 | 2278 | $wsTitle = "\x00Wrk"; | 
| 2271 | 2279 |  		if ($pCell !== NULL) { | 
| @@ -2715,8 +2723,11 @@ discard block | ||
| 2715 | 2723 | // echo 'Element is a Closing bracket<br />'; | 
| 2716 | 2724 | $expectingOperand = false; | 
| 2717 | 2725 |  				while (($o2 = $stack->pop()) && $o2['value'] != '(') {		//	Pop off the stack back to the last ( | 
| 2718 | -					if ($o2 === NULL) return $this->_raiseFormulaError('Formula Error: Unexpected closing brace ")"'); | |
| 2719 | - else $output[] = $o2; | |
| 2726 | +					if ($o2 === NULL) { | |
| 2727 | +						return $this->_raiseFormulaError('Formula Error: Unexpected closing brace ")"'); | |
| 2728 | +					} else { | |
| 2729 | + $output[] = $o2; | |
| 2730 | + } | |
| 2720 | 2731 | } | 
| 2721 | 2732 | $d = $stack->last(2); | 
| 2722 | 2733 |  				if (preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i', $d['value'], $matches)) {	//	Did this parenthesis just close a function? | 
| @@ -2794,8 +2805,12 @@ discard block | ||
| 2794 | 2805 |  			} elseif ($opCharacter == ',') {			//	Is this the separator for function arguments? | 
| 2795 | 2806 | // echo 'Element is a Function argument separator<br />'; | 
| 2796 | 2807 |  				while (($o2 = $stack->pop()) && $o2['value'] != '(') {		//	Pop off the stack back to the last ( | 
| 2797 | -					if ($o2 === NULL) return $this->_raiseFormulaError("Formula Error: Unexpected ,"); | |
| 2798 | - else $output[] = $o2; // pop the argument expression stuff and push onto the output | |
| 2808 | +					if ($o2 === NULL) { | |
| 2809 | +						return $this->_raiseFormulaError("Formula Error: Unexpected ,"); | |
| 2810 | +					} else { | |
| 2811 | + $output[] = $o2; | |
| 2812 | + } | |
| 2813 | + // pop the argument expression stuff and push onto the output | |
| 2799 | 2814 | } | 
| 2800 | 2815 | // If we've a comma when we're expecting an operand, then what we actually have is a null operand; | 
| 2801 | 2816 | // so push a null onto the stack | 
| @@ -2804,8 +2819,9 @@ discard block | ||
| 2804 | 2819 | } | 
| 2805 | 2820 | // make sure there was a function | 
| 2806 | 2821 | $d = $stack->last(2); | 
| 2807 | -				if (!preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i', $d['value'], $matches)) | |
| 2808 | -					return $this->_raiseFormulaError("Formula Error: Unexpected ,"); | |
| 2822 | +				if (!preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i', $d['value'], $matches)) { | |
| 2823 | +									return $this->_raiseFormulaError("Formula Error: Unexpected ,"); | |
| 2824 | + } | |
| 2809 | 2825 | $d = $stack->pop(); | 
| 2810 | 2826 | $stack->push($d['type'],++$d['value'],$d['reference']); // increment the argument count | 
| 2811 | 2827 |  				$stack->push('Brace', '(');	// put the ( back on, we'll need to pop back to it again | 
| @@ -2876,12 +2892,16 @@ discard block | ||
| 2876 | 2892 |  						if (strpos('!',$startRowColRef) !== false) { | 
| 2877 | 2893 |  							list($rangeWS1,$startRowColRef) = explode('!',$startRowColRef); | 
| 2878 | 2894 | } | 
| 2879 | - if ($rangeWS1 != '') $rangeWS1 .= '!'; | |
| 2895 | +						if ($rangeWS1 != '') { | |
| 2896 | + $rangeWS1 .= '!'; | |
| 2897 | + } | |
| 2880 | 2898 | $rangeWS2 = $rangeWS1; | 
| 2881 | 2899 |  						if (strpos('!',$val) !== false) { | 
| 2882 | 2900 |  							list($rangeWS2,$val) = explode('!',$val); | 
| 2883 | 2901 | } | 
| 2884 | - if ($rangeWS2 != '') $rangeWS2 .= '!'; | |
| 2902 | +						if ($rangeWS2 != '') { | |
| 2903 | + $rangeWS2 .= '!'; | |
| 2904 | + } | |
| 2885 | 2905 | if ((is_integer($startRowColRef)) && (ctype_digit($val)) && | 
| 2886 | 2906 |  							($startRowColRef <= 1048576) && ($val <= 1048576)) { | 
| 2887 | 2907 | // Row range | 
| @@ -2977,8 +2997,10 @@ discard block | ||
| 2977 | 2997 | } | 
| 2978 | 2998 | |
| 2979 | 2999 |  		while (($op = $stack->pop()) !== NULL) {	// pop everything off the stack and push onto output | 
| 2980 | -			if ((is_array($opCharacter) && $opCharacter['value'] == '(') || ($opCharacter === '(')) | |
| 2981 | -				return $this->_raiseFormulaError("Formula Error: Expecting ')'");	// if there are any opening braces on the stack, then braces were unbalanced | |
| 3000 | +			if ((is_array($opCharacter) && $opCharacter['value'] == '(') || ($opCharacter === '(')) { | |
| 3001 | +							return $this->_raiseFormulaError("Formula Error: Expecting ')'"); | |
| 3002 | + } | |
| 3003 | + // if there are any opening braces on the stack, then braces were unbalanced | |
| 2982 | 3004 | $output[] = $op; | 
| 2983 | 3005 | } | 
| 2984 | 3006 | return $output; | 
| @@ -3002,7 +3024,9 @@ discard block | ||
| 3002 | 3024 | |
| 3003 | 3025 | // evaluate postfix notation | 
| 3004 | 3026 |  	private function _processTokenStack($tokens, $cellID = null, PHPExcel_Cell $pCell = null) { | 
| 3005 | - if ($tokens == false) return false; | |
| 3027 | +		if ($tokens == false) { | |
| 3028 | + return false; | |
| 3029 | + } | |
| 3006 | 3030 | |
| 3007 | 3031 | // If we're using cell caching, then $pCell may well be flushed back to the cache (which detaches the parent worksheet), | 
| 3008 | 3032 | // so we store the parent worksheet so that we can re-attach it when necessary | 
| @@ -3019,8 +3043,12 @@ discard block | ||
| 3019 | 3043 |  			if (isset(self::$_binaryOperators[$token])) { | 
| 3020 | 3044 | // echo 'Token is a binary operator<br />'; | 
| 3021 | 3045 | // We must have two operands, error if we don't | 
| 3022 | -				if (($operand2Data = $stack->pop()) === NULL) return $this->_raiseFormulaError('Internal error - Operand value missing from stack'); | |
| 3023 | -				if (($operand1Data = $stack->pop()) === NULL) return $this->_raiseFormulaError('Internal error - Operand value missing from stack'); | |
| 3046 | +				if (($operand2Data = $stack->pop()) === NULL) { | |
| 3047 | +					return $this->_raiseFormulaError('Internal error - Operand value missing from stack'); | |
| 3048 | + } | |
| 3049 | +				if (($operand1Data = $stack->pop()) === NULL) { | |
| 3050 | +					return $this->_raiseFormulaError('Internal error - Operand value missing from stack'); | |
| 3051 | + } | |
| 3024 | 3052 | |
| 3025 | 3053 | $operand1 = self::_dataTestReference($operand1Data); | 
| 3026 | 3054 | $operand2 = self::_dataTestReference($operand2Data); | 
| @@ -3158,7 +3186,9 @@ discard block | ||
| 3158 | 3186 | // if the token is a unary operator, pop one value off the stack, do the operation, and push it back on | 
| 3159 | 3187 |  			} elseif (($token === '~') || ($token === '%')) { | 
| 3160 | 3188 | // echo 'Token is a unary operator<br />'; | 
| 3161 | -				if (($arg = $stack->pop()) === NULL) return $this->_raiseFormulaError('Internal error - Operand value missing from stack'); | |
| 3189 | +				if (($arg = $stack->pop()) === NULL) { | |
| 3190 | +					return $this->_raiseFormulaError('Internal error - Operand value missing from stack'); | |
| 3191 | + } | |
| 3162 | 3192 | $arg = $arg['value']; | 
| 3163 | 3193 |  				if ($token === '~') { | 
| 3164 | 3194 | // echo 'Token is a negation operator<br />'; | 
| @@ -3388,7 +3418,9 @@ discard block | ||
| 3388 | 3418 | } | 
| 3389 | 3419 | } | 
| 3390 | 3420 | // when we're out of tokens, the stack should have a single element, the final result | 
| 3391 | -		if ($stack->count() != 1) return $this->_raiseFormulaError("internal error"); | |
| 3421 | +		if ($stack->count() != 1) { | |
| 3422 | +			return $this->_raiseFormulaError("internal error"); | |
| 3423 | + } | |
| 3392 | 3424 | $output = $stack->pop(); | 
| 3393 | 3425 | $output = $output['value']; | 
| 3394 | 3426 | |
| @@ -3502,8 +3534,12 @@ discard block | ||
| 3502 | 3534 | |
| 3503 | 3535 |  	private function _executeNumericBinaryOperation($cellID,$operand1,$operand2,$operation,$matrixFunction,&$stack) { | 
| 3504 | 3536 | // Validate the two operands | 
| 3505 | - if (!$this->_validateBinaryOperand($cellID,$operand1,$stack)) return false; | |
| 3506 | - if (!$this->_validateBinaryOperand($cellID,$operand2,$stack)) return false; | |
| 3537 | +		if (!$this->_validateBinaryOperand($cellID,$operand1,$stack)) { | |
| 3538 | + return false; | |
| 3539 | + } | |
| 3540 | +		if (!$this->_validateBinaryOperand($cellID,$operand2,$stack)) { | |
| 3541 | + return false; | |
| 3542 | + } | |
| 3507 | 3543 | |
| 3508 | 3544 | $executeMatrixOperation = false; | 
| 3509 | 3545 | // If either of the operands is a matrix, we need to treat them both as matrices | 
| @@ -3595,7 +3631,9 @@ discard block | ||
| 3595 | 3631 |  	protected function _raiseFormulaError($errorMessage) { | 
| 3596 | 3632 | $this->formulaError = $errorMessage; | 
| 3597 | 3633 | $this->debugLogStack = array(); | 
| 3598 | - if (!$this->suppressFormulaErrors) throw new Exception($errorMessage); | |
| 3634 | +		if (!$this->suppressFormulaErrors) { | |
| 3635 | + throw new Exception($errorMessage); | |
| 3636 | + } | |
| 3599 | 3637 | trigger_error($errorMessage, E_USER_ERROR); | 
| 3600 | 3638 | } // function _raiseFormulaError() | 
| 3601 | 3639 | |
| @@ -515,8 +515,9 @@ discard block | ||
| 515 | 515 |  		if (($PHPDateArray !== False) && ($PHPDateArray['error_count'] == 0)) { | 
| 516 | 516 | // Execute function | 
| 517 | 517 |  			if ($PHPDateArray['year'] == '')	{ $PHPDateArray['year'] = strftime('%Y'); } | 
| 518 | - if ($PHPDateArray['year'] < 1900) | |
| 519 | - return PHPExcel_Calculation_Functions::VALUE(); | |
| 518 | +			if ($PHPDateArray['year'] < 1900) { | |
| 519 | + return PHPExcel_Calculation_Functions::VALUE(); | |
| 520 | + } | |
| 520 | 521 |  			if ($PHPDateArray['month'] == '')	{ $PHPDateArray['month'] = strftime('%m'); } | 
| 521 | 522 |  			if ($PHPDateArray['day'] == '')		{ $PHPDateArray['day'] = strftime('%d'); } | 
| 522 | 523 | $excelDateValue = floor(PHPExcel_Shared_Date::FormattedPHPToExcel($PHPDateArray['year'],$PHPDateArray['month'],$PHPDateArray['day'],$PHPDateArray['hour'],$PHPDateArray['minute'],$PHPDateArray['second'])); | 
| @@ -656,7 +657,9 @@ discard block | ||
| 656 | 657 | break; | 
| 657 | 658 | case 'YM': | 
| 658 | 659 | $retVal = intval($endMonths - $startMonths); | 
| 659 | - if ($retVal < 0) $retVal = 12 + $retVal; | |
| 660 | +				if ($retVal < 0) { | |
| 661 | + $retVal = 12 + $retVal; | |
| 662 | + } | |
| 660 | 663 | // We're only interested in full months | 
| 661 | 664 |  				if ($endDays < $startDays) { | 
| 662 | 665 | --$retVal; | 
| @@ -749,10 +749,18 @@ discard block | ||
| 749 | 749 | * @return string The "cleaned" complex number | 
| 750 | 750 | */ | 
| 751 | 751 |  	private static function _cleanComplex($complexNumber) { | 
| 752 | -		if ($complexNumber{0} == '+') $complexNumber = substr($complexNumber,1); | |
| 753 | -		if ($complexNumber{0} == '0') $complexNumber = substr($complexNumber,1); | |
| 754 | -		if ($complexNumber{0} == '.') $complexNumber = '0'.$complexNumber; | |
| 755 | -		if ($complexNumber{0} == '+') $complexNumber = substr($complexNumber,1); | |
| 752 | +		if ($complexNumber{0} == '+') { | |
| 753 | + $complexNumber = substr($complexNumber,1); | |
| 754 | + } | |
| 755 | +		if ($complexNumber{0} == '0') { | |
| 756 | + $complexNumber = substr($complexNumber,1); | |
| 757 | + } | |
| 758 | +		if ($complexNumber{0} == '.') { | |
| 759 | + $complexNumber = '0'.$complexNumber; | |
| 760 | + } | |
| 761 | +		if ($complexNumber{0} == '+') { | |
| 762 | + $complexNumber = substr($complexNumber,1); | |
| 763 | + } | |
| 756 | 764 | return $complexNumber; | 
| 757 | 765 | } | 
| 758 | 766 | |
| @@ -1658,7 +1666,9 @@ discard block | ||
| 1658 | 1666 | $realNumber = (float) $realNumber; | 
| 1659 | 1667 | $imaginary = (float) $imaginary; | 
| 1660 | 1668 | |
| 1661 | - if ($suffix == '') $suffix = 'i'; | |
| 1669 | +			if ($suffix == '') { | |
| 1670 | + $suffix = 'i'; | |
| 1671 | + } | |
| 1662 | 1672 |  			if ($realNumber == 0.0) { | 
| 1663 | 1673 |  				if ($imaginary == 0.0) { | 
| 1664 | 1674 | return (string) '0'; | 
| @@ -1304,7 +1304,9 @@ discard block | ||
| 1304 | 1304 | |
| 1305 | 1305 | |
| 1306 | 1306 |  	public static function IRR($values, $guess = 0.1) { | 
| 1307 | - if (!is_array($values)) return PHPExcel_Calculation_Functions::VALUE(); | |
| 1307 | +		if (!is_array($values)) { | |
| 1308 | + return PHPExcel_Calculation_Functions::VALUE(); | |
| 1309 | + } | |
| 1308 | 1310 | $values = PHPExcel_Calculation_Functions::flattenArray($values); | 
| 1309 | 1311 | $guess = PHPExcel_Calculation_Functions::flattenSingleValue($guess); | 
| 1310 | 1312 | |
| @@ -1314,14 +1316,18 @@ discard block | ||
| 1314 | 1316 | $f1 = self::NPV($x1, $values); | 
| 1315 | 1317 | $f2 = self::NPV($x2, $values); | 
| 1316 | 1318 |  		for ($i = 0; $i < FINANCIAL_MAX_ITERATIONS; ++$i) { | 
| 1317 | - if (($f1 * $f2) < 0.0) break; | |
| 1319 | +			if (($f1 * $f2) < 0.0) { | |
| 1320 | + break; | |
| 1321 | + } | |
| 1318 | 1322 |  			if (abs($f1) < abs($f2)) { | 
| 1319 | 1323 | $f1 = self::NPV($x1 += 1.6 * ($x1 - $x2), $values); | 
| 1320 | 1324 |  			} else { | 
| 1321 | 1325 | $f2 = self::NPV($x2 += 1.6 * ($x2 - $x1), $values); | 
| 1322 | 1326 | } | 
| 1323 | 1327 | } | 
| 1324 | - if (($f1 * $f2) > 0.0) return PHPExcel_Calculation_Functions::VALUE(); | |
| 1328 | +		if (($f1 * $f2) > 0.0) { | |
| 1329 | + return PHPExcel_Calculation_Functions::VALUE(); | |
| 1330 | + } | |
| 1325 | 1331 | |
| 1326 | 1332 | $f = self::NPV($x1, $values); | 
| 1327 | 1333 |  		if ($f < 0.0) { | 
| @@ -1336,8 +1342,12 @@ discard block | ||
| 1336 | 1342 | $dx *= 0.5; | 
| 1337 | 1343 | $x_mid = $rtb + $dx; | 
| 1338 | 1344 | $f_mid = self::NPV($x_mid, $values); | 
| 1339 | - if ($f_mid <= 0.0) $rtb = $x_mid; | |
| 1340 | - if ((abs($f_mid) < FINANCIAL_PRECISION) || (abs($dx) < FINANCIAL_PRECISION)) return $x_mid; | |
| 1345 | +			if ($f_mid <= 0.0) { | |
| 1346 | + $rtb = $x_mid; | |
| 1347 | + } | |
| 1348 | +			if ((abs($f_mid) < FINANCIAL_PRECISION) || (abs($dx) < FINANCIAL_PRECISION)) { | |
| 1349 | + return $x_mid; | |
| 1350 | + } | |
| 1341 | 1351 | } | 
| 1342 | 1352 | return PHPExcel_Calculation_Functions::VALUE(); | 
| 1343 | 1353 | } // function IRR() | 
| @@ -1385,7 +1395,9 @@ discard block | ||
| 1385 | 1395 | |
| 1386 | 1396 | |
| 1387 | 1397 |  	public static function MIRR($values, $finance_rate, $reinvestment_rate) { | 
| 1388 | - if (!is_array($values)) return PHPExcel_Calculation_Functions::VALUE(); | |
| 1398 | +		if (!is_array($values)) { | |
| 1399 | + return PHPExcel_Calculation_Functions::VALUE(); | |
| 1400 | + } | |
| 1389 | 1401 | $values = PHPExcel_Calculation_Functions::flattenArray($values); | 
| 1390 | 1402 | $finance_rate = PHPExcel_Calculation_Functions::flattenSingleValue($finance_rate); | 
| 1391 | 1403 | $reinvestment_rate = PHPExcel_Calculation_Functions::flattenSingleValue($reinvestment_rate); | 
| @@ -1810,8 +1822,9 @@ discard block | ||
| 1810 | 1822 | $rate = ($y1 * $x0 - $y0 * $x1) / ($y1 - $y0); | 
| 1811 | 1823 | $x0 = $x1; | 
| 1812 | 1824 | $x1 = $rate; | 
| 1813 | - if (($nper * abs($pmt)) > ($pv - $fv)) | |
| 1814 | - $x1 = abs($x1); | |
| 1825 | +			if (($nper * abs($pmt)) > ($pv - $fv)) { | |
| 1826 | + $x1 = abs($x1); | |
| 1827 | + } | |
| 1815 | 1828 | |
| 1816 | 1829 |  			if (abs($rate) < FINANCIAL_PRECISION) { | 
| 1817 | 1830 | $y = $pv * (1 + $nper * $rate) + $pmt * (1 + $rate * $type) * $nper + $fv; | 
| @@ -2060,11 +2073,15 @@ discard block | ||
| 2060 | 2073 | |
| 2061 | 2074 | |
| 2062 | 2075 |  	public static function XIRR($values, $dates, $guess = 0.1) { | 
| 2063 | - if ((!is_array($values)) && (!is_array($dates))) return PHPExcel_Calculation_Functions::VALUE(); | |
| 2076 | +		if ((!is_array($values)) && (!is_array($dates))) { | |
| 2077 | + return PHPExcel_Calculation_Functions::VALUE(); | |
| 2078 | + } | |
| 2064 | 2079 | $values = PHPExcel_Calculation_Functions::flattenArray($values); | 
| 2065 | 2080 | $dates = PHPExcel_Calculation_Functions::flattenArray($dates); | 
| 2066 | 2081 | $guess = PHPExcel_Calculation_Functions::flattenSingleValue($guess); | 
| 2067 | - if (count($values) != count($dates)) return PHPExcel_Calculation_Functions::NaN(); | |
| 2082 | +		if (count($values) != count($dates)) { | |
| 2083 | + return PHPExcel_Calculation_Functions::NaN(); | |
| 2084 | + } | |
| 2068 | 2085 | |
| 2069 | 2086 | // create an initial range, with a root somewhere between 0 and guess | 
| 2070 | 2087 | $x1 = 0.0; | 
| @@ -2072,14 +2089,18 @@ discard block | ||
| 2072 | 2089 | $f1 = self::XNPV($x1, $values, $dates); | 
| 2073 | 2090 | $f2 = self::XNPV($x2, $values, $dates); | 
| 2074 | 2091 |  		for ($i = 0; $i < FINANCIAL_MAX_ITERATIONS; ++$i) { | 
| 2075 | - if (($f1 * $f2) < 0.0) break; | |
| 2092 | +			if (($f1 * $f2) < 0.0) { | |
| 2093 | + break; | |
| 2094 | + } | |
| 2076 | 2095 |  			if (abs($f1) < abs($f2)) { | 
| 2077 | 2096 | $f1 = self::XNPV($x1 += 1.6 * ($x1 - $x2), $values, $dates); | 
| 2078 | 2097 |  			} else { | 
| 2079 | 2098 | $f2 = self::XNPV($x2 += 1.6 * ($x2 - $x1), $values, $dates); | 
| 2080 | 2099 | } | 
| 2081 | 2100 | } | 
| 2082 | - if (($f1 * $f2) > 0.0) return PHPExcel_Calculation_Functions::VALUE(); | |
| 2101 | +		if (($f1 * $f2) > 0.0) { | |
| 2102 | + return PHPExcel_Calculation_Functions::VALUE(); | |
| 2103 | + } | |
| 2083 | 2104 | |
| 2084 | 2105 | $f = self::XNPV($x1, $values, $dates); | 
| 2085 | 2106 |  		if ($f < 0.0) { | 
| @@ -2094,8 +2115,12 @@ discard block | ||
| 2094 | 2115 | $dx *= 0.5; | 
| 2095 | 2116 | $x_mid = $rtb + $dx; | 
| 2096 | 2117 | $f_mid = self::XNPV($x_mid, $values, $dates); | 
| 2097 | - if ($f_mid <= 0.0) $rtb = $x_mid; | |
| 2098 | - if ((abs($f_mid) < FINANCIAL_PRECISION) || (abs($dx) < FINANCIAL_PRECISION)) return $x_mid; | |
| 2118 | +			if ($f_mid <= 0.0) { | |
| 2119 | + $rtb = $x_mid; | |
| 2120 | + } | |
| 2121 | +			if ((abs($f_mid) < FINANCIAL_PRECISION) || (abs($dx) < FINANCIAL_PRECISION)) { | |
| 2122 | + return $x_mid; | |
| 2123 | + } | |
| 2099 | 2124 | } | 
| 2100 | 2125 | return PHPExcel_Calculation_Functions::VALUE(); | 
| 2101 | 2126 | } | 
| @@ -2117,17 +2142,27 @@ discard block | ||
| 2117 | 2142 | */ | 
| 2118 | 2143 |  	public static function XNPV($rate, $values, $dates) { | 
| 2119 | 2144 | $rate = PHPExcel_Calculation_Functions::flattenSingleValue($rate); | 
| 2120 | - if (!is_numeric($rate)) return PHPExcel_Calculation_Functions::VALUE(); | |
| 2121 | - if ((!is_array($values)) || (!is_array($dates))) return PHPExcel_Calculation_Functions::VALUE(); | |
| 2145 | +		if (!is_numeric($rate)) { | |
| 2146 | + return PHPExcel_Calculation_Functions::VALUE(); | |
| 2147 | + } | |
| 2148 | +		if ((!is_array($values)) || (!is_array($dates))) { | |
| 2149 | + return PHPExcel_Calculation_Functions::VALUE(); | |
| 2150 | + } | |
| 2122 | 2151 | $values = PHPExcel_Calculation_Functions::flattenArray($values); | 
| 2123 | 2152 | $dates = PHPExcel_Calculation_Functions::flattenArray($dates); | 
| 2124 | 2153 | $valCount = count($values); | 
| 2125 | - if ($valCount != count($dates)) return PHPExcel_Calculation_Functions::NaN(); | |
| 2126 | - if ((min($values) > 0) || (max($values) < 0)) return PHPExcel_Calculation_Functions::VALUE(); | |
| 2154 | +		if ($valCount != count($dates)) { | |
| 2155 | + return PHPExcel_Calculation_Functions::NaN(); | |
| 2156 | + } | |
| 2157 | +		if ((min($values) > 0) || (max($values) < 0)) { | |
| 2158 | + return PHPExcel_Calculation_Functions::VALUE(); | |
| 2159 | + } | |
| 2127 | 2160 | |
| 2128 | 2161 | $xnpv = 0.0; | 
| 2129 | 2162 |  		for ($i = 0; $i < $valCount; ++$i) { | 
| 2130 | - if (!is_numeric($values[$i])) return PHPExcel_Calculation_Functions::VALUE(); | |
| 2163 | +			if (!is_numeric($values[$i])) { | |
| 2164 | + return PHPExcel_Calculation_Functions::VALUE(); | |
| 2165 | + } | |
| 2131 | 2166 | $xnpv += $values[$i] / pow(1 + $rate, PHPExcel_Calculation_DateTime::DATEDIF($dates[0],$dates[$i],'d') / 365); | 
| 2132 | 2167 | } | 
| 2133 | 2168 | return (is_finite($xnpv)) ? $xnpv : PHPExcel_Calculation_Functions::VALUE(); |