PurchaseForm   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 28 2
1
<?php
2
3
namespace ConferenceTools\Tickets\Form;
4
5
use ConferenceTools\Tickets\Domain\ValueObject\Delegate;
6
use ConferenceTools\Tickets\Form\Fieldset\DelegateInformation;
7
use ConferenceTools\Tickets\Hydrator\DelegateHydrator;
8
use Zend\Form\Element\Collection;
9
use Zend\Form\Element\Csrf;
10
use Zend\Form\Element\Hidden;
11
use Zend\Form\Element\Text;
12
use Zend\Form\Form;
13
use Zend\Validator\EmailAddress;
14
use Zend\Validator\NotEmpty;
15
16
class PurchaseForm extends Form
17
{
18
    public function __construct($tickets)
19
    {
20
        parent::__construct('delegate-form');
21
        $this->add(['type' => Hidden::class, 'name' => 'stripe_token']);
22
        $this->add([
23
            'type' => Text::class,
24
            'name' => 'purchase_email',
25
            'options' => [
26
                'label' => 'Email',
27
                'help-block' => 'Your receipt will be emailed to this address'
28
            ]
29
        ]);
30
31
        for ($i = 0; $i < $tickets; $i++) {
32
            $this->add(['type' => DelegateInformation::class, 'name' => 'delegates_' . $i]);
33
        }
34
35
        $this->add(new Csrf('security'));
36
37
        $this->getInputFilter()
38
            ->get('purchase_email')
39
            ->setAllowEmpty(false)
40
            ->setRequired(true)
41
            ->getValidatorChain()
42
            ->attach(new NotEmpty())
43
            ->attach(new EmailAddress());
44
45
    }
46
}