Conditions | 21 |
Paths | 11 |
Total Lines | 181 |
Code Lines | 129 |
Lines | 56 |
Ratio | 30.94 % |
Changes | 3 | ||
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 |
||
33 | protected function renderContent() { |
||
34 | ?> |
||
35 | <div id="maj-sosa-missing-page" class="center"> |
||
36 | <h2><?= $this->data->get('title') ?></h2> |
||
37 | |||
38 | <?php if($this->data->get('is_setup')) { |
||
39 | $this->renderSosaHeader(); |
||
40 | if($this->data->get('has_missing', false)) { |
||
41 | $table_id = $this->data->get('table_id'); |
||
42 | ?> |
||
43 | <div id="sosa-indi-missing" class="smissing-list"> |
||
44 | <table id="<?= $table_id ?>"> |
||
45 | <thead> |
||
46 | <tr> |
||
47 | <th colspan="11"> |
||
48 | <div class="btn-toolbar"> |
||
49 | <div class="btn-group"> |
||
50 | <button |
||
51 | class="ui-state-default" |
||
52 | data-filter-column="10" |
||
53 | data-filter-value="M" |
||
54 | title="<?php I18N::translate('Show only males.'); ?>" |
||
55 | type="button" |
||
56 | > |
||
57 | <?= Individual::sexImage('M', 'large') ?> |
||
58 | </button> |
||
59 | <button |
||
60 | class="ui-state-default" |
||
61 | data-filter-column="10" |
||
62 | data-filter-value="F" |
||
63 | title="<?php I18N::translate('Show only females.'); ?>" |
||
64 | type="button" |
||
65 | > |
||
66 | <?= Individual::sexImage('F', 'large') ?> |
||
67 | </button> |
||
68 | <button |
||
69 | class="ui-state-default" |
||
70 | data-filter-column="10" |
||
71 | data-filter-value="U" |
||
72 | title="<?php I18N::translate('Show only individuals for whom the gender is not known.'); ?>" |
||
73 | type="button" |
||
74 | > |
||
75 | <?= Individual::sexImage('U', 'large') ?> |
||
76 | </button> |
||
77 | </div> |
||
78 | </div> |
||
79 | </th> |
||
80 | </tr> |
||
81 | <tr> |
||
82 | <th><?= I18N::translate('Sosa') ?></th> |
||
83 | <th><?= GedcomTag::getLabel('INDI') ?></th> |
||
84 | <th><?= GedcomTag::getLabel('GIVN') ?></th> |
||
85 | <th><?= GedcomTag::getLabel('SURN') ?></th> |
||
86 | <?php if (ModuleManager::getInstance()->isOperational(Constants::MODULE_MAJ_ISSOURCED_NAME)) { ?> |
||
87 | <th><i class="icon-source" title="<?= I18N::translate('Sourced individual') ?>" border="0"></i></th> |
||
88 | <?php } else { ?> |
||
89 | <th></th> |
||
90 | <?php } ?> |
||
91 | <th><?= Functions::getRelationshipNameFromPath('fat') ?></th> |
||
92 | <th><?= Functions::getRelationshipNameFromPath('mot') ?></th> |
||
93 | <th><?= GedcomTag::getLabel('BIRT') ?></th> |
||
94 | <th><?= GedcomTag::getLabel('PLAC') ?></th> |
||
95 | <?php if (ModuleManager::getInstance()->isOperational(Constants::MODULE_MAJ_ISSOURCED_NAME)) { ?> |
||
96 | <th><i class="icon-source" title="<?= I18N::translate('Sourced birth') ?>" border="0"></i></th> |
||
97 | <?php } else { ?> |
||
98 | <th></th> |
||
99 | <?php } ?> |
||
100 | <th hidden>SEX</th> |
||
101 | </tr> |
||
102 | </thead> |
||
103 | <tbody> |
||
104 | |||
105 | <?php foreach($this->data->get('missing_list') as $missing_tab) { |
||
106 | $person = $missing_tab['indi']; |
||
107 | |||
108 | /** @var \Fisharebest\Webtrees\Individual $person */ |
||
109 | View Code Duplication | if ($person->isPendingAddtion()) { |
|
|
|||
110 | $class = ' class="new"'; |
||
111 | } elseif ($person->isPendingDeletion()) { |
||
112 | $class = ' class="old"'; |
||
113 | } else { |
||
114 | $class = ''; |
||
115 | } |
||
116 | $dperson = new \MyArtJaub\Webtrees\Individual($person); |
||
117 | list($surn_givn, $givn_surn) = FunctionsPrintLists::sortableNames($person); |
||
118 | ?> |
||
119 | <tr <?= $class ?>> |
||
120 | <td class="transparent"><?= $missing_tab['sosa'] ?></td> |
||
121 | <td class="transparent"><?= $person->getXref() ?></td> |
||
122 | <td colspan="2" data-sort="<?= Filter::escapeHtml($givn_surn) ?>"> |
||
123 | View Code Duplication | <?php foreach ($person->getAllNames() as $num=>$name) { |
|
124 | if ($name['type']=='NAME') { |
||
125 | $title=''; |
||
126 | } else { |
||
127 | $title='title="'.strip_tags(GedcomTag::getLabel($name['type'], $person)).'"'; |
||
128 | } |
||
129 | if ($num==$person->getPrimaryName()) { |
||
130 | $class=' class="name2"'; |
||
131 | $sex_image=$person->getSexImage(); |
||
132 | } else { |
||
133 | $class=''; |
||
134 | $sex_image=''; |
||
135 | } ?> |
||
136 | <a <?= $title.' '.$class ?> href="<?= $person->getHtmlUrl() ?>"> |
||
137 | <?= \Fisharebest\Webtrees\Functions\FunctionsPrint::highlightSearchHits($name['full']) ?> |
||
138 | </a> |
||
139 | <?= $sex_image; |
||
140 | echo implode(' ', |
||
141 | \MyArtJaub\Webtrees\Hook\HookProvider::getInstance() |
||
142 | ->get('hRecordNameAppend') |
||
143 | ->executeOnlyFor(array(Constants::MODULE_MAJ_SOSA_NAME), $person, 'smaller')); ?> |
||
144 | <br/> |
||
145 | <?php } |
||
146 | echo $person->getPrimaryParentsNames('parents details1', 'none'); |
||
147 | ?> |
||
148 | </td> |
||
149 | <td hidden data-sort="<?= Filter::escapeHtml($surn_givn) ?>"></td> |
||
150 | View Code Duplication | <?php if (ModuleManager::getInstance()->isOperational(Constants::MODULE_MAJ_ISSOURCED_NAME)) { |
|
151 | $isISourced = $dperson->isSourced(); ?> |
||
152 | <td data-sort="<?= $isISourced ?>"><?= FunctionsPrint::formatIsSourcedIcon('R', $isISourced, 'INDI', 1, 'medium') ?></td> |
||
153 | <?php } else { ?> |
||
154 | <td> </td> |
||
155 | <?php } ?> |
||
156 | <td><?= $missing_tab['has_father'] ? ' ' : 'X' ?></td> |
||
157 | <td><?= $missing_tab['has_mother'] ? ' ' : 'X' ?></td> |
||
158 | <?php $birth_dates = $person->getAllBirthDates(); ?> |
||
159 | <td data-sort="<?= $person->getEstimatedBirthDate()->julianDay() ?>"> |
||
160 | <?php |
||
161 | foreach ($birth_dates as $n => $birth_date) { |
||
162 | if ($n > 0) { ?> <br> <?php } |
||
163 | echo $birth_date->display(true); |
||
164 | } |
||
165 | ?> |
||
166 | </td> |
||
167 | <td> |
||
168 | <?php foreach ($person->getAllBirthPlaces() as $n => $birth_place) { |
||
169 | $tmp = new \Fisharebest\Webtrees\Place($birth_place, $person->getTree()); |
||
170 | if ($n > 0) { ?><br><?php } ?> |
||
171 | <a href="'<?= $tmp->getURL(); ?>" title="<?= strip_tags($tmp->getFullName()) ?>"> |
||
172 | <?= \Fisharebest\Webtrees\Functions\FunctionsPrint::highlightSearchHits($tmp->getShortName()) ?> |
||
173 | </a> |
||
174 | <?php } ?> |
||
175 | </td> |
||
176 | View Code Duplication | <?php if (ModuleManager::getInstance()->isOperational(Constants::MODULE_MAJ_ISSOURCED_NAME)) { |
|
177 | $isBSourced = $dperson->isBirthSourced(); ?> |
||
178 | <td data-sort="<?= $isBSourced ?>"><?= FunctionsPrint::formatIsSourcedIcon('E', $isBSourced, 'BIRT', 1, 'medium') ?></td> |
||
179 | <?php } else { ?> |
||
180 | <td> </td> |
||
181 | <?php } ?> |
||
182 | <td hidden><?= $person->getSex() ?></td> |
||
183 | </tr> |
||
184 | <?php } ?> |
||
185 | </tbody> |
||
186 | <tfoot> |
||
187 | <tr> |
||
188 | <td class="ui-state-default" colspan="11"> |
||
189 | <div class="center"> |
||
190 | <?= I18N::translate('Number of different missing ancestors: %s', I18N::number($this->data->get('missing_diff_count'))) ?> |
||
191 | View Code Duplication | <?php if($this->data->get('missing_hidden') > 0) echo ' ['. I18N::translate('%s hidden', I18N::number($this->data->get('missing_hidden'))).']'; ?> |
|
192 | <?= ' - ' . I18N::translate('Generation complete at %s', I18N::percentage($this->data->get('perc_sosa'), 2)) ?> |
||
193 | <?= ' [' . I18N::translate('Potential %s', I18N::percentage($this->data->get('perc_sosa_potential'),2)).']' ?> |
||
194 | </div> |
||
195 | </td> |
||
196 | </tr> |
||
197 | </tfoot> |
||
198 | </table> |
||
199 | <?php } else if ($this->data->get('generation', 0) > 0) { ?> |
||
200 | <p><?= I18N::translate('No ancestors are missing for this generation. Generation complete at %s.', I18N::percentage($this->data->get('perc_sosa'), 2)) ?></p> |
||
201 | <?php } |
||
202 | View Code Duplication | } else { ?> |
|
203 | <p class="warning"><?= I18N::translate('The list could not be displayed. Reasons might be:') ?><br/> |
||
204 | <ul> |
||
205 | <li><?= I18N::translate('No Sosa root individual has been defined.') ?></li> |
||
206 | <li><?= I18N::translate('The Sosa ancestors have not been computed yet.') ?></li> |
||
207 | <li><?= I18N::translate('No generation were found.') ?></li> |
||
208 | </ul> |
||
209 | </p> |
||
210 | <?php } ?> |
||
211 | </div> |
||
212 | <?php |
||
213 | } |
||
214 | } |
||
215 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.