GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — analysis-q1V94y ( 6e252a )
by butschster
08:30
created

Date::getWidth()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SleepingOwl\Admin\Display\Column\Filter;
4
5
use Carbon\Carbon;
6
use Illuminate\Support\Facades\Log;
7
use SleepingOwl\Admin\Traits\DateFormat;
8
use SleepingOwl\Admin\Traits\DatePicker;
9
10
class Date extends Text
11
{
12
    use DatePicker, DateFormat;
13
14
    /**
15
     * @var string
16
     */
17
    protected $view = 'column.filter.date';
18
19
    /**
20
     * @var string
21
     */
22
    protected $format;
23
24
    /**
25
     * @var string
26
     */
27
    protected $searchFormat = 'Y-m-d';
28
29
    /**
30
     * @var bool
31
     */
32
    protected $seconds = false;
33
34
    /**
35
     * @var string
36
     */
37
    protected $timezone;
38
39
    public function initialize()
40
    {
41
        parent::initialize();
42
        $this->setHtmlAttribute('data-type', 'date');
43
    }
44
45
    /**
46
     * @return bool
47
     */
48
    public function hasSeconds()
49
    {
50
        return $this->seconds;
51
    }
52
53
    /**
54
     * @param bool $status
55
     *
56
     * @return $this
57
     * @deprecated use showSeconds
58
     */
59
    public function setSeconds($status)
60
    {
61
        return $this->showSeconds($status);
62
    }
63
64
    /**
65
     * @param bool $status
66
     *
67
     * @return $this
68
     */
69
    public function showSeconds($status = true)
70
    {
71
        $this->seconds = (bool) $status;
72
73
        return $this;
74
    }
75
76
    /**
77
     * @return string
78
     */
79
    public function getPickerFormat()
80
    {
81
        return $this->pickerFormat ?: config('sleeping_owl.dateFormat');
82
    }
83
84
    /**
85
     * @return array
86
     */
87
    public function toArray()
88
    {
89
        return parent::toArray() + [
90
            'seconds' => $this->hasSeconds(),
91
            'pickerFormat' => $this->getJsPickerFormat(),
92
        ];
93
    }
94
95
    /**
96
     * @param string $date
97
     *
98
     * @return string
99
     */
100
    public function parseValue($date)
101
    {
102
        if (empty($date)) {
103
            return;
104
        }
105
106
        if (! $date instanceof Carbon) {
0 ignored issues
show
introduced by
$date is never a sub-type of Carbon\Carbon.
Loading history...
107
            try {
108
                $date = Carbon::parse($date);
109
            } catch (\Exception $e) {
110
                try {
111
                    $date = Carbon::createFromFormat($this->getPickerFormat(), $date);
112
                } catch (\Exception $e) {
113
                    Log::error('Unable to parse date!', [
114
                        'format' => $this->getPickerFormat(),
115
                        'date' => $date,
116
                        'exception' => $e,
117
                    ]);
118
119
                    return;
120
                }
121
            }
122
        }
123
124
        return $date->timezone($this->getTimezone())->format($this->getFormat());
125
    }
126
}
127