1 | <?php |
||
13 | class ImportHelper |
||
14 | { |
||
15 | /** |
||
16 | * Import a CSV from a string or filename and return array. |
||
17 | * |
||
18 | * The filename can be either a resource from fopen() or a string containing the csv data. Filenames will be wrapped trough {{Yii::getAlias()}} method. |
||
19 | * |
||
20 | * @param string $filename Can be either a filename which is parsed by {{luya\helpers\FileHelper::getFileContent()}} or a string with the contained csv data. |
||
21 | * @param array $options Provide options to the csv |
||
22 | * + removeHeader: boolean, Whether the import csv contains a header in the first row to skip or not. Default value is false. |
||
23 | * + delimiter: string, The delimiter which is used to explode the columns. Default value is `,`. |
||
24 | * + enclosure: string, The encloser which is used betweend the columns. Default value is `"`. |
||
25 | * + fields: array, An array with fielnames (based on the array header if any, or position) which should be parsed into the final export. |
||
26 | * ```php |
||
27 | * 'fields' => ['firstname', 'lastname'] // will only parse those fields based on table header (row 0) |
||
28 | * 'fields' => [0,1,3] // will only parse fields by those positions if no table header is present. Positions starts at 0 |
||
29 | * ``` |
||
30 | * @return Returns an array with the csv data. |
||
31 | */ |
||
32 | public static function csv($filename, array $options = []) |
||
77 | } |
||
78 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.