MultispacedParser   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 19
c 0
b 0
f 0
wmc 1
lcom 0
cbo 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getMap() 0 8 1
1
<?php
2
3
namespace TraderInteractive\ColumnParser\HeaderParser;
4
5
/**
6
 * This determines the widths of each column in a header row.
7
 */
8
class MultispacedParser
9
{
10
    /**
11
     * Splits a line on consecutive spaces (2+) to determine the width of the column and the column header.
12
     *
13
     * The trailing spaces are counted as part of the width of the column, but aren't included in the header.
14
     *
15
     * @param string $line The line of data.
16
     * @return array A map of column header => column width.
17
     */
18
    public function getMap(string $line) : array
19
    {
20
        preg_match_all('/(.+?)( {2,}|$)/', $line, $matches);
21
        $columnHeaders = $matches[1];
22
        $columnWidths = array_map('strlen', $matches[0]);
23
24
        return array_combine($columnHeaders, $columnWidths);
25
    }
26
}
27