Passed
Pull Request — master (#1574)
by
unknown
04:47 queued 01:14
created

Hook::assignment()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 3
eloc 5
c 2
b 1
f 0
nc 3
nop 2
dl 0
loc 7
rs 10
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: User
5
 * Date: 2/13/2019
6
 * Time: 5:43 PM
7
 */
8
9
namespace crocodicstudio\crudbooster\types\date;
10
11
use crocodicstudio\crudbooster\types\TypesHook;
12
13
class Hook extends TypesHook
14
{
15
    /**
16
     * @param $row
17
     * @param $column DatetimeModel
0 ignored issues
show
Bug introduced by
The type crocodicstudio\crudboost...ypes\date\DatetimeModel was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
     * @return mixed
19
     */
20
    public function indexRender($row, $column)
21
    {
22
        if($column->getFormat()) {
23
            return date($column->getFormat(), strtotime($row->{$column->getField()}));
24
        }else{
25
            return $row->{$column->getField()};
26
        }
27
    }
28
29
    public function assignment($value, $column)
30
    {
31
	if($column->getFormat()) {
32
		$date = date_create_from_format($column->getFormat(), $value);
33
		return $date ? $date->format('Y-m-d') : $value;
34
	} else {
35
		return $value;
36
	}
37
    }
38
    
39
    public function detailRender($row, $column)
40
    {
41
        return $this->indexRender($row, $column);
42
    }
43
44
    public function filterQuery($query, $column, $value)
45
    {
46
        $start = sanitizeXSS($value['start']);
47
        $end = sanitizeXSS($value['end']);
48
        if($start && $end) {
49
            $start = date("Y-m-d", strtotime($start));
50
            $end = date("Y-m-d", strtotime($end));
51
            $query->whereBetween($column->getFilterColumn(), [$start, $end]);
52
        }
53
        return $query;
54
    }
55
56
}
57