Conditions | 10 |
Paths | 13 |
Total Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
32 | public function __construct(Attendee $attendee, $main = false, $required = true) |
||
33 | { |
||
34 | parent::__construct(); |
||
35 | $this->setTag('fieldset'); |
||
36 | $this->setLegend(_t('AttendeeField.VALUED', '{title} valued {price}', null, array( |
||
|
|||
37 | 'title' => $attendee->Ticket()->Title, |
||
38 | 'price' => $attendee->Ticket()->dbObject('Price')->NiceDecimalPoint()) |
||
39 | )); |
||
40 | |||
41 | $children = FieldList::create(); |
||
42 | $savableFields = $attendee->Event()->Fields(); |
||
43 | |||
44 | /** @var UserField $field */ |
||
45 | foreach ($savableFields as $field) { |
||
46 | // Generate a unique field name |
||
47 | $fieldName = "{$this->name}[{$attendee->ID}][$field->ID]"; |
||
48 | |||
49 | // Create the field an fill with attendee data |
||
50 | $hasField = $attendee->Fields()->find('ID', $field->ID); |
||
51 | $value = $hasField ? $hasField->getField('Value') : null; |
||
52 | $formField = $field->createField($fieldName, $value, $main); |
||
53 | |||
54 | // Check if the field is required |
||
55 | if ($field->Required && $required) { |
||
56 | if ($formField instanceof CompositeField) { |
||
57 | foreach ($formField->getChildren()->column('Name') as $requiredField) { |
||
58 | $this->addRequiredField($requiredField); |
||
59 | } |
||
60 | } else { |
||
61 | $this->addRequiredField($fieldName); |
||
62 | } |
||
63 | } |
||
64 | |||
65 | // Pre fill the field if a member is logged in |
||
66 | if ($main && empty($formField->value) && $member = Member::currentUser()) { |
||
67 | $formField->setValue($member->getField($field->Name)); |
||
68 | } |
||
69 | |||
70 | // Add the form |
||
71 | $children->add($formField); |
||
72 | } |
||
73 | |||
74 | // Set the main field |
||
75 | $children->add(HiddenField::create("{$this->name}[{$attendee->ID}][Main]", 'Main', (int)$main)); |
||
76 | |||
77 | // set the children |
||
78 | $this->setChildren($children); |
||
79 | |||
80 | // Add a hook to modify the added fields if needed |
||
81 | $this->extend('updateAttendeeField', $attendee, $main, $required); |
||
82 | } |
||
83 | |||
103 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: