| Conditions | 14 |
| Paths | 121 |
| Total Lines | 78 |
| Code Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 2 | Features | 1 |
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 |
||
| 46 | public function build() |
||
| 47 | { |
||
| 48 | |||
| 49 | if ($this->isBuild) { |
||
| 50 | return; |
||
| 51 | } |
||
| 52 | |||
| 53 | $settings = $this->getObject(); |
||
| 54 | $reflection = new \ReflectionClass($settings); |
||
| 55 | $properties = $reflection->getProperties(); |
||
| 56 | |||
| 57 | $skipProperties = array('_settings', 'isWritable'); |
||
| 58 | if ($settings instanceof ModuleSettingsContainerInterface) { |
||
| 59 | $skipProperties[] = '_module'; |
||
| 60 | } |
||
| 61 | $children = array(); |
||
| 62 | foreach ($properties as $property) { |
||
| 63 | if (in_array($property->getName(), $skipProperties) || $this->has($property->getName())) { |
||
| 64 | continue; |
||
| 65 | } |
||
| 66 | $property->setAccessible(true); |
||
| 67 | $value = $property->getValue($settings); |
||
| 68 | if ($value instanceof SettingsContainerInterface) { |
||
| 69 | $children[$property->getName()] = $value; |
||
| 70 | continue; |
||
| 71 | } |
||
| 72 | |||
| 73 | $inputName = $property->getName(); |
||
| 74 | |||
| 75 | $inputLabel = isset($this->labelMap[$inputName]) ? $this->labelMap[$inputName] : $inputName; |
||
| 76 | |||
| 77 | if (is_array($inputLabel)){ |
||
| 78 | $priority = isset($inputLabel[1])?$inputLabel[1]:0; |
||
| 79 | $inputLabel = $inputLabel[0]; |
||
| 80 | }else{ |
||
| 81 | $priority = 0; |
||
| 82 | } |
||
| 83 | |||
| 84 | $input = array( |
||
| 85 | 'name' => $inputName, |
||
| 86 | 'options' => array( |
||
| 87 | |||
| 88 | 'label' => $inputLabel |
||
| 89 | ), |
||
| 90 | ); |
||
| 91 | if (is_bool($value)) { |
||
| 92 | $input['type']= 'Checkbox'; |
||
| 93 | $input['attributes']['checked'] = $value; |
||
| 94 | } else { |
||
| 95 | $input['attributes']['value'] = $value; |
||
| 96 | } |
||
| 97 | $this->add($input,['priority'=>$priority]); |
||
| 98 | |||
| 99 | } |
||
| 100 | |||
| 101 | foreach ($children as $name => $child) { |
||
| 102 | $objectClass = ltrim(get_class($settings), '\\'); |
||
| 103 | $moduleName = substr($objectClass, 0, strpos($objectClass, '\\')); |
||
| 104 | $fieldsetName = $moduleName . '/' . ucfirst($name) . 'SettingsFieldset'; |
||
| 105 | |||
| 106 | if ($this->formManager->has($fieldsetName)) { |
||
| 107 | $fieldset = $this->formManager->get($fieldsetName); |
||
| 108 | if (!$fieldset->getHydrator() instanceof SettingsEntityHydrator) { |
||
| 109 | $fieldset->setHydrator($this->getHydrator()); |
||
| 110 | } |
||
| 111 | } else { |
||
| 112 | $fieldset = new self(); |
||
|
|
|||
| 113 | $label = preg_replace('~([A-Z])~', ' $1', $name); |
||
| 114 | $fieldset->setLabel(ucfirst($label)); |
||
| 115 | } |
||
| 116 | $fieldset->setName($name) |
||
| 117 | ->setObject($child); |
||
| 118 | |||
| 119 | |||
| 120 | $this->add($fieldset); |
||
| 121 | } |
||
| 122 | $this->isBuild = true; |
||
| 123 | } |
||
| 124 | |||
| 134 |
This check looks for function calls that miss required arguments.