ArrayHelper::combineArrays()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace Pim\Bundle\ExcelConnectorBundle\Iterator;
4
5
/**
6
 * Helper methods for Excel files
7
 *
8
 * @author    Antoine Guigan <[email protected]>
9
 * @copyright 2013 Akeneo SAS (http://www.akeneo.com)
10
 * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
11
 */
12
class ArrayHelper
13
{
14
    /**
15
     * Combines array of different sizes
16
     *
17
     * @param array $keys
18
     * @param array $values
19
     *
20
     * @return array
21
     */
22
    public function combineArrays(array $keys, array $values)
23
    {
24
        return array_combine($keys, $this->resizeArray($values, count($keys)));
25
    }
26
27
    /**
28
     * Resizes an array to the specified data count
29
     *
30
     * @param array $data
31
     * @param int   $count
32
     *
33
     * @return array
34
     */
35
    protected function resizeArray(array $data, $count)
36
    {
37
        if (count($data) < $count) {
38
            $data = array_merge($data, array_fill(0, $count - count($data), ''));
39
        }
40
41
        return array_slice($data, 0, $count);
42
    }
43
}
44