#401 : PHPCS (Calculation\MathTrig & Logical)
This commit is contained in:
parent
12590bbf1e
commit
05643d16d5
|
@ -306,7 +306,7 @@ class Calculation
|
||||||
),
|
),
|
||||||
'AND' => array(
|
'AND' => array(
|
||||||
'category' => Calculation\Categories::CATEGORY_LOGICAL,
|
'category' => Calculation\Categories::CATEGORY_LOGICAL,
|
||||||
'functionCall' => '\\PHPExcel\\Calculation\\Logical::LOGICAL_AND',
|
'functionCall' => '\\PHPExcel\\Calculation\\Logical::logicalAnd',
|
||||||
'argumentCount' => '1+'
|
'argumentCount' => '1+'
|
||||||
),
|
),
|
||||||
'AREAS' => array(
|
'AREAS' => array(
|
||||||
|
@ -993,7 +993,7 @@ class Calculation
|
||||||
),
|
),
|
||||||
'IF' => array(
|
'IF' => array(
|
||||||
'category' => Calculation\Categories::CATEGORY_LOGICAL,
|
'category' => Calculation\Categories::CATEGORY_LOGICAL,
|
||||||
'functionCall' => '\\PHPExcel\\Calculation\\Logical::STATEMENT_IF',
|
'functionCall' => '\\PHPExcel\\Calculation\\Logical::statementIf',
|
||||||
'argumentCount' => '1-3'
|
'argumentCount' => '1-3'
|
||||||
),
|
),
|
||||||
'IFERROR' => array(
|
'IFERROR' => array(
|
||||||
|
@ -1239,7 +1239,7 @@ class Calculation
|
||||||
),
|
),
|
||||||
'LOG' => array(
|
'LOG' => array(
|
||||||
'category' => Calculation\Categories::CATEGORY_MATH_AND_TRIG,
|
'category' => Calculation\Categories::CATEGORY_MATH_AND_TRIG,
|
||||||
'functionCall' => '\\PHPExcel\\Calculation\\MathTrig::LOG_BASE',
|
'functionCall' => '\\PHPExcel\\Calculation\\MathTrig::logBase',
|
||||||
'argumentCount' => '1,2'
|
'argumentCount' => '1,2'
|
||||||
),
|
),
|
||||||
'LOG10' => array(
|
'LOG10' => array(
|
||||||
|
@ -1496,7 +1496,7 @@ class Calculation
|
||||||
),
|
),
|
||||||
'OR' => array(
|
'OR' => array(
|
||||||
'category' => Calculation\Categories::CATEGORY_LOGICAL,
|
'category' => Calculation\Categories::CATEGORY_LOGICAL,
|
||||||
'functionCall' => '\\PHPExcel\\Calculation\\Logical::LOGICAL_OR',
|
'functionCall' => '\\PHPExcel\\Calculation\\Logical::logicalOr',
|
||||||
'argumentCount' => '1+'
|
'argumentCount' => '1+'
|
||||||
),
|
),
|
||||||
'PEARSON' => array(
|
'PEARSON' => array(
|
||||||
|
|
|
@ -102,7 +102,8 @@ class Functions
|
||||||
{
|
{
|
||||||
if (($compatibilityMode == self::COMPATIBILITY_EXCEL) ||
|
if (($compatibilityMode == self::COMPATIBILITY_EXCEL) ||
|
||||||
($compatibilityMode == self::COMPATIBILITY_GNUMERIC) ||
|
($compatibilityMode == self::COMPATIBILITY_GNUMERIC) ||
|
||||||
($compatibilityMode == self::COMPATIBILITY_OPENOFFICE)) {
|
($compatibilityMode == self::COMPATIBILITY_OPENOFFICE)
|
||||||
|
) {
|
||||||
self::$compatibilityMode = $compatibilityMode;
|
self::$compatibilityMode = $compatibilityMode;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -143,7 +144,8 @@ class Functions
|
||||||
{
|
{
|
||||||
if (($returnDateType == self::RETURNDATE_PHP_NUMERIC) ||
|
if (($returnDateType == self::RETURNDATE_PHP_NUMERIC) ||
|
||||||
($returnDateType == self::RETURNDATE_PHP_OBJECT) ||
|
($returnDateType == self::RETURNDATE_PHP_OBJECT) ||
|
||||||
($returnDateType == self::RETURNDATE_EXCEL)) {
|
($returnDateType == self::RETURNDATE_EXCEL)
|
||||||
|
) {
|
||||||
self::$returnDateType = $returnDateType;
|
self::$returnDateType = $returnDateType;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -326,7 +328,7 @@ class Functions
|
||||||
$operand = \PHPExcel\Calculation::wrapResult(strtoupper($operand));
|
$operand = \PHPExcel\Calculation::wrapResult(strtoupper($operand));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $operator.$operand;
|
return $operator . $operand;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -404,7 +406,7 @@ class Functions
|
||||||
* @param mixed $value Value to check
|
* @param mixed $value Value to check
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static function isNa(($value = '')
|
public static function isNa($value = '')
|
||||||
{
|
{
|
||||||
$value = self::flattenSingleValue($value);
|
$value = self::flattenSingleValue($value);
|
||||||
|
|
||||||
|
@ -535,7 +537,7 @@ class Functions
|
||||||
* An error value The error value
|
* An error value The error value
|
||||||
* Anything else 0
|
* Anything else 0
|
||||||
*/
|
*/
|
||||||
public static function N($value = null)
|
public static function n($value = null)
|
||||||
{
|
{
|
||||||
while (is_array($value)) {
|
while (is_array($value)) {
|
||||||
$value = array_shift($value);
|
$value = array_shift($value);
|
||||||
|
@ -547,7 +549,7 @@ class Functions
|
||||||
case 'integer':
|
case 'integer':
|
||||||
return $value;
|
return $value;
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
return (integer) $value;
|
return (integer)$value;
|
||||||
case 'string':
|
case 'string':
|
||||||
// Errors
|
// Errors
|
||||||
if ((strlen($value) > 0) && ($value{0} == '#')) {
|
if ((strlen($value) > 0) && ($value{0} == '#')) {
|
||||||
|
@ -618,7 +620,7 @@ class Functions
|
||||||
public static function flattenArray($array)
|
public static function flattenArray($array)
|
||||||
{
|
{
|
||||||
if (!is_array($array)) {
|
if (!is_array($array)) {
|
||||||
return (array) $array;
|
return (array)$array;
|
||||||
}
|
}
|
||||||
|
|
||||||
$arrayValues = array();
|
$arrayValues = array();
|
||||||
|
@ -651,7 +653,7 @@ class Functions
|
||||||
public static function flattenArrayIndexed($array)
|
public static function flattenArrayIndexed($array)
|
||||||
{
|
{
|
||||||
if (!is_array($array)) {
|
if (!is_array($array)) {
|
||||||
return (array) $array;
|
return (array)$array;
|
||||||
}
|
}
|
||||||
|
|
||||||
$arrayValues = array();
|
$arrayValues = array();
|
||||||
|
@ -660,10 +662,10 @@ class Functions
|
||||||
foreach ($value as $k2 => $val) {
|
foreach ($value as $k2 => $val) {
|
||||||
if (is_array($val)) {
|
if (is_array($val)) {
|
||||||
foreach ($val as $k3 => $v) {
|
foreach ($val as $k3 => $v) {
|
||||||
$arrayValues[$k1.'.'.$k2.'.'.$k3] = $v;
|
$arrayValues[$k1 . '.' . $k2 . '.' . $k3] = $v;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$arrayValues[$k1.'.'.$k2] = $val;
|
$arrayValues[$k1 . '.' . $k2] = $val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -724,7 +726,8 @@ if (!function_exists('atanh')) {
|
||||||
// As we'll only ever use this function with UTF-8 characters, we can simply "hard-code" the character set
|
// As we'll only ever use this function with UTF-8 characters, we can simply "hard-code" the character set
|
||||||
//
|
//
|
||||||
if ((!function_exists('mb_str_replace')) &&
|
if ((!function_exists('mb_str_replace')) &&
|
||||||
(function_exists('mb_substr')) && (function_exists('mb_strlen')) && (function_exists('mb_strpos'))) {
|
(function_exists('mb_substr')) && (function_exists('mb_strlen')) && (function_exists('mb_strpos'))
|
||||||
|
) {
|
||||||
function mb_str_replace($search, $replace, $subject)
|
function mb_str_replace($search, $replace, $subject)
|
||||||
{
|
{
|
||||||
if (is_array($subject)) {
|
if (is_array($subject)) {
|
||||||
|
@ -735,7 +738,7 @@ if ((!function_exists('mb_str_replace')) &&
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ((array) $search as $key => $s) {
|
foreach ((array)$search as $key => $s) {
|
||||||
if ($s == '' && $s !== 0) {
|
if ($s == '' && $s !== 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ class Logical
|
||||||
* @param mixed $arg,... Data values
|
* @param mixed $arg,... Data values
|
||||||
* @return boolean The logical AND of the arguments.
|
* @return boolean The logical AND of the arguments.
|
||||||
*/
|
*/
|
||||||
public static function LOGICAL_AND()
|
public static function logicalAnd()
|
||||||
{
|
{
|
||||||
// Return value
|
// Return value
|
||||||
$returnValue = true;
|
$returnValue = true;
|
||||||
|
@ -142,7 +142,7 @@ class Logical
|
||||||
* @param mixed $arg,... Data values
|
* @param mixed $arg,... Data values
|
||||||
* @return boolean The logical OR of the arguments.
|
* @return boolean The logical OR of the arguments.
|
||||||
*/
|
*/
|
||||||
public static function LOGICAL_OR()
|
public static function logicalOr()
|
||||||
{
|
{
|
||||||
// Return value
|
// Return value
|
||||||
$returnValue = false;
|
$returnValue = false;
|
||||||
|
@ -246,7 +246,7 @@ class Logical
|
||||||
* @param mixed $returnIfFalse Optional value to return when condition is false
|
* @param mixed $returnIfFalse Optional value to return when condition is false
|
||||||
* @return mixed The value of returnIfTrue or returnIfFalse determined by condition
|
* @return mixed The value of returnIfTrue or returnIfFalse determined by condition
|
||||||
*/
|
*/
|
||||||
public static function STATEMENT_IF($condition = true, $returnIfTrue = 0, $returnIfFalse = false)
|
public static function statementIf($condition = true, $returnIfTrue = 0, $returnIfFalse = false)
|
||||||
{
|
{
|
||||||
$condition = (is_null($condition)) ? true : (boolean) Functions::flattenSingleValue($condition);
|
$condition = (is_null($condition)) ? true : (boolean) Functions::flattenSingleValue($condition);
|
||||||
$returnIfTrue = (is_null($returnIfTrue)) ? 0 : Functions::flattenSingleValue($returnIfTrue);
|
$returnIfTrue = (is_null($returnIfTrue)) ? 0 : Functions::flattenSingleValue($returnIfTrue);
|
||||||
|
@ -273,6 +273,6 @@ class Logical
|
||||||
$testValue = (is_null($testValue)) ? '' : Functions::flattenSingleValue($testValue);
|
$testValue = (is_null($testValue)) ? '' : Functions::flattenSingleValue($testValue);
|
||||||
$errorpart = (is_null($errorpart)) ? '' : Functions::flattenSingleValue($errorpart);
|
$errorpart = (is_null($errorpart)) ? '' : Functions::flattenSingleValue($errorpart);
|
||||||
|
|
||||||
return self::STATEMENT_IF(Functions::isError($testValue), $errorpart, $testValue);
|
return self::statementIf(Functions::isError($testValue), $errorpart, $testValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -498,7 +498,7 @@ class MathTrig
|
||||||
* @param float $base The base of the logarithm. If base is omitted, it is assumed to be 10.
|
* @param float $base The base of the logarithm. If base is omitted, it is assumed to be 10.
|
||||||
* @return float
|
* @return float
|
||||||
*/
|
*/
|
||||||
public static function LOG_BASE($number = null, $base = 10)
|
public static function logBase($number = null, $base = 10)
|
||||||
{
|
{
|
||||||
$number = Functions::flattenSingleValue($number);
|
$number = Functions::flattenSingleValue($number);
|
||||||
$base = (is_null($base)) ? 10 : (float) Functions::flattenSingleValue($base);
|
$base = (is_null($base)) ? 10 : (float) Functions::flattenSingleValue($base);
|
||||||
|
|
|
@ -121,7 +121,7 @@ class FunctionsTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function providerERROR_TYPE()
|
public function providerERROR_TYPE()
|
||||||
{
|
{
|
||||||
return new \testDataFileIterator('rawTestData/Calculation/Functions/errorType.data');
|
return new \testDataFileIterator('rawTestData/Calculation/Functions/ERROR_TYPE.data');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -31,7 +31,7 @@ class LogicalTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
$expectedResult = array_pop($args);
|
$expectedResult = array_pop($args);
|
||||||
$result = call_user_func_array(array('\PHPExcel\Calculation\Logical','LOGICAL_AND'), $args);
|
$result = call_user_func_array(array('\PHPExcel\Calculation\Logical','logicalAnd'), $args);
|
||||||
$this->assertEquals($expectedResult, $result);
|
$this->assertEquals($expectedResult, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ class LogicalTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
$expectedResult = array_pop($args);
|
$expectedResult = array_pop($args);
|
||||||
$result = call_user_func_array(array('\PHPExcel\Calculation\Logical','LOGICAL_OR'), $args);
|
$result = call_user_func_array(array('\PHPExcel\Calculation\Logical','logicalOr'), $args);
|
||||||
$this->assertEquals($expectedResult, $result);
|
$this->assertEquals($expectedResult, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ class LogicalTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
$expectedResult = array_pop($args);
|
$expectedResult = array_pop($args);
|
||||||
$result = call_user_func_array(array('\PHPExcel\Calculation\Logical','STATEMENT_IF'), $args);
|
$result = call_user_func_array(array('\PHPExcel\Calculation\Logical','statementIf'), $args);
|
||||||
$this->assertEquals($expectedResult, $result);
|
$this->assertEquals($expectedResult, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -227,7 +227,7 @@ class MathTrigTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
$expectedResult = array_pop($args);
|
$expectedResult = array_pop($args);
|
||||||
$result = call_user_func_array(array('\PHPExcel\Calculation\MathTrig','LOG_BASE'), $args);
|
$result = call_user_func_array(array('\PHPExcel\Calculation\MathTrig','logBase'), $args);
|
||||||
$this->assertEquals($expectedResult, $result, null, 1E-12);
|
$this->assertEquals($expectedResult, $result, null, 1E-12);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue