Completed
Push — master ( 4cc8d8...e56a52 )
by Arjay
04:43
created

RowProcessor   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 69
c 1
b 0
f 0
wmc 9
lcom 1
cbo 2
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A rowValue() 0 12 4
A rowData() 0 11 3
A getData() 0 4 1
1
<?php
2
3
namespace Yajra\Datatables\Processors;
4
5
use Illuminate\Support\Arr;
6
use Yajra\Datatables\Helper;
7
8
/**
9
 * Class RowProcessor
10
 *
11
 * @package Yajra\Datatables
12
 */
13
class RowProcessor
14
{
15
    /**
16
     * @var mixed
17
     */
18
    private $data;
19
20
    /**
21
     * @var mixed
22
     */
23
    private $row;
24
25
    /**
26
     * @param mixed $data
27
     * @param mixed $row
28
     */
29
    public function __construct($data, $row)
30
    {
31
        $this->data = $data;
32
        $this->row  = $row;
33
    }
34
35
    /**
36
     * Process DT RowId and Class value.
37
     *
38
     * @param string $attribute
39
     * @param string|callable $template
40
     * @return $this
41
     */
42
    public function rowValue($attribute, $template)
43
    {
44
        if (! empty($template)) {
45
            if (! is_callable($template) && Arr::get($this->data, $template)) {
46
                $this->data[$attribute] = Arr::get($this->data, $template);
47
            } else {
48
                $this->data[$attribute] = Helper::compileContent($template, $this->data, $this->row);
49
            }
50
        }
51
52
        return $this;
53
    }
54
55
    /**
56
     * Process DT Row Data and Attr.
57
     *
58
     * @param string $attribute
59
     * @param array $template
60
     * @return $this
61
     */
62
    public function rowData($attribute, array $template)
63
    {
64
        if (count($template)) {
65
            $this->data[$attribute] = [];
66
            foreach ($template as $key => $value) {
67
                $this->data[$attribute][$key] = Helper::compileContent($value, $this->data, $this->row);
68
            }
69
        }
70
71
        return $this;
72
    }
73
74
    /**
75
     * @return mixed
76
     */
77
    public function getData()
78
    {
79
        return $this->data;
80
    }
81
}
82