XlsxFileIterator::setDefaultOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 1
1
<?php
2
3
namespace Pim\Bundle\ExcelConnectorBundle\Iterator;
4
5
use Symfony\Component\OptionsResolver\OptionsResolver;
6
7
/**
8
 * XSLX file iterator
9
 *
10
 * @author    Antoine Guigan <[email protected]>
11
 * @copyright 2013 Akeneo SAS (http://www.akeneo.com)
12
 * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
13
 */
14
class XlsxFileIterator extends AbstractXlsxFileIterator
15
{
16
    /** @var array */
17
    protected $labels;
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function current()
23
    {
24
        $values = $this->getArrayHelper()->combineArrays($this->labels, $this->valuesIterator->current());
25
26
        if ($this->options['skip_empty']) {
27
            foreach (array_keys($values) as $key) {
28
                if (!$values[$key]) {
29
                    unset($values[$key]);
30
                }
31
            }
32
        }
33
34
        return $values;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    protected function createValuesIterator()
41
    {
42
        $iterator = $this->getExcelObject()->createRowIterator(
43
            $this->worksheetIterator->key(),
44
            $this->options['parser_options']
45
        );
46
        $iterator->rewind();
47
        while ($iterator->valid() && ((int) $this->options['label_row'] > $iterator->key())) {
48
            $iterator->next();
49
        }
50
        $this->labels = $iterator->current();
51
        while ($iterator->valid() && ((int) $this->options['data_row'] > $iterator->key())) {
52
            $iterator->next();
53
        }
54
55
        return $iterator;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    protected function setDefaultOptions(OptionsResolver $resolver)
62
    {
63
        parent::setDefaultOptions($resolver);
64
        $resolver->setDefaults(
65
            array(
66
                'skip_empty' => false,
67
                'label_row'  => 1,
68
                'data_row'   => 2,
69
            )
70
        );
71
    }
72
}
73