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.
Completed
Push — master ( 414922...a9bc98 )
by butschster
12:35
created

DateRange   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 104
Duplicated Lines 19.23 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 20
loc 104
rs 10
c 1
b 0
f 0
wmc 12
lcom 1
cbo 3

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultFrom() 10 10 3
A setDefaultFrom() 0 6 1
A getDefaultTo() 10 10 3
A setDefaultTo() 0 6 1
A setValue() 0 8 2
A toArray() 0 7 1
A parseValue() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace SleepingOwl\Admin\Form\Element;
4
5
use Carbon\Carbon;
6
use Illuminate\Database\Eloquent\Model;
7
8
class DateRange extends Date
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $format = 'Y-m-d';
14
15
    /**
16
     * @var string
17
     */
18
    protected $defaultFrom;
19
20
    /**
21
     * @var string
22
     */
23
    protected $defaultTo;
24
25
    /**
26
     * @return string
27
     */
28 View Code Duplication
    public function getDefaultFrom()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30
        if (! $this->defaultFrom) {
31
            $this->defaultFrom = Carbon::now();
0 ignored issues
show
Documentation Bug introduced by
It seems like \Carbon\Carbon::now() of type object<Carbon\Carbon> is incompatible with the declared type string of property $defaultFrom.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
32
        }
33
34
        return $this->defaultFrom instanceof \DateTime
35
            ? $this->defaultFrom->format(config('sleeping_owl.dateFormat', $this->getPickerFormat()))
36
            : $this->defaultFrom;
37
    }
38
39
    /**
40
     * @param string $defaultFrom
41
     *
42
     * @return $this
43
     */
44
    public function setDefaultFrom($defaultFrom)
45
    {
46
        $this->defaultFrom = $defaultFrom;
47
48
        return $this;
49
    }
50
51
    /**
52
     * @return string
53
     */
54 View Code Duplication
    public function getDefaultTo()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
    {
56
        if (! $this->defaultTo) {
57
            $this->defaultTo = Carbon::now();
0 ignored issues
show
Documentation Bug introduced by
It seems like \Carbon\Carbon::now() of type object<Carbon\Carbon> is incompatible with the declared type string of property $defaultTo.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
58
        }
59
60
        return $this->defaultTo instanceof \DateTime
61
            ? $this->defaultTo->format(config('sleeping_owl.dateFormat', $this->getPickerFormat()))
62
            : $this->defaultTo;
63
    }
64
65
    /**
66
     * @param string $defaultTo
67
     *
68
     * @return $this
69
     */
70
    public function setDefaultTo($defaultTo)
71
    {
72
        $this->defaultTo = $defaultTo;
73
74
        return $this;
75
    }
76
77
    /**
78
     * @param Model $model
79
     * @param string $attribute
80
     * @param mixed $value
81
     */
82
    public function setValue(Model $model, $attribute, $value)
83
    {
84
        $value = ! empty($value) ? array_map(function ($date) {
85
            return Carbon::createFromFormat($this->getPickerFormat(), $date);
86
        }, explode('::', $value)) : null;
87
88
        $model->setAttribute($attribute, $value);
89
    }
90
91
    /**
92
     * @return array
93
     */
94
    public function toArray()
95
    {
96
        return parent::toArray() + [
97
            'startDate' => $this->getDefaultFrom(),
98
            'endDate' => $this->getDefaultTo(),
99
        ];
100
    }
101
102
    /**
103
     * @param string $value
104
     *
105
     * @return string|void
106
     */
107
    protected function parseValue($value)
108
    {
109
        dd($value);
110
    }
111
}
112