ColumnIndexTransformer::transform()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Akeneo\Component\SpreadsheetParser\Xlsx;
4
5
/**
6
 * Transforms an Excel cell name in an index
7
 *
8
 * @author    Antoine Guigan <[email protected]>
9
 * @copyright 2014 Akeneo SAS (http://www.akeneo.com)
10
 * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
11
 */
12
13
class ColumnIndexTransformer
14
{
15
    /**
16
     * Transforms an Excel cell name in an index
17
     *
18
     * @param string $name
19
     *
20
     * @return integer
21
     */
22
    public function transform($name)
23
    {
24
        $number = -1;
25
26
        foreach (str_split($name) as $chr) {
27
            $digit = ord($chr) - 65;
28
            if ($digit < 0) {
29
                break;
30
            }
31
            $number = ($number + 1) * 26 + $digit;
32
        }
33
34
        return $number;
35
    }
36
}
37