Conditions | 15 |
Paths | 342 |
Total Lines | 72 |
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 |
||
75 | public function add($name, $type = null, array $fieldDescriptionOptions = []) |
||
76 | { |
||
77 | // Default sort on "associated_property" |
||
78 | if (isset($fieldDescriptionOptions['associated_property'])) { |
||
79 | if (!isset($fieldDescriptionOptions['sortable'])) { |
||
80 | $fieldDescriptionOptions['sortable'] = true; |
||
81 | } |
||
82 | if (!isset($fieldDescriptionOptions['sort_parent_association_mappings'])) { |
||
83 | $fieldDescriptionOptions['sort_parent_association_mappings'] = [[ |
||
84 | 'fieldName' => $name, |
||
85 | ]]; |
||
86 | } |
||
87 | if (!isset($fieldDescriptionOptions['sort_field_mapping'])) { |
||
88 | $fieldDescriptionOptions['sort_field_mapping'] = [ |
||
89 | 'fieldName' => $fieldDescriptionOptions['associated_property'], |
||
90 | ]; |
||
91 | } |
||
92 | } |
||
93 | |||
94 | // Ensure batch and action pseudo-fields are tagged as virtual |
||
95 | if (\in_array($type, ['actions', 'batch', 'select'], true)) { |
||
96 | $fieldDescriptionOptions['virtual_field'] = true; |
||
97 | } |
||
98 | |||
99 | if (\array_key_exists('identifier', $fieldDescriptionOptions) && !\is_bool($fieldDescriptionOptions['identifier'])) { |
||
100 | throw new \InvalidArgumentException(sprintf('Value for "identifier" option must be boolean, %s given.', \gettype($fieldDescriptionOptions['identifier']))); |
||
101 | } |
||
102 | |||
103 | if ($name instanceof FieldDescriptionInterface) { |
||
104 | $fieldDescription = $name; |
||
105 | $fieldDescription->mergeOptions($fieldDescriptionOptions); |
||
106 | } elseif (\is_string($name)) { |
||
107 | if ($this->admin->hasListFieldDescription($name)) { |
||
108 | throw new \LogicException(sprintf( |
||
109 | 'Duplicate field name "%s" in list mapper. Names should be unique.', |
||
110 | $name |
||
111 | )); |
||
112 | } |
||
113 | |||
114 | $fieldDescription = $this->admin->getModelManager()->getNewFieldDescriptionInstance( |
||
115 | $this->admin->getClass(), |
||
116 | $name, |
||
117 | $fieldDescriptionOptions |
||
118 | ); |
||
119 | } else { |
||
120 | throw new \TypeError( |
||
121 | 'Unknown field name in list mapper. ' |
||
|
|||
122 | .'Field name should be either of FieldDescriptionInterface interface or string.' |
||
123 | ); |
||
124 | } |
||
125 | |||
126 | if (null === $fieldDescription->getLabel()) { |
||
127 | $fieldDescription->setOption( |
||
128 | 'label', |
||
129 | $this->admin->getLabelTranslatorStrategy()->getLabel($fieldDescription->getName(), 'list', 'label') |
||
130 | ); |
||
131 | } |
||
132 | |||
133 | if (isset($fieldDescriptionOptions['header_style'])) { |
||
134 | @trigger_error( |
||
135 | 'The "header_style" option is deprecated, please, use "header_class" option instead.', |
||
136 | E_USER_DEPRECATED |
||
137 | ); |
||
138 | } |
||
139 | |||
140 | if (!isset($fieldDescriptionOptions['role']) || $this->admin->isGranted($fieldDescriptionOptions['role'])) { |
||
141 | // add the field with the FormBuilder |
||
142 | $this->builder->addField($this->list, $type, $fieldDescription, $this->admin); |
||
143 | } |
||
144 | |||
145 | return $this; |
||
146 | } |
||
147 | |||
178 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.