Completed
Push — master ( 2aba8e...47e2a2 )
by Andrey
04:14 queued 01:19
created

Cell::getCellValueByColumnAndRow()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 3
1
<?php
2
3
namespace EFParser;
4
5
use EFParserInterface\ICellParser,
6
    EFParserInterface\IExcel;
7
/**
8
 * Class Cell
9
 * Класс для парсинга ячеек
10
 */
11
class Cell implements ICellParser
12
{
13
    private $parser;
14
15
    /**
16
     * Конструктор
17
     *
18
     * @param IExcel $excel (Класс реализующий IExcel интерфейс)
19
     */
20
    public function __construct(IExcel $excel)
21
    {
22
        $this->parser = $excel;
23
    }
24
25
    /**
26
     * Метод для чтения значения ячейки по адресу (A1 etc)
27
     *
28
     * @param string  $cell         (Адрес ячейки)
29
     * @param string  $sheetName    (Название листа, которому пренадлежит эта ячейка)
30
     *
31
     * @return mixed $value        (Значение)
32
     */
33
    public function getCellValue($cell, $sheetName)
34
    {
35
        $value = $this->parser->sourceReader
0 ignored issues
show
Bug introduced by
Accessing sourceReader on the interface EFParserInterface\IExcel suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
36
                              ->load($this->parser->sourceFilePath.$this->parser->sourceFile)
0 ignored issues
show
Bug introduced by
Accessing sourceFilePath on the interface EFParserInterface\IExcel suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
Bug introduced by
Accessing sourceFile on the interface EFParserInterface\IExcel suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
37
                              ->setActiveSheetIndexByName($sheetName)
38
                              ->getCell($cell)
39
                              ->getValue();
40
41
        return $value;
42
    }
43
44
    /**
45
     * Метод для чтения значения ячейки (по координатам)
46
     *
47
     * @param string $column    (Буквенный индекс колонки)
48
     * @param int    $row       (Индекс строки)
49
     * @param string $sheetName (Название листа, которому пренадлежит эта ячейка)
50
     *
51
     * @return mixed $value     (Значение)
52
     */
53
    public function getCellValueByColumnAndRow($column, $row, $sheetName)
54
    {
55
        $value = $this->parser->sourceReader
0 ignored issues
show
Bug introduced by
Accessing sourceReader on the interface EFParserInterface\IExcel suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
56
                              ->load($this->parser->sourceFilePath.$this->parser->sourceFile)
0 ignored issues
show
Bug introduced by
Accessing sourceFilePath on the interface EFParserInterface\IExcel suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
Bug introduced by
Accessing sourceFile on the interface EFParserInterface\IExcel suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
57
                              ->setActiveSheetIndexByName($sheetName)
58
                              ->getCellByColumnAndRow($column, $row)
59
                              ->getValue();
60
61
        return $value;
62
    }
63
64
    /**
65
     * Метод для чтения значениий нескольких ячеек
66
     *
67
     * @param array  $cells     (Массив ячеек)
68
     *
69
     * ```php
70
     * $cells = array("A27", "C28", "I27", "E49");
71
     * ```
72
     * @param string $sheetName (Название листа, которому пренадлежат эти ячейки)
73
     *
74
     * @return array $value     (Массив значений)
75
     */
76
    public function getCellsValues(array $cells, $sheetName)
77
    {
78
        $value = array();
79
80
        foreach ($cells as $cell)
81
        {
82
            $value[$cell] = $this->getCellValue($cell, $sheetName);
83
        }
84
85
        return $value;
86
    }
87
}