Excel   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 76
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

3 Methods

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