Conditions | 5 |
Paths | 6 |
Total Lines | 23 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
23 | public function __construct(string $filepath, int $features, bool $headingRow = true) |
||
24 | { |
||
25 | if (!file_exists($filepath)) { |
||
26 | throw FileException::missingFile(basename($filepath)); |
||
27 | } |
||
28 | |||
29 | if (false === $handle = fopen($filepath, 'rb')) { |
||
30 | throw FileException::cantOpenFile(basename($filepath)); |
||
31 | } |
||
32 | |||
33 | if ($headingRow) { |
||
34 | $data = fgetcsv($handle, 1000, ','); |
||
35 | $this->columnNames = array_slice($data, 0, $features); |
||
36 | } else { |
||
37 | $this->columnNames = range(0, $features - 1); |
||
38 | } |
||
39 | |||
40 | while (($data = fgetcsv($handle, 1000, ',')) !== false) { |
||
41 | $this->samples[] = array_slice($data, 0, $features); |
||
42 | $this->targets[] = $data[$features]; |
||
43 | } |
||
44 | fclose($handle); |
||
45 | } |
||
46 | |||
55 |