Completed
Pull Request — master (#155)
by
unknown
03:10
created

DataRow   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 6
c 3
b 1
f 0
lcom 1
cbo 1
dl 0
loc 73
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getId() 0 4 1
A getSrc() 0 4 1
A src() 0 4 1
extractCellValue() 0 1 ?
A getCellValue() 0 5 2
1
<?php
2
namespace Nayjest\Grids;
3
4
/**
5
 * Class DataRow
6
 *
7
 * Abstract class for DataRowInterface implementations
8
 *
9
 * @package Nayjest\Grids
10
 */
11
abstract class DataRow implements DataRowInterface
12
{
13
14
    /** @var  mixed row data */
15
    protected $src;
16
17
    /** @var int row id */
18
    protected $id;
19
20
    /**
21
     * Constructor.
22
     *
23
     * @param $src
24
     * @param int $id
25
     */
26
    public function __construct($src, $id)
27
    {
28
        $this->src = $src;
29
        $this->id = $id;
30
    }
31
32
    /**
33
     * Returns row id.
34
     *
35
     * It's row number starting from 1, considering pagination.
36
     *
37
     * @return mixed
38
     */
39
    public function getId()
40
    {
41
        return $this->id;
42
    }
43
44
    /**
45
     * Returns row data source.
46
     *
47
     * @return mixed
48
     */
49
    public function getSrc()
50
    {
51
        return $this->src;
52
    }
53
54
    /**
55
     * Returns row data source.
56
     *
57
     * @return mixed
58
     */
59
    public function src()
60
    {
61
        return $this->getSrc();
62
    }
63
64
    /**
65
     * Returns value for specified column.
66
     *
67
     * @param string $fieldName
68
     * @return mixed
69
     */
70
    abstract protected function extractCellValue($fieldName);
71
72
    /**
73
     * Returns value of specified column from row.
74
     *
75
     * @param FieldConfig|string $field
76
     * @return mixed
77
     */
78
    public function getCellValue($field)
79
    {
80
        $fieldName = $field instanceof FieldConfig ? $field->getName() : $field;
81
        return $this->extractCellValue($fieldName);
82
    }
83
}
84