Passed
Push — spaghetti ( 4802b3...dd673c )
by simpletoimplement
02:07
created

Column   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 17
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 15 3
1
<?php declare(strict_types = 1);
2
3
namespace Spaghetti\XLSXParser\Transformer;
4
5
use function ord;
6
use function str_split;
7
8
/**
9
 * @internal
10
 */
11
final class Column
12
{
13
    public function transform(string $name): int
14
    {
15
        $number = 0;
16
17
        foreach (str_split(string: $name) as $char) {
18
            $digit = ord(character: $char) - 65;
19
20
            if ($digit < 0) {
21
                break;
22
            }
23
24
            $number = $number * 26 + $digit;
25
        }
26
27
        return $number;
28
    }
29
}
30