Writer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 24
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A writeFromArray() 0 4 2
A writeRow() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EasyCSV;
6
7
use function array_map;
8
use function explode;
9
use function is_string;
10
11
class Writer extends AbstractBase
12
{
13
    /**
14
     * @param string|string[] $row
15
     *
16
     * @return false|int
17
     */
18 5
    public function writeRow($row)
19
    {
20 5
        if (is_string($row)) {
21 5
            $row = explode(',', $row);
22 5
            $row = array_map('trim', $row);
23
        }
24
25 5
        return $this->getHandle()->fputcsv($row, $this->delimiter, $this->enclosure);
26
    }
27
28
    /**
29
     * @param mixed[][] $array
30
     */
31 2
    public function writeFromArray(array $array) : void
32
    {
33 2
        foreach ($array as $key => $value) {
34 2
            $this->writeRow($value);
35
        }
36 2
    }
37
}
38