PurchaseForm::__construct()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 19
nc 2
nop 1
dl 0
loc 28
rs 8.8571
c 0
b 0
f 0
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
}