Conditions | 5 |
Paths | 6 |
Total Lines | 27 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
19 | public function __construct(string $filepath, int $features, bool $headingRow = true, string $delimiter = ',', int $maxLineLength = 0) |
||
20 | { |
||
21 | if (!file_exists($filepath)) { |
||
22 | throw new FileException(sprintf('File "%s" missing.', basename($filepath))); |
||
23 | } |
||
24 | |||
25 | $handle = fopen($filepath, 'rb'); |
||
26 | if ($handle === false) { |
||
27 | throw new FileException(sprintf('File "%s" can\'t be open.', basename($filepath))); |
||
28 | } |
||
29 | |||
30 | if ($headingRow) { |
||
31 | $data = fgetcsv($handle, $maxLineLength, $delimiter); |
||
32 | $this->columnNames = array_slice((array) $data, 0, $features); |
||
33 | } else { |
||
34 | $this->columnNames = range(0, $features - 1); |
||
35 | } |
||
36 | |||
37 | $samples = $targets = []; |
||
38 | while ($data = fgetcsv($handle, $maxLineLength, $delimiter)) { |
||
39 | $samples[] = array_slice($data, 0, $features); |
||
40 | $targets[] = $data[$features]; |
||
41 | } |
||
42 | |||
43 | fclose($handle); |
||
44 | |||
45 | parent::__construct($samples, $targets); |
||
46 | } |
||
53 |