ColumnIndexTransformer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 14 3
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