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

CellFormulaFormatter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A extractNodeFormula() 0 8 2
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
}