PurchaseForm::__construct()   B
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 29
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 19
nc 3
nop 1
dl 0
loc 29
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace ConferenceTools\Tickets\Form;
4
5
use ConferenceTools\Tickets\Domain\ReadModel\TicketRecord\PurchaseRecord;
6
use ConferenceTools\Tickets\Domain\ReadModel\TicketRecord\TicketRecord;
7
use ConferenceTools\Tickets\Domain\ValueObject\Delegate;
8
use ConferenceTools\Tickets\Form\Fieldset\DelegateInformation;
9
use ConferenceTools\Tickets\Hydrator\DelegateHydrator;
0 ignored issues
show
Bug introduced by
The type ConferenceTools\Tickets\Hydrator\DelegateHydrator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Zend\Form\Element\Collection;
11
use Zend\Form\Element\Csrf;
12
use Zend\Form\Element\Hidden;
13
use Zend\Form\Element\Text;
14
use Zend\Form\Form;
15
use Zend\Validator\EmailAddress;
16
use Zend\Validator\NotEmpty;
17
18
class PurchaseForm extends Form
19
{
20
    public function __construct(PurchaseRecord $purchase)
21
    {
22
        parent::__construct('delegate-form');
23
        $this->add(['type' => Hidden::class, 'name' => 'stripe_token']);
24
        $this->add([
25
            'type' => Text::class,
26
            'name' => 'purchase_email',
27
            'options' => [
28
                'label' => 'Email',
29
                'help-block' => 'Your receipt will be emailed to this address'
30
            ]
31
        ]);
32
33
        foreach ($purchase->getTickets() as $i => $ticket) {
34
            /** @var TicketRecord $ticket */
35
            if (!$ticket->getTicketType()->isSupplementary()) {
36
                $this->add(['type' => DelegateInformation::class, 'name' => 'delegates_' . $i]);
37
            }
38
        }
39
40
        $this->add(new Csrf('security'));
41
42
        $this->getInputFilter()
0 ignored issues
show
Deprecated Code introduced by
The function Zend\InputFilter\InputInterface::setAllowEmpty() has been deprecated: 2.4.8 Add Zend\Validator\NotEmpty validator to the ValidatorChain and set this to `true`. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

42
        /** @scrutinizer ignore-deprecated */ $this->getInputFilter()

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
43
            ->get('purchase_email')
44
            ->setAllowEmpty(false)
0 ignored issues
show
Bug introduced by
The method setAllowEmpty() does not exist on Zend\InputFilter\InputFilterInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
            ->/** @scrutinizer ignore-call */ setAllowEmpty(false)

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45
            ->setRequired(true)
0 ignored issues
show
Bug introduced by
The method setRequired() does not exist on Zend\InputFilter\InputFilterInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
            ->/** @scrutinizer ignore-call */ setRequired(true)

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
            ->getValidatorChain()
0 ignored issues
show
Bug introduced by
The method getValidatorChain() does not exist on Zend\InputFilter\InputFilterInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
            ->/** @scrutinizer ignore-call */ getValidatorChain()

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
47
            ->attach(new NotEmpty())
48
            ->attach(new EmailAddress());
49
50
    }
51
}