Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — master ( 09719b...ca9302 )
by Cristian
04:21
created

date_range.blade.php ➔ formatDate()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 3
nop 2
dl 0
loc 13
rs 8.8571
c 0
b 0
f 0
1
<!-- bootstrap daterange picker input -->
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 6 and the first side effect is on line 1.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
<?php
4
    // if the column has been cast to Carbon or Date (using attribute casting)
5
    // get the value as a date string
6
    function formatDate($entry, $dateFieldName)
7
    {
8
        $formattedDate = null;
9
        if (isset($entry) && !empty($entry->{$dateFieldName})) {
10
            $dateField = $entry->{$dateFieldName};
11
            if ($dateField instanceof \Carbon\Carbon || $dateField instanceof \Jenssegers\Date\Date) {
12
                $formattedDate = $dateField->format('Y-m-d H:i:s');
13
            } else {
14
                $formattedDate = date('Y-m-d H:i:s', strtotime($entry->{$dateFieldName}));
15
            }
16
        }
17
        return $formattedDate;
18
    }
19
20
    $start_name = formatDate($entry, $field['start_name']);
21
    $end_name = formatDate($entry, $field['end_name']);
22
?>
23
24
<div @include('crud::inc.field_wrapper_attributes') >
25
    <input class="datepicker-range-start" type="hidden" name="{{ $field['start_name'] }}" value="{{ old($field['start_name']) ? old($field['start_name']) : (isset($start_name) ? $start_name : (isset($field['start_default']) ? $field['start_default'] : '' )) }}">
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 262 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
26
    <input class="datepicker-range-end" type="hidden" name="{{ $field['end_name'] }}" value="{{ old($field['end_name']) ? old($field['end_name']) : (!empty($end_name) ? $end_name : (isset($field['end_default']) ? $field['end_default'] : '' )) }}">
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 247 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
27
    <label>{!! $field['label'] !!}</label>
28
    <div class="input-group date">
29
        <input
30
            data-bs-daterangepicker="{{ isset($field['date_range_options']) ? json_encode($field['date_range_options']) : '{}'}}"
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 129 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
31
            type="text"
32
            @include('crud::inc.field_attributes')
33
            >
34
        <div class="input-group-addon">
35
            <span class="glyphicon glyphicon-calendar"></span>
36
        </div>
37
    </div>
38
39
    {{-- HINT --}}
40
    @if (isset($field['hint']))
41
        <p class="help-block">{!! $field['hint'] !!}</p>
42
    @endif
43
</div>
44
45
{{-- ########################################## --}}
46
{{-- Extra CSS and JS for this particular field --}}
47
{{-- If a field type is shown multiple times on a form, the CSS and JS will only be loaded once --}}
48
@if ($crud->checkIfFieldIsFirstOfItsType($field, $fields))
49
50
    {{-- FIELD CSS - will be loaded in the after_styles section --}}
51
    @push('crud_fields_styles')
52
    <link rel="stylesheet" href="{{ asset('/vendor/adminlte/plugins/daterangepicker/daterangepicker.css') }}">
53
    @endpush
54
55
    {{-- FIELD JS - will be loaded in the after_scripts section --}}
56
    @push('crud_fields_scripts')
57
    <script src="{{ asset('/vendor/adminlte/plugins/daterangepicker/moment.min.js') }}"></script>
58
    <script src="{{ asset('/vendor/adminlte/plugins/daterangepicker/daterangepicker.js') }}"></script>
59
    <script>
60
        jQuery(document).ready(function($){
61
            $('[data-bs-daterangepicker]').each(function(){
62
63
                var $fake = $(this),
64
                $start = $fake.parents('.form-group').find('.datepicker-range-start'),
65
                $end = $fake.parents('.form-group').find('.datepicker-range-end'),
66
                $customConfig = $.extend({
67
                    format: 'dd/mm/yyyy',
68
                    autoApply: true,
69
                    startDate: moment($start.val()),
70
                    endDate: moment($end.val())
71
                }, $fake.data('bs-daterangepicker'));
72
73
                $fake.daterangepicker($customConfig);
74
                $picker = $fake.data('daterangepicker');
75
76
                $fake.on('keydown', function(e){
77
                    e.preventDefault();
78
                    return false;
79
                });
80
81
                $fake.on('apply.daterangepicker hide.daterangepicker', function(e, picker){
82
                    $start.val( picker.startDate.format('YYYY-MM-DD HH:mm:ss') );
83
                    $end.val( picker.endDate.format('YYYY-MM-DD H:mm:ss') );
84
                });
85
86
            });
87
        });
88
    </script>
89
    @endpush
90
91
@endif
92
{{-- End of Extra CSS and JS --}}
93