| 1 |
<?php |
| 2 |
|
| 3 |
namespace TablePress\PhpOffice\PhpSpreadsheet\Calculation\Statistical; |
| 4 |
|
| 5 |
use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Functions; |
| 6 |
|
| 7 |
abstract class AggregateBase |
| 8 |
{ |
| 9 |
/** |
| 10 |
* MS Excel does not count Booleans if passed as cell values, but they are counted if passed as literals. |
| 11 |
* OpenOffice Calc always counts Booleans. |
| 12 |
* Gnumeric never counts Booleans. |
| 13 |
* @param mixed $arg |
| 14 |
* @param mixed $k |
| 15 |
* @return mixed |
| 16 |
*/ |
| 17 |
protected static function testAcceptedBoolean($arg, $k) |
| 18 |
{ |
| 19 |
if (!is_bool($arg)) { |
| 20 |
return $arg; |
| 21 |
} |
| 22 |
if (Functions::getCompatibilityMode() === Functions::COMPATIBILITY_GNUMERIC) { |
| 23 |
return $arg; |
| 24 |
} |
| 25 |
if (Functions::getCompatibilityMode() === Functions::COMPATIBILITY_OPENOFFICE) { |
| 26 |
return (int) $arg; |
| 27 |
} |
| 28 |
if (!Functions::isCellValue($k)) { |
| 29 |
return (int) $arg; |
| 30 |
} |
| 31 |
/*if ( |
| 32 |
(is_bool($arg)) && |
| 33 |
((!Functions::isCellValue($k) && (Functions::getCompatibilityMode() === Functions::COMPATIBILITY_EXCEL)) || |
| 34 |
(Functions::getCompatibilityMode() === Functions::COMPATIBILITY_OPENOFFICE)) |
| 35 |
) { |
| 36 |
$arg = (int) $arg; |
| 37 |
}*/ |
| 38 |
|
| 39 |
return $arg; |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* @param mixed $arg |
| 44 |
* @param mixed $k |
| 45 |
*/ |
| 46 |
protected static function isAcceptedCountable($arg, $k, bool $countNull = false): bool |
| 47 |
{ |
| 48 |
if ($countNull && $arg === null && !Functions::isCellValue($k) && Functions::getCompatibilityMode() !== Functions::COMPATIBILITY_GNUMERIC) { |
| 49 |
return true; |
| 50 |
} |
| 51 |
if (!is_numeric($arg)) { |
| 52 |
return false; |
| 53 |
} |
| 54 |
if (!is_string($arg)) { |
| 55 |
return true; |
| 56 |
} |
| 57 |
if (!Functions::isCellValue($k) && Functions::getCompatibilityMode() === Functions::COMPATIBILITY_OPENOFFICE) { |
| 58 |
return true; |
| 59 |
} |
| 60 |
if (!Functions::isCellValue($k) && Functions::getCompatibilityMode() !== Functions::COMPATIBILITY_GNUMERIC) { |
| 61 |
return true; |
| 62 |
} |
| 63 |
|
| 64 |
return false; |
| 65 |
} |
| 66 |
} |
| 67 |
|