Completed
Push — master ( 9f5802...03a8a6 )
by Patrick
07:27 queued 05:23
created

CSVDataTable::read()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 6
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
namespace Data;
3
4
class CSVDataTable extends DataTable
5
{
6
    /**
7
     * @param string $file The csv file
8
     */
9
    public function __construct($file)
10
    {
11
        $this->data = array_map('str_getcsv', file($file));
0 ignored issues
show
Bug introduced by
The property data does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
12
	$titles = array_shift($this->data);
13
	$count = count($this->data);
14
	for($i = 0; $i < $count; $i++)
15
	{
16
            $this->data[$i] = array_combine($titles, $this->data[$i]);
17
	}
18
    }
19
20
    public function count($filter = false)
21
    {
22
        if($filter)
23
	{
24
            $res = $this->data;
25
	    $res = $filter->filter_array($res);
0 ignored issues
show
Bug introduced by
The method filter_array cannot be called on $filter (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
26
	    return count($res);
27
	}
28
	return count($this->data);
29
    }
30
  
31
    public function read($filter = false, $select = false, $count = false, $skip = false, $sort = false, $params = false)
32
    {
33
        $res = $this->data;
34
	if($filter !== false)
35
	{
36
            $res = $filter->filter_array($res);
0 ignored issues
show
Bug introduced by
The method filter_array cannot be called on $filter (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
37
	}
38
	return $res;
39
    }
40
41
    public function create($data)
42
    {
43
        throw new \Exception('CSVDataTable is read only');
44
    }
45
46
    public function update($filter, $data)
47
    {
48
        throw new \Exception('CSVDataTable is read only');
49
    }
50
51
    public function delete($filter)
52
    {
53
        throw new \Exception('CSVDataTable is read only');
54
    }
55
}
56
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
57