Completed
Push — master ( cc2184...cecba6 )
by Bram
10:11
created

TicketControllerExtension   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 0
loc 58
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A TicketForm() 0 10 3
A WaitingListRegistrationForm() 0 8 2
A checkIn() 0 4 1
A getWaitingListSuccess() 0 4 1
1
<?php
2
/**
3
 * TicketControllerExtension.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 Extension;
13
14
/**
15
 * Class TicketControllerExtension
16
 *
17
 * @package Broarm\EventTickets
18
 *
19
 * @property TicketControllerExtension|TicketExtension|CalendarEvent_Controller $owner
20
 */
21
class TicketControllerExtension extends Extension
22
{
23
    private static $allowed_actions = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $allowed_actions 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...
24
        'TicketForm',
25
        'WaitingListRegistrationForm',
26
        'checkin'
27
    );
28
29
    /**
30
     * Get the ticket form with available tickets
31
     *
32
     * @return TicketForm
0 ignored issues
show
Documentation introduced by
Should the return type not be TicketForm|null?

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...
33
     */
34
    public function TicketForm()
35
    {
36
        if ($this->owner->Tickets()->count() && $this->owner->getAvailability() > 0) {
1 ignored issue
show
Bug introduced by
The method getAvailability does only exist in Broarm\EventTickets\TicketExtension, but not in Broarm\EventTickets\Tick...alendarEvent_Controller.

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...
37
            $ticketForm = new TicketForm($this->owner, 'TicketForm', $this->owner->Tickets(), $this->owner->dataRecord);
38
            $ticketForm->setNextStep(CheckoutSteps::start());
39
            return $ticketForm;
40
        } else {
41
            return null;
42
        }
43
    }
44
45
    /**
46
     * show the waiting list form when the event is sold out
47
     *
48
     * @return WaitingListRegistrationForm
0 ignored issues
show
Documentation introduced by
Should the return type not be WaitingListRegistrationForm|null?

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...
49
     */
50
    public function WaitingListRegistrationForm()
51
    {
52
        if ($this->owner->Tickets()->count()) {
53
            return new WaitingListRegistrationForm($this->owner, 'WaitingListRegistrationForm');
54
        } else {
55
            return null;
56
        }
57
    }
58
59
    /**
60
     * Go to the check in controller
61
     *
62
     * @return CheckInController
63
     */
64
    public function checkIn()
65
    {
66
        return new CheckInController($this->owner->dataRecord);
67
    }
68
69
    /**
70
     * Checks the waiting list var
71
     *
72
     * @return mixed
73
     */
74
    public function getWaitingListSuccess()
75
    {
76
        return $this->owner->getRequest()->getVar('waitinglist');
77
    }
78
}
79