CsvParser::createRowIteratorFactory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Akeneo\Component\SpreadsheetParser\Csv;
4
5
/**
6
 * Entry point for CSV parser
7
 *
8
 * @author Antoine Guigan <[email protected]>
9
 */
10
class CsvParser
11
{
12
    /**
13
     * @staticvar string the name of the format
14
     */
15
    const FORMAT_NAME = 'csv';
16
17
    /**
18
     * @staticvar string Spreadsheet class
19
     */
20
    const WORKBOOK_CLASS = 'Akeneo\Component\SpreadsheetParser\Csv\Spreadsheet';
21
22
    /**
23
     * @staticvar string RowIterator class
24
     */
25
    const ROW_ITERATOR_CLASS = 'Akeneo\Component\SpreadsheetParser\Csv\RowIterator';
26
27
    /**
28
     * @staticvar string The name of the sheet
29
     */
30
    const SHEET_NAME = 'default';
31
32
    /**
33
     * @var SpreadsheetLoader
34
     */
35
    private static $spreadsheetLoader;
36
37
    /**
38
     * Opens a CSV file
39
     *
40
     * @param string $path
41
     *
42
     * @return Spreadsheet
43
     */
44
    public static function open($path)
45
    {
46
        return static::getSpreadsheetLoader()->open($path);
47
    }
48
49
    /**
50
     * @return SpreadsheetLoader
51
     */
52
    public static function getSpreadsheetLoader()
53
    {
54
        if (!isset(self::$spreadsheetLoader)) {
55
            self::$spreadsheetLoader = new SpreadsheetLoader(
56
                static::createRowIteratorFactory(),
57
                static::WORKBOOK_CLASS,
58
                static::SHEET_NAME
59
            );
60
        }
61
62
        return self::$spreadsheetLoader;
63
    }
64
65
    /**
66
     * @return RowIteratorFactory
67
     */
68
    protected static function createRowIteratorFactory()
69
    {
70
        return new RowIteratorFactory(static::ROW_ITERATOR_CLASS);
71
    }
72
}
73