CsvSerialiser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 63.64%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 26
ccs 7
cts 11
cp 0.6364
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A serialise() 0 18 3
1
<?php
2
3
/*
4
 * This file is part of Payload.
5
 *
6
 * (c) DraperStudio <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace DraperStudio\Payload\Serialisers;
13
14
use DraperStudio\Payload\Contracts\Serialiser;
15
use League\Csv\Writer;
16
17
/**
18
 * Class CsvSerialiser.
19
 */
20
class CsvSerialiser implements Serialiser
21
{
22
    /**
23
     * @param $input
24
     *
25
     * @return mixed
26
     */
27 6
    public function serialise($input)
28
    {
29 6
        $writer = Writer::createFromString('');
30
31 6
        if (is_array(reset($input))) {
32
            $writer->insertOne(array_keys(reset($input)));
33
        } else {
34 6
            $writer->insertOne(array_keys($input));
35
        }
36
37 6
        if (is_array(reset($input))) {
38
            $writer->insertAll($input);
39
        } else {
40 6
            $writer->insertOne($input);
41
        }
42
43 6
        return $writer->__toString();
44
    }
45
}
46