CheckInForm   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 1
A doCheckIn() 0 19 4
1
<?php
2
/**
3
 * CheckInForm.php
4
 *
5
 * @author Bram de Leeuw
6
 * Date: 07/04/17
7
 */
8
9
namespace Broarm\EventTickets;
10
11
use FieldList;
12
use Form;
13
use FormAction;
14
use RequiredFields;
15
use TextField;
16
17
class CheckInForm extends Form
18
{
19
    public function __construct($controller, $name = 'CheckInForm')
20
    {
21
        $fields = FieldList::create(
22
            TextField::create('TicketCode', _t('CheckInForm.TICKET_CODE', 'Ticket code'))
23
                ->setAttribute('autofocus', true)
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
24
        );
25
26
        $actions = FieldList::create(
27
            FormAction::create('doCheckIn', _t('CheckInForm.CheckIn', 'Check in'))
28
        );
29
30
        $required = new RequiredFields(array('TicketCode'));
31
        parent::__construct($controller, $name, $fields, $actions, $required);
32
        $this->extend('onAfterConstruct');
33
    }
34
35
    /**
36
     * Do the check in, if all checks pass return a success
37
     *
38
     * @param             $data
39
     * @param CheckInForm $form
40
     *
41
     * @return \SS_HTTPResponse
42
     */
43
    public function doCheckIn($data, CheckInForm $form)
44
    {
45
        /** @var CheckInController $controller */
46
        $controller = $form->getController();
47
        $validator = CheckInValidator::create();
48
        $result = $validator->validate($data['TicketCode']);
49
        switch ($result['Code']) {
50
            case CheckInValidator::MESSAGE_CHECK_OUT_SUCCESS:
51
                $validator->getAttendee()->checkOut();
52
                break;
53
            case CheckInValidator::MESSAGE_CHECK_IN_SUCCESS:
54
                $validator->getAttendee()->checkIn();
55
                break;
56
        }
57
        
58
        $form->sessionMessage($result['Message'], strtolower($result['Type']), false);
59
        $this->extend('onAfterCheckIn', $response, $form, $result);
60
        return $response ? $response : $controller->redirect($controller->Link());
61
    }
62
}