Completed
Push — master ( 3ef8ec...6ec2cc )
by
unknown
40s queued 31s
created

CalculationBase::getFunctions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Calculation;
4
5
class CalculationBase
6
{
7
    /**
8
     * Get a list of all implemented functions as an array of function objects.
9
     *
10
     * return array<string, array<string, mixed>>
11
     */
12
    public static function getFunctions(): array
13
    {
14
        return FunctionArray::$phpSpreadsheetFunctions;
15
    }
16
17
    /**
18
     * Get address of list of all implemented functions as an array of function objects.
19
     *
20
     * @return array<string, array<string, mixed>>
21
     */
22
    protected static function &getFunctionsAddress(): array
23
    {
24
        return FunctionArray::$phpSpreadsheetFunctions;
25
    }
26
27
    /**
28
     * @param array<string, array<string, mixed>> $value
29
     */
30
    public static function addFunction(string $key, array $value): bool
31
    {
32
        $key = strtoupper($key);
33
        if (array_key_exists($key, FunctionArray::$phpSpreadsheetFunctions)) {
34
            return false;
35
        }
36
        $value['custom'] = true;
37
        FunctionArray::$phpSpreadsheetFunctions[$key] = $value;
38
39
        return true;
40
    }
41
42
    public static function removeFunction(string $key): bool
43
    {
44
        $key = strtoupper($key);
45
        if (array_key_exists($key, FunctionArray::$phpSpreadsheetFunctions)) {
46
            if (FunctionArray::$phpSpreadsheetFunctions[$key]['custom'] ?? false) {
47
                unset(FunctionArray::$phpSpreadsheetFunctions[$key]);
48
49
                return true;
50
            }
51
        }
52
53
        return false;
54
    }
55
}
56