Fullcalendar::getOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Edofre\Fullcalendar;
4
5
/**
6
 * Class Fullcalendar
7
 * @package Edofre\Fullcalendar
8
 */
9
class Fullcalendar
10
{
11
    /** @var string */
12
    protected $id = 'fullcalendar';
13
    /** @var array */
14
    protected $events = [];
15
    /** @var array */
16
    protected $defaultOptions = [
17
        'header'   => [
18
            'left'   => 'prev,next today',
19
            'center' => 'title',
20
            'right'  => 'month,agendaWeek,agendaDay',
21
        ],
22
        'firstDay' => 1,
23
    ];
24
    /** @var array */
25
    protected $clientOptions = [];
26
27
    /**
28
     * Renders the view that includes the script files
29
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
30
     */
31
    public static function renderScriptFiles()
32
    {
33
        return view('fullcalendar::files', [
34
            'include_gcal' => config('fullcalendar.enable_gcal'),
35
        ]);
36
    }
37
38
    /**
39
     * @return string
40
     */
41
    public function generate()
42
    {
43
        return $this->calendar() . $this->script();
44
    }
45
46
    /**
47
     * Create the <div> the calendar will be rendered into
48
     * @return string
49
     */
50
    private function calendar()
51
    {
52
        return "<div id='" . $this->getId() . "'></div>";
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function getId()
59
    {
60
        return $this->id;
61
    }
62
63
    /**
64
     * @param $id
65
     */
66
    public function setId($id)
67
    {
68
        $this->id = $id;
69
    }
70
71
    /**
72
     * Get the <script> block to render the calendar
73
     * @return \Illuminate\View\View
74
     */
75
    private function script()
76
    {
77
        return view('fullcalendar::script', [
0 ignored issues
show
Bug introduced by
The method render does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
78
            'id'              => $this->getId(),
79
            'options'         => $this->getOptionsJson(),
80
            'include_scripts' => config('fullcalendar.include_scripts', true),
81
            'include_gcal'    => config('fullcalendar.enable_gcal', false),
82
        ])->render();
83
    }
84
85
    /**
86
     * @return string
87
     */
88
    public function getOptionsJson()
89
    {
90
        $options = $this->getOptions();
91
92
        if (!isset($options['events'])) {
93
            $options['events'] = $this->events;
94
        }
95
96
        // Encode the JSON properly to format the callbacks
97
        return JsonEncoder::encode($options);
98
    }
99
100
101
    /**
102
     * Get the fullcalendar options (not including the events list)
103
     * @return array
104
     */
105
    public function getOptions()
106
    {
107
        return array_merge($this->defaultOptions, $this->clientOptions);
108
    }
109
110
111
    /**
112
     * @param array $options
113
     */
114
    public function setOptions(array $options)
115
    {
116
        $this->clientOptions = $options;
117
    }
118
119
    /**
120
     * @return array
121
     */
122
    public function getEvents()
123
    {
124
        return $this->events;
125
    }
126
127
    /**
128
     * @param mixed $events
129
     */
130
    public function setEvents($events)
131
    {
132
        $this->events = $events;
0 ignored issues
show
Documentation Bug introduced by
It seems like $events of type * is incompatible with the declared type array of property $events.

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...
133
    }
134
}