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

WaitingListRegistrationForm   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 7
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 1
A doRegister() 0 7 1
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 WaitingListRegistrationForm extends Form
18
{
19
    public function __construct($controller, $name = 'CheckInForm')
20
    {
21
        $fields = FieldList::create(
22
            TextField::create('Title', _t('WaitingListRegistration.Name', 'Name')),
23
            TextField::create('Email', _t('WaitingListRegistration.Email', 'Email')),
24
            TextField::create('Telephone', _t('WaitingListRegistration.Telephone', 'Telephone'))
25
        );
26
27
        $actions = FieldList::create(
28
            FormAction::create('doRegister', _t('WaitingListRegistrationForm.REGISTER', 'Register'))
29
        );
30
31
        $required = new RequiredFields(array('Title', 'Email'));
32
33
        parent::__construct($controller, $name, $fields, $actions, $required);
34
        $this->extend('updateWaitingListRegistrationForm');
35
    }
36
37
    /**
38
     * Sets the person on the waiting list
39
     *
40
     * @param                             $data
41
     * @param WaitingListRegistrationForm $form
42
     */
43
    public function doRegister($data, WaitingListRegistrationForm $form)
0 ignored issues
show
Unused Code introduced by
The parameter $data 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...
44
    {
45
        $form->saveInto($registration = WaitingListRegistration::create());
46
        $registration->EventID = $this->getController()->ID;
0 ignored issues
show
Documentation introduced by
The property EventID does not exist on object<Broarm\EventTicke...aitingListRegistration>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
47
        $this->getController()->WaitingList()->add($registration);
48
        $this->getController()->redirect($this->getController()->Link('?waitinglist=1'));
0 ignored issues
show
Unused Code introduced by
The call to Controller::Link() has too many arguments starting with '?waitinglist=1'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
49
    }
50
51
}