PersonFormTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 2 Features 0
Metric Value
eloc 38
c 5
b 2
f 0
dl 0
loc 59
ccs 38
cts 38
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addPersonFormFields() 0 46 2
A addFieldIfEnabled() 0 3 2
1
<?php
2
3
namespace Bone\User\Form;
4
5
use Del\Form\Field\FieldInterface;
6
use Del\Form\Field\Hidden;
7
use Del\Form\Field\Select;
8
use Del\Form\Field\Text;
9
use Del\Form\FormInterface;
10
use Del\Form\Transformer\CountryTransformer;
11
use Del\Repository\CountryRepository;
12
13
trait PersonFormTrait
14
{
15
    /** @var array $disabledFields */
16
    protected $disabledFields = [];
17
18
    /**
19
     * @param FormInterface $form
20
     */
21 1
    public function addPersonFormFields(FormInterface $form): void
22
    {
23 1
        $firstName = new Text('firstname');
24 1
        $firstName->setLabel('First name');
25 1
        $firstName->setRequired(true);
26
27 1
        $middleName = new Text('middlename');
28 1
        $middleName->setLabel('Middle name');
29
30 1
        $lastName = new Text('lastname');
31 1
        $lastName->setLabel('Last name');
32 1
        $lastName->setRequired(true);
33
34 1
        $aka = new Text('aka');
35 1
        $aka->setLabel('A.K.A.');
36
37 1
        $dob = new Text\Date('dob', 'd/m/Y');
38 1
        $dob->setLabel('Date of Birth');
39 1
        $dob->setClass('form-control datepicker');
40 1
        $dob->setRequired(true);
41
42 1
        $birthPlace = new Text('birthplace');
43 1
        $birthPlace->setLabel('Birth place');
44
45 1
        $country = new Select('country');
46 1
        $country->setLabel('Country');
47 1
        $country->setTransformer(new CountryTransformer());
48 1
        $countryRepository = new CountryRepository();
49 1
        $countries = $countryRepository->findAllCountries();
50 1
        $country->setRequired(true);
51 1
        $country->setOption('', '');
52 1
        foreach ($countries as $c) {
53 1
            $country->setOption($c->getIso(), $c->getName());
54
        }
55
56 1
        $image = new Hidden('image');
57 1
        $image->setId('image');
58
59 1
        $this->addFieldIfEnabled('firstname', $firstName, $form);
60 1
        $this->addFieldIfEnabled('middlename', $middleName, $form);
61 1
        $this->addFieldIfEnabled('lastname', $lastName, $form);
62 1
        $this->addFieldIfEnabled('aka', $aka, $form);
63 1
        $this->addFieldIfEnabled('dob', $dob, $form);
64 1
        $this->addFieldIfEnabled('birthplace', $birthPlace, $form);
65 1
        $this->addFieldIfEnabled('country', $country, $form);
66 1
        $this->addFieldIfEnabled('image', $image, $form);
67
    }
68
69 1
    private function addFieldIfEnabled(string $name, FieldInterface $field, FormInterface $form)
70
    {
71 1
        in_array($name, $this->disabledFields) ? null : $form->addField($field);
72
    }
73
}
74