Completed
Push — master ( b004b4...a833f9 )
by Bram
01:53
created

TicketExtension::getTicketsSoldOut()   A

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
 * TicketExtension.php
4
 *
5
 * @author Bram de Leeuw
6
 * Date: 09/03/17
7
 */
8
9
namespace Broarm\EventTickets;
10
11
use CalendarEvent_Controller;
12
use DataExtension;
13
use FieldList;
14
use GridField;
15
use GridFieldConfig_RecordEditor;
16
use HasManyList;
17
use HtmlEditorField;
18
use LiteralField;
19
use NumericField;
20
use SiteConfig;
21
22
/**
23
 * Class TicketExtension
24
 *
25
 * @package Broarm\EventTickets
26
 *
27
 * @property TicketExtension|\CalendarEvent $owner
28
 * @property int                            Capacity
29
 * @property int                            OrderMin
30
 * @property int                            OrderMax
31
 * @property string                         SuccessMessage
32
 * @property string                         SuccessMessageMail
33
 *
34
 * @method \HasManyList Tickets()
35
 * @method \HasManyList Reservations()
36
 * @method \HasManyList Attendees()
37
 * @method \HasManyList WaitingList()
38
 * @method \HasManyList Fields()
39
 */
40
class TicketExtension extends DataExtension
41
{
42
    /**
43
     * @var CalendarEvent_Controller
44
     */
45
    protected $controller;
46
47
    private static $db = array(
0 ignored issues
show
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
48
        'Capacity' => 'Int',
49
        'OrderMin' => 'Int',
50
        'OrderMax' => 'Int',
51
        'SuccessMessage' => 'HTMLText',
52
        'SuccessMessageMail' => 'HTMLText'
53
    );
54
55
    private static $has_many = array(
0 ignored issues
show
Unused Code introduced by
The property $has_many is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
56
        'Tickets' => 'Broarm\EventTickets\Ticket.Event',
57
        'Reservations' => 'Broarm\EventTickets\Reservation.Event',
58
        'Attendees' => 'Broarm\EventTickets\Attendee.Event',
59
        'WaitingList' => 'Broarm\EventTickets\WaitingListRegistration.Event',
60
        'Fields' => 'Broarm\EventTickets\UserField.Event'
61
    );
62
63
    private static $defaults = array(
0 ignored issues
show
Unused Code introduced by
The property $defaults is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
64
        'Capacity' => 50
65
    );
66
67
    private static $translate = array(
0 ignored issues
show
Unused Code introduced by
The property $translate is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
68
        'SuccessMessage',
69
        'SuccessMessageMail'
70
    );
71
72
    public function updateCMSFields(FieldList $fields)
73
    {
74
        $ticketLabel = _t('TicketExtension.Tickets', 'Tickets');
75
        $fields->addFieldsToTab(
76
            "Root.$ticketLabel", array(
77
            GridField::create('Tickets', $ticketLabel, $this->owner->Tickets(), TicketsGridFieldConfig::create($this->canCreateTickets())),
1 ignored issue
show
Bug introduced by
The method Tickets does only exist in Broarm\EventTickets\TicketExtension, but not in CalendarEvent.

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
            NumericField::create('Capacity', _t('TicketExtension.Capacity', 'Capacity')),
79
            HtmlEditorField::create('SuccessMessage', _t('TicketExtension.SuccessMessage', 'Success message'))->setRows(4),
80
            HtmlEditorField::create('SuccessMessageMail', _t('TicketExtension.MailMessage', 'Mail message'))->setRows(4)
81
        ));
82
83
        // Create Reservations tab
84
        if ($this->owner->Reservations()->exists()) {
85
            $reservationLabel = _t('TicketExtension.Reservations', 'Reservations');
86
            $fields->addFieldToTab(
87
                "Root.$reservationLabel",
88
                GridField::create('Reservations', $reservationLabel, $this->owner->Reservations(), GridFieldConfig_RecordEditor::create())
1 ignored issue
show
Bug introduced by
The method Reservations does only exist in Broarm\EventTickets\TicketExtension, but not in CalendarEvent.

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...
89
            );
90
        }
91
92
        // Create Attendees tab
93 View Code Duplication
        if ($this->owner->Attendees()->exists()) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
94
            $guestListLabel = _t('TicketExtension.GuestList', 'GuestList');
95
            $fields->addFieldToTab(
96
                "Root.$guestListLabel",
97
                GridField::create('Attendees', $guestListLabel, $this->owner->Attendees(), GuestListGridFieldConfig::create($this->owner))
1 ignored issue
show
Bug introduced by
The method Attendees does only exist in Broarm\EventTickets\TicketExtension, but not in CalendarEvent.

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...
98
            );
99
        }
100
101
        // Create WaitingList tab
102 View Code Duplication
        if ($this->owner->WaitingList()->exists()) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
103
            $waitingListLabel = _t('TicketExtension.WaitingList', 'WaitingList');
104
            $fields->addFieldToTab(
105
                "Root.$waitingListLabel",
106
                GridField::create('WaitingList', $waitingListLabel, $this->owner->WaitingList(), GridFieldConfig_RecordEditor::create())
1 ignored issue
show
Bug introduced by
The method WaitingList does only exist in Broarm\EventTickets\TicketExtension, but not in CalendarEvent.

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...
107
            );
108
        }
109
110
        // Create Fields tab
111
        $extraFieldsLabel = _t('TicketExtension.ExtraFields', 'Attendee fields');
112
        $fields->addFieldToTab(
113
            "Root.$extraFieldsLabel",
114
            GridField::create('ExtraFields', $extraFieldsLabel, $this->owner->Fields(), UserFieldsGridFieldConfig::create())
1 ignored issue
show
Bug introduced by
The method Fields does only exist in Broarm\EventTickets\TicketExtension, but not in CalendarEvent.

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...
115
        );
116
117
        $this->owner->extend('updateTicketExtensionFields', $fields);
118
    }
119
120
    /**
121
     * Trigger actions after write
122
     */
123
    public function onAfterWrite()
124
    {
125
        $this->createDefaultFields();
126
        parent::onAfterWrite();
127
    }
128
129
    /**
130
     * Creates and sets up the default fields
131
     */
132
    public function createDefaultFields()
133
    {
134
        $fields = Attendee::config()->get('default_fields');
135
        if (!$this->owner->Fields()->exists()) {
136
            foreach ($fields as $fieldName => $config) {
137
                $field = UserField::createDefaultField($fieldName, $config);
138
                $this->owner->Fields()->add($field);
1 ignored issue
show
Bug introduced by
The method Fields does only exist in Broarm\EventTickets\TicketExtension, but not in CalendarEvent.

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...
139
            }
140
        }
141
    }
142
143
    /**
144
     * Extend the page actions with an start check in action
145
     *
146
     * @param FieldList $actions
147
     */
148
    public function updateCMSActions(FieldList $actions)
149
    {
150
        $checkInButton = new LiteralField('StartCheckIn',
151
            "<a class='action ss-ui-button ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only'
152
                id='Edit_StartCheckIn'
153
                role='button'
154
                href='{$this->owner->Link('checkin')}'
155
                target='_blank'>
156
                Start check in
157
            </a>"
158
        );
159
160
        if ($this->owner->Attendees()->exists()) {
1 ignored issue
show
Bug introduced by
The method Attendees does only exist in Broarm\EventTickets\TicketExtension, but not in CalendarEvent.

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...
161
            $actions->push($checkInButton);
162
        }
163
    }
164
165
    /**
166
     * Get the leftover capacity
167
     *
168
     * @return int
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|double?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
169
     */
170
    public function getAvailability()
171
    {
172
        return $this->owner->Capacity - $this->owner->getGuestList()->count();
1 ignored issue
show
Bug introduced by
The method getGuestList does only exist in Broarm\EventTickets\TicketExtension, but not in CalendarEvent.

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...
173
    }
174
175
    /**
176
     * Check if the tickets are still available
177
     *
178
     * @return bool
179
     */
180
    public function getTicketsAvailable()
181
    {
182
        return $this->owner->getAvailability() > 0;
1 ignored issue
show
Bug introduced by
The method getAvailability does only exist in Broarm\EventTickets\TicketExtension, but not in CalendarEvent.

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...
183
    }
184
185
    /**
186
     * Check if the tickets are sold out
187
     * @return bool
188
     */
189
    public function getTicketsSoldOut()
190
    {
191
        return $this->owner->getAvailability() <= 0;
1 ignored issue
show
Bug introduced by
The method getAvailability does only exist in Broarm\EventTickets\TicketExtension, but not in CalendarEvent.

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...
192
    }
193
194
    /**
195
     * get The sale start date
196
     *
197
     * @return \SS_DateTime
198
     */
199
    public function getTicketSaleStartDate()
200
    {
201
        $saleStart = null;
202
        if (($tickets = $this->owner->Tickets())) {
0 ignored issues
show
Unused Code introduced by
$tickets is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
203
            /** @var Ticket $ticket */
204
            foreach ($this->owner->Tickets() as $ticket) {
1 ignored issue
show
Bug introduced by
The method Tickets does only exist in Broarm\EventTickets\TicketExtension, but not in CalendarEvent.

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...
205
                if (($date = $ticket->getAvailableFrom()) && strtotime($date) < strtotime($saleStart) || $saleStart === null) {
206
                    $saleStart = $date;
207
                }
208
            }
209
        }
210
211
        return $saleStart;
212
    }
213
214
    /**
215
     * Check if the event is expired, either by unavailable tickets or because the date has passed
216
     *
217
     * @return bool
218
     */
219
    public function getEventExpired()
220
    {
221
        $expired = false;
222
        if (($tickets = $this->owner->Tickets()) && $expired = $tickets->exists()) {
223
            /** @var Ticket $ticket */
224
            foreach ($this->owner->Tickets() as $ticket) {
1 ignored issue
show
Bug introduced by
The method Tickets does only exist in Broarm\EventTickets\TicketExtension, but not in CalendarEvent.

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...
225
                $expired = (!$ticket->validateDate() && $expired);
226
            }
227
        }
228
229
        return $expired;
230
    }
231
232
    /**
233
     * Check if the ticket sale is still pending
234
     *
235
     * @return bool
236
     */
237
    public function getTicketSalePending()
238
    {
239
        return time() < strtotime($this->owner->getTicketSaleStartDate());
1 ignored issue
show
Bug introduced by
The method getTicketSaleStartDate does only exist in Broarm\EventTickets\TicketExtension, but not in CalendarEvent.

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...
240
    }
241
242
    /**
243
     * Get only the attendees who are certain to attend
244
     * Fixme: Using callback filter instead of join, because join gives ambiguous error on 'EventID'
245
     *
246
     * @return \ArrayList
247
     */
248
    public function getGuestList()
249
    {
250
        return $this->owner->Attendees()->filterByCallback(function(Attendee $attendee, HasManyList $list) {
1 ignored issue
show
Bug introduced by
The method Attendees does only exist in Broarm\EventTickets\TicketExtension, but not in CalendarEvent.

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...
Unused Code introduced by
The parameter $list is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
251
            return $attendee->Reservation()->Status === 'PAID';
252
        });
253
    }
254
255
    /**
256
     * Get the success message
257
     *
258
     * @return mixed|string
259
     */
260 View Code Duplication
    public function getSuccessContent()
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...
261
    {
262
        if (!empty($this->owner->SuccessMessage)) {
263
            return $this->owner->dbObject('SuccessMessage');
264
        } else {
265
            return SiteConfig::current_site_config()->dbObject('SuccessMessage');
266
        }
267
    }
268
269
    /**
270
     * Get the mail message
271
     *
272
     * @return mixed|string
273
     */
274 View Code Duplication
    public function getMailContent()
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...
275
    {
276
        if (!empty($this->owner->SuccessMessageMail)) {
277
            return $this->owner->dbObject('SuccessMessageMail');
278
        } else {
279
            return SiteConfig::current_site_config()->dbObject('SuccessMessageMail');
280
        }
281
    }
282
283
    /**
284
     * Get the Ticket logo
285
     *
286
     * @return \Image
287
     */
288
    public function getMailLogo()
289
    {
290
        return SiteConfig::current_site_config()->TicketLogo();
291
    }
292
293
    /**
294
     * Check if the current event can have tickets
295
     *
296
     * @return bool
297
     */
298
    public function canCreateTickets()
299
    {
300
        $currentDate = $this->owner->getController()->CurrentDate();
1 ignored issue
show
Bug introduced by
The method getController does only exist in Broarm\EventTickets\TicketExtension, but not in CalendarEvent.

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...
301
        if ($currentDate && $currentDate->exists()) {
302
            return $currentDate->dbObject('StartDate')->InFuture();
303
        }
304
305
        return false;
306
    }
307
308
    /**
309
     * Get the calendar controller
310
     *
311
     * @return CalendarEvent_Controller
312
     */
313
    public function getController()
314
    {
315
        return $this->controller
316
            ? $this->controller
317
            : $this->controller = CalendarEvent_Controller::create($this->owner);
318
    }
319
}
320