Writer::writeRow()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
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