Completed
Push — master ( 77aa9b...c41f01 )
by Andrey
02:55
created

Excel::getReader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace EFParser;
4
5
use EFParserInterface\IExcel;
6
7
/**
8
 * Class excelParser.
9
 * Класс содержит общие свойства и методы, которые используются в классах Sheet, Сell
10
 */
11
class Excel implements IExcel
12
{
13
    /**
14
     * Документ
15
     *
16
     * @var string
17
     */
18
    public $sourceFile;
19
20
    /**
21
     * Путь к документу
22
     *
23
     * @var string
24
     */
25
    public $sourceFilePath;
26
27
    /**
28
     * Объект ридера
29
     *
30
     * @var string
31
     */
32
    public $sourceReader;
33
34
    /**
35
     * excelParser constructor.
36
     *
37
     * @param string $file (Документ)
38
     *
39
     * @param string $path (Путь)
40
     */
41
    public function __construct($file, $path)
42
    {
43
        $this->sourceFile       = $file;
44
        $this->sourceFilePath   = $path;
45
        $this->sourceReader     = $this->getReader();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getReader() of type object<PHPExcel_Reader_IReader> is incompatible with the declared type string of property $sourceReader.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
46
    }
47
48
    /**
49
     * Метод возвращает ридер для документа
50
     *
51
     * @return PHPExcel_Reader_IReader  (Ридер документа)
52
     *
53
     * @throws PHPExcel_Reader_Exception (Не удалось определить тип документа)
54
     */
55
    public function getReader()
56
    {
57
        $readerType = \PHPExcel_IOFactory::identify($this->sourceFilePath . $this->sourceFile);
58
59
        return \PHPExcel_IOFactory::createReader($readerType);
60
    }
61
62
    /**
63
     * Метод возвращает массив с распарсенными данными, отсеивая null значения
64
     *
65
     * @param array $objPHPExcel (Масив данных полученных с помощью toArray())
66
     *
67
     * @return array
68
     */
69
    public function getData(array $objPHPExcel)
70
    {
71
        $data = array();
72
73
        foreach ($objPHPExcel as $key => $item)
74
        {
75
            foreach ($item as $value)
76
            {
77
                if (!is_null($value))
78
                {
79
                    $data[$key][] = $value;
80
                }
81
            }
82
        }
83
        
84
        return $data;
85
    }
86
}
87