Conditions | 12 |
Paths | 22 |
Total Lines | 110 |
Code Lines | 79 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
93 | public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string |
||
94 | { |
||
95 | $PEDIGREE_ROOT_ID = $tree->getPreference('PEDIGREE_ROOT_ID'); |
||
96 | $gedcomid = $tree->getUserPreference(Auth::user(), User::PREF_TREE_ACCOUNT_XREF); |
||
97 | $default_xref = $gedcomid ?: $PEDIGREE_ROOT_ID; |
||
98 | |||
99 | $type = $this->getBlockSetting($block_id, 'type', 'pedigree'); |
||
100 | $xref = $this->getBlockSetting($block_id, 'pid', $default_xref); |
||
101 | |||
102 | extract($config, EXTR_OVERWRITE); |
||
103 | |||
104 | $individual = Registry::individualFactory()->make($xref, $tree); |
||
105 | |||
106 | $title = $this->title(); |
||
107 | |||
108 | if ($individual instanceof Individual) { |
||
109 | switch ($type) { |
||
110 | default: |
||
111 | case 'pedigree': |
||
112 | $module = $this->module_service->findByInterface(PedigreeChartModule::class)->first(); |
||
113 | if ($module instanceof PedigreeChartModule) { |
||
114 | $title = $module->chartTitle($individual); |
||
115 | $chart_url = $module->chartUrl($individual, [ |
||
116 | 'ajax' => true, |
||
117 | 'generations' => 3, |
||
118 | 'layout' => PedigreeChartModule::STYLE_RIGHT, |
||
119 | ]); |
||
120 | $content = view('modules/charts/chart', [ |
||
121 | 'block_id' => $block_id, |
||
122 | 'chart_url' => $chart_url, |
||
123 | 'class' => 'wt-chart-pedigree', |
||
124 | ]); |
||
125 | } else { |
||
126 | $title = I18N::translate('Pedigree'); |
||
127 | $content = I18N::translate('The module “%s” has been disabled.', $title); |
||
128 | } |
||
129 | break; |
||
130 | |||
131 | case 'descendants': |
||
132 | $module = $this->module_service->findByInterface(DescendancyChartModule::class)->first(); |
||
133 | |||
134 | if ($module instanceof DescendancyChartModule) { |
||
135 | $title = $module->chartTitle($individual); |
||
136 | $chart_url = $module->chartUrl($individual, [ |
||
137 | 'ajax' => true, |
||
138 | 'generations' => 2, |
||
139 | 'chart_style' => DescendancyChartModule::CHART_STYLE_TREE, |
||
140 | ]); |
||
141 | $content = view('modules/charts/chart', [ |
||
142 | 'block_id' => $block_id, |
||
143 | 'chart_url' => $chart_url, |
||
144 | 'class' => 'wt-chart-descendants', |
||
145 | ]); |
||
146 | } else { |
||
147 | $title = I18N::translate('Descendants'); |
||
148 | $content = I18N::translate('The module “%s” has been disabled.', $title); |
||
149 | } |
||
150 | |||
151 | break; |
||
152 | |||
153 | case 'hourglass': |
||
154 | $module = $this->module_service->findByInterface(HourglassChartModule::class)->first(); |
||
155 | |||
156 | if ($module instanceof HourglassChartModule) { |
||
157 | $title = $module->chartTitle($individual); |
||
158 | $chart_url = $module->chartUrl($individual, [ |
||
159 | 'ajax' => true, |
||
160 | 'generations' => 2, |
||
161 | ]); |
||
162 | $content = view('modules/charts/chart', [ |
||
163 | 'block_id' => $block_id, |
||
164 | 'chart_url' => $chart_url, |
||
165 | 'class' => 'wt-chart-hourglass', |
||
166 | ]); |
||
167 | } else { |
||
168 | $title = I18N::translate('Hourglass chart'); |
||
169 | $content = I18N::translate('The module “%s” has been disabled.', $title); |
||
170 | } |
||
171 | break; |
||
172 | |||
173 | case 'treenav': |
||
174 | $module = $this->module_service->findByInterface(InteractiveTreeModule::class)->first(); |
||
175 | |||
176 | if ($module instanceof InteractiveTreeModule) { |
||
177 | $title = I18N::translate('Interactive tree of %s', $individual->fullName()); |
||
178 | $tv = new TreeView(); |
||
179 | [$html, $js] = $tv->drawViewport($individual, 2); |
||
180 | $content = $html . '<script>' . $js . '</script>'; |
||
181 | } else { |
||
182 | $title = I18N::translate('Interactive tree'); |
||
183 | $content = I18N::translate('The module “%s” has been disabled.', $title); |
||
184 | } |
||
185 | |||
186 | break; |
||
187 | } |
||
188 | } else { |
||
189 | $content = I18N::translate('You must select an individual and a chart type in the block preferences'); |
||
190 | } |
||
191 | |||
192 | if ($context !== self::CONTEXT_EMBED) { |
||
193 | return view('modules/block-template', [ |
||
194 | 'block' => Str::kebab($this->name()), |
||
195 | 'id' => $block_id, |
||
196 | 'config_url' => $this->configUrl($tree, $context, $block_id), |
||
197 | 'title' => $title, |
||
198 | 'content' => $content, |
||
199 | ]); |
||
200 | } |
||
201 | |||
202 | return $content; |
||
203 | } |
||
288 |