Completed
Push — master ( d2d480...28a4db )
by Patrick
03:16
created

CSVSerializer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 30
rs 10
wmc 5
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B serializeData() 0 25 5
1
<?php
2
namespace Serialize;
3
4
class CSVSerializer extends SpreadSheetSerializer
5
{
6
    protected $types = array('csv', 'text/csv');
7
8
    public function serializeData($type, $array)
9
    {
10
        if($this->supportsType($type) === false)
11
        {
12
            return null;
13
        }
14
        if(count($array) === 0)
15
        {
16
            return null;
17
        }
18
        $data = $this->getArray($array);
19
        ob_start();
20
        $df = fopen('php://output', 'w');
21
        foreach($data as $row)
22
        {
23
            if(!is_array($row))
24
            {
25
                $row = array($row);
26
            }
27
            fputcsv($df, $row);
28
        }
29
        fclose($df);
30
        $ret = ob_get_clean();
31
        return $ret;
32
    }
33
}
34
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
35