| 1441 |
ariadna |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical;
|
|
|
4 |
|
|
|
5 |
use 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 |
*/
|
|
|
14 |
protected static function testAcceptedBoolean(mixed $arg, mixed $k): mixed
|
|
|
15 |
{
|
|
|
16 |
if (!is_bool($arg)) {
|
|
|
17 |
return $arg;
|
|
|
18 |
}
|
|
|
19 |
if (Functions::getCompatibilityMode() === Functions::COMPATIBILITY_GNUMERIC) {
|
|
|
20 |
return $arg;
|
|
|
21 |
}
|
|
|
22 |
if (Functions::getCompatibilityMode() === Functions::COMPATIBILITY_OPENOFFICE) {
|
|
|
23 |
return (int) $arg;
|
|
|
24 |
}
|
|
|
25 |
if (!Functions::isCellValue($k)) {
|
|
|
26 |
return (int) $arg;
|
|
|
27 |
}
|
|
|
28 |
/*if (
|
|
|
29 |
(is_bool($arg)) &&
|
|
|
30 |
((!Functions::isCellValue($k) && (Functions::getCompatibilityMode() === Functions::COMPATIBILITY_EXCEL)) ||
|
|
|
31 |
(Functions::getCompatibilityMode() === Functions::COMPATIBILITY_OPENOFFICE))
|
|
|
32 |
) {
|
|
|
33 |
$arg = (int) $arg;
|
|
|
34 |
}*/
|
|
|
35 |
|
|
|
36 |
return $arg;
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
protected static function isAcceptedCountable(mixed $arg, mixed $k, bool $countNull = false): bool
|
|
|
40 |
{
|
|
|
41 |
if ($countNull && $arg === null && !Functions::isCellValue($k) && Functions::getCompatibilityMode() !== Functions::COMPATIBILITY_GNUMERIC) {
|
|
|
42 |
return true;
|
|
|
43 |
}
|
|
|
44 |
if (!is_numeric($arg)) {
|
|
|
45 |
return false;
|
|
|
46 |
}
|
|
|
47 |
if (!is_string($arg)) {
|
|
|
48 |
return true;
|
|
|
49 |
}
|
|
|
50 |
if (!Functions::isCellValue($k) && Functions::getCompatibilityMode() === Functions::COMPATIBILITY_OPENOFFICE) {
|
|
|
51 |
return true;
|
|
|
52 |
}
|
|
|
53 |
if (!Functions::isCellValue($k) && Functions::getCompatibilityMode() !== Functions::COMPATIBILITY_GNUMERIC) {
|
|
|
54 |
return true;
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
return false;
|
|
|
58 |
}
|
|
|
59 |
}
|