Completed
Pull Request — master (#773)
by
unknown
12:09
created

CellFormulaFormatter::extractNodeFormula()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Box\Spout\Reader\XLSX\Helper;
4
5
/**
6
 * Class CellFormulaFormatter
7
 * This class provides helper functions to format cell formulas
8
 */
9
class CellFormulaFormatter
10
{
11
    /** Definition of XML nodes names used to parse data */
12
    const XML_NODE_FORMULA = 'f';
13
    
14
    /**
15
     * Returns the cell formula associated to the given XML node.
16
     *
17
     * @param \DOMNode $node
18
     * @return string The formula associated with the cell
19
     */
20
    public function extractNodeFormula($node)
21
    {
22
        // for cell types having a "f" tag containing the formula.
23
        // if not, the returned formula should be empty string.
24
        $vNode = $node->getElementsByTagName(self::XML_NODE_FORMULA)->item(0);
25
26
        return ($vNode !== null) ? $vNode->nodeValue : '';
27
    }
28
}