CsvUnserialiser::unserialise()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 21
ccs 5
cts 6
cp 0.8333
rs 9.3142
cc 2
eloc 6
nc 2
nop 2
crap 2.0185
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\Unserialisers;
13
14
use DraperStudio\Payload\Contracts\Unserialiser;
15
use DraperStudio\Payload\Utils\Mapper;
16
use League\Csv\Reader;
17
18
/**
19
 * Class CsvUnserialiser.
20
 */
21
class CsvUnserialiser implements Unserialiser
22
{
23
    /**
24
     * @param $input
25
     * @param null $class
26
     *
27
     * @return mixed
28
     */
29 6
    public function unserialise($input, $class = null)
30
    {
31 6
        $reader = Reader::createFromString($input);
32
33 6
        $contents = $reader->fetchAll();
34
35
        // @deprecated for the moment
36
        // for ($i = 0; $i < count($contents); ++$i) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
37
        //     if ($i <= 0) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
38
        //         continue;
39
        //     }
40
        //
41
        //     $contents[$i] = array_combine($contents[0], $contents[$i]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
42
        // }
43
44 6
        if (!is_null($class)) {
45
            return (new Mapper())->map($contents, $class);
46
        }
47
48 6
        return $contents;
49
    }
50
}
51